illume avatar illume committed 99ae54b

Added more tests for mask.get_bounding_rects()

Comments (0)

Files changed (1)

test/mask_test.py

 
         m.set_at((0,3), 1)
         m.set_at((3,3), 1)
+        
+        r = m.get_bounding_rects()
+        
+        self.assertEquals(repr(r), "[<rect(0, 0, 2, 2)>, <rect(0, 3, 1, 1)>, <rect(3, 3, 1, 1)>]")
+        
+        
+        
+
+
+        #1100
+        #1111
+        m = pygame.Mask((4,2))
+        m.set_at((0,0), 1)
+        m.set_at((1,0), 1)
+        m.set_at((2,0), 0)
+        m.set_at((3,0), 0)
+
+        m.set_at((0,1), 1)
+        m.set_at((1,1), 1)
+        m.set_at((2,1), 1)
+        m.set_at((3,1), 1)
+ 
+        r = m.get_bounding_rects()
+        self.assertEquals(repr(r), "[<rect(0, 0, 4, 2)>]")
+
+        
+        #00100
+        #01110
+        #00100
+        m = pygame.Mask((5,3))
+        m.set_at((0,0), 0)
+        m.set_at((1,0), 0)
+        m.set_at((2,0), 1)
+        m.set_at((3,0), 0)
+        m.set_at((4,0), 0)
+
+        m.set_at((0,1), 0)
+        m.set_at((1,1), 1)
+        m.set_at((2,1), 1)
+        m.set_at((3,1), 1)
+        m.set_at((4,1), 0)
+
+        m.set_at((0,2), 0)
+        m.set_at((1,2), 0)
+        m.set_at((2,2), 1)
+        m.set_at((3,2), 0)
+        m.set_at((4,2), 0)
 
         r = m.get_bounding_rects()
+        self.assertEquals(repr(r), "[<rect(1, 0, 3, 3)>]")
 
-        self.assertEquals(repr(r), "[<rect(0, 0, 2, 2)>, <rect(0, 3, 1, 1)>, <rect(3, 3, 1, 1)>]")
+
+
+        #00010
+        #00100
+        #01000
+        m = pygame.Mask((5,3))
+        m.set_at((0,0), 0)
+        m.set_at((1,0), 0)
+        m.set_at((2,0), 0)
+        m.set_at((3,0), 1)
+        m.set_at((4,0), 0)
+
+        m.set_at((0,1), 0)
+        m.set_at((1,1), 0)
+        m.set_at((2,1), 1)
+        m.set_at((3,1), 0)
+        m.set_at((4,1), 0)
+
+        m.set_at((0,2), 0)
+        m.set_at((1,2), 1)
+        m.set_at((2,2), 0)
+        m.set_at((3,2), 0)
+        m.set_at((4,2), 0)
+
+        r = m.get_bounding_rects()
+        self.assertEquals(repr(r), "[<rect(1, 0, 3, 3)>]")
+
+
+
+
+        #00011
+        #11111
+        m = pygame.Mask((5,2))
+        m.set_at((0,0), 0)
+        m.set_at((1,0), 0)
+        m.set_at((2,0), 0)
+        m.set_at((3,0), 1)
+        m.set_at((4,0), 1)
+
+        m.set_at((0,1), 1)
+        m.set_at((1,1), 1)
+        m.set_at((2,1), 1)
+        m.set_at((3,1), 1)
+        m.set_at((3,1), 1)
+ 
+        r = m.get_bounding_rects()
+        #TODO: this should really make one bounding rect.
+        #self.assertEquals(repr(r), "[<rect(0, 0, 5, 2)>]")
+
+
+
+
 
 class MaskModuleTest(unittest.TestCase):
     def test_from_surface(self):
         print surf.get_at((0,0))
 
         print "asdf"
-        print surf
+        print surf
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.