示例#1
0
    def setUp(self):
        self.matrixOne = [0, 0, 0, 0,
                          0, 0, 0, 0,
                          0, 0, 0, 0,
                          0, 0, 0, 0]
        
        self.matrixTwo = [0, 0, 1, 0,
                          0, 0, 1, 0,
                          0, 0, 1, 0,
                          0, 0, 1, 0]

        self.matrixDiag = [1, 0, 0, 0,
                           0, 1, 0, 0,
                           0, 0, 1, 0,
                           0, 0, 0, 1]

        self.matrixCorners = [1, 0, 0, 1,
                              0, 0, 0, 0,
                              0, 0, 0, 0,
                              1, 0, 0, 1]

        self.matrixHoriz = [0, 0, 0, 0,
                            1, 1, 1, 1,
                            0, 0, 0, 0,
                            0, 0, 0, 0]

        self.matrixThree = [0, 1, 0, 0,
                            0, 1, 0, 0,
                            1, 1, 1, 0,
                            0, 0, 1, 0]
        
        self.matrixSquare = [0, 0, 0, 0,
                             0, 1, 1, 1,
                             0, 1, 0, 1,
                             0, 1, 1, 1]
        
        self.matrixNoDiv = [0, 0, 0, 0, 0,
                            0, 1, 1, 0, 0,
                            0, 0, 1, 0, 0,
                            0, 0, 1, 1, 0,
                            0, 0, 0, 0, 0]

        self.matrixNoDiv2 =[1, 1, 0, 0, 0,
                            0, 1, 1, 0, 0,
                            0, 0, 1, 0, 0,
                            0, 0, 1, 1, 0,
                            0, 0, 0, 0, 0]

        self.regions = RegionCounter()
示例#2
0
class TestConnectedRegions(unittest.TestCase):

    def setUp(self):
        self.matrixOne = [0, 0, 0, 0,
                          0, 0, 0, 0,
                          0, 0, 0, 0,
                          0, 0, 0, 0]
        
        self.matrixTwo = [0, 0, 1, 0,
                          0, 0, 1, 0,
                          0, 0, 1, 0,
                          0, 0, 1, 0]

        self.matrixDiag = [1, 0, 0, 0,
                           0, 1, 0, 0,
                           0, 0, 1, 0,
                           0, 0, 0, 1]

        self.matrixCorners = [1, 0, 0, 1,
                              0, 0, 0, 0,
                              0, 0, 0, 0,
                              1, 0, 0, 1]

        self.matrixHoriz = [0, 0, 0, 0,
                            1, 1, 1, 1,
                            0, 0, 0, 0,
                            0, 0, 0, 0]

        self.matrixThree = [0, 1, 0, 0,
                            0, 1, 0, 0,
                            1, 1, 1, 0,
                            0, 0, 1, 0]
        
        self.matrixSquare = [0, 0, 0, 0,
                             0, 1, 1, 1,
                             0, 1, 0, 1,
                             0, 1, 1, 1]
        
        self.matrixNoDiv = [0, 0, 0, 0, 0,
                            0, 1, 1, 0, 0,
                            0, 0, 1, 0, 0,
                            0, 0, 1, 1, 0,
                            0, 0, 0, 0, 0]

        self.matrixNoDiv2 =[1, 1, 0, 0, 0,
                            0, 1, 1, 0, 0,
                            0, 0, 1, 0, 0,
                            0, 0, 1, 1, 0,
                            0, 0, 0, 0, 0]

        self.regions = RegionCounter()

    def testRegionsOne(self):
        print '\nTesting One Region' 
        regionCountOne = self.regions.countRegions(self.matrixOne, 4, 4)
        self.assertEqual(regionCountOne, 1)
   
    def testRegionsTwo(self):
        print '\nTesting Two Regions'
        regionCountTwo = self.regions.countRegions(self.matrixTwo, 4, 4)
        self.assertEqual(regionCountTwo, 2)

    def testRegionsDiag(self):
        print '\nTesting Diagonal Division'
        regionCountDiag = self.regions.countRegions(self.matrixDiag, 4, 4)
        self.assertEqual(regionCountDiag, 2)

    def testRegionsCorners(self):
        print '\nTesting Corners'
        regionCountCorners = self.regions.countRegions(self.matrixCorners, 4, 4)
        self.assertEqual(regionCountCorners, 1)

    def testRegionsHoriz(self):
        print '\nTesting Horizontal Division'
        regionCountHoriz = self.regions.countRegions(self.matrixHoriz, 4, 4)
        self.assertEqual(regionCountHoriz, 2)

    def testRegionsThree(self):
        regionCountThree = self.regions.countRegions(self.matrixThree, 4, 4)
        self.assertEqual(regionCountThree, 3)

    def testRegionsSquare(self):
        print '\nTesting Square Region'
        regionCountSquare = self.regions.countRegions(self.matrixSquare, 4, 4)
        self.assertEqual(regionCountSquare, 2)
    
    def testRegionsNoDiv(self):
        print '\nTesting No Division'
        regionCountNoDiv = self.regions.countRegions(self.matrixNoDiv, 5, 5)
        self.assertEqual(regionCountNoDiv, 1)

    def testRegionsNoDiv2(self):
        print '\nTesting No Division 2'
        regionCountNoDiv2 = self.regions.countRegions(self.matrixNoDiv2, 5, 5)
        self.assertEqual(regionCountNoDiv2, 1)