#! /usr/bin/python

from counting_box import Counting_Box
import Image
import sys
import unittest 



 
class Test_Counting_Box(unittest.TestCase): 
    def assertEqualPrecision(self,first,second,precision):
        if abs(first - second) > precision:
            print first , " must equal to " , second , " with the precision : " , precision             
        self.assert_(abs(first - second) < precision)

    def testCountingBox (self): 
        """ Test Counting Box """
        delta=0.2
        #           (Box,white,grey,black)
        values = ( ( 2,1088.75 ,177 ,1426 ), 
                   ( 3,447.3337,151,598),
                   ( 4,232.9375, 125, 315 ),
                   ( 7,59.1633,78.7614,82),
                   ( 10,21.87,53.8,32)  ,
                   ( 11,15.8926,49.0909,24),
                   ( 16,2.3711,32.6875,7),
                   ( 20,2.5675,20.35,4),
                   ( 21,1.3197,20.0952,3)
                   ) 
        
        Cb=Counting_Box("Test_Counting_Box.bmp")
        
        Cb.Size_max_box=22
        Cb.setboxes("all")
        Cb.compute()

        for box, white, grey, black  in values: 
            res_white,res_grey,res_black =Cb.Computation[box]
            self.assertEqualPrecision (res_white, white,delta)
            self.assertEqualPrecision (res_grey, grey,delta)
            self.assertEqualPrecision (res_black, black,delta)          
             
if __name__ == "__main__": 
    unittest.main()    































Cb.nuage()

