Mercurial > pygame
annotate test/rect_test.py @ 3172:d1b367fc08bc tests-returncode
Use a return code of 1 when the tests fail.
| author | Thomas Kluyver <takowl@gmail.com> |
|---|---|
| date | Wed, 09 Jan 2013 10:13:57 +0000 |
| parents | ebd545641c8b |
| children |
| rev | line source |
|---|---|
|
1418
af8675f5e463
test suite now pygame.tests subpackage as well
Lenard Lindstrom <len-l@telus.net>
parents:
1261
diff
changeset
|
1 if __name__ == '__main__': |
|
af8675f5e463
test suite now pygame.tests subpackage as well
Lenard Lindstrom <len-l@telus.net>
parents:
1261
diff
changeset
|
2 import sys |
|
af8675f5e463
test suite now pygame.tests subpackage as well
Lenard Lindstrom <len-l@telus.net>
parents:
1261
diff
changeset
|
3 import os |
|
af8675f5e463
test suite now pygame.tests subpackage as well
Lenard Lindstrom <len-l@telus.net>
parents:
1261
diff
changeset
|
4 pkg_dir = os.path.split(os.path.abspath(__file__))[0] |
|
af8675f5e463
test suite now pygame.tests subpackage as well
Lenard Lindstrom <len-l@telus.net>
parents:
1261
diff
changeset
|
5 parent_dir, pkg_name = os.path.split(pkg_dir) |
|
af8675f5e463
test suite now pygame.tests subpackage as well
Lenard Lindstrom <len-l@telus.net>
parents:
1261
diff
changeset
|
6 is_pygame_pkg = (pkg_name == 'tests' and |
|
af8675f5e463
test suite now pygame.tests subpackage as well
Lenard Lindstrom <len-l@telus.net>
parents:
1261
diff
changeset
|
7 os.path.split(parent_dir)[1] == 'pygame') |
|
af8675f5e463
test suite now pygame.tests subpackage as well
Lenard Lindstrom <len-l@telus.net>
parents:
1261
diff
changeset
|
8 if not is_pygame_pkg: |
|
af8675f5e463
test suite now pygame.tests subpackage as well
Lenard Lindstrom <len-l@telus.net>
parents:
1261
diff
changeset
|
9 sys.path.insert(0, parent_dir) |
|
af8675f5e463
test suite now pygame.tests subpackage as well
Lenard Lindstrom <len-l@telus.net>
parents:
1261
diff
changeset
|
10 else: |
|
af8675f5e463
test suite now pygame.tests subpackage as well
Lenard Lindstrom <len-l@telus.net>
parents:
1261
diff
changeset
|
11 is_pygame_pkg = __name__.startswith('pygame.tests.') |
| 312 | 12 |
|
1418
af8675f5e463
test suite now pygame.tests subpackage as well
Lenard Lindstrom <len-l@telus.net>
parents:
1261
diff
changeset
|
13 if is_pygame_pkg: |
|
af8675f5e463
test suite now pygame.tests subpackage as well
Lenard Lindstrom <len-l@telus.net>
parents:
1261
diff
changeset
|
14 from pygame.tests.test_utils import test_not_implemented, unittest |
|
af8675f5e463
test suite now pygame.tests subpackage as well
Lenard Lindstrom <len-l@telus.net>
parents:
1261
diff
changeset
|
15 else: |
|
af8675f5e463
test suite now pygame.tests subpackage as well
Lenard Lindstrom <len-l@telus.net>
parents:
1261
diff
changeset
|
16 from test.test_utils import test_not_implemented, unittest |
| 312 | 17 from pygame import Rect |
| 18 | |
|
1148
1d1ed35fb837
Added in many test stubs, hopefully some test faeries will fill some of them out.
akalias
parents:
716
diff
changeset
|
19 class RectTypeTest( unittest.TestCase ): |
| 312 | 20 def testConstructionXYWidthHeight( self ): |
| 21 r = Rect(1,2,3,4) | |
| 22 self.assertEqual( 1, r.left ) | |
| 23 self.assertEqual( 2, r.top ) | |
| 24 self.assertEqual( 3, r.width ) | |
| 25 self.assertEqual( 4, r.height ) | |
| 26 | |
| 27 def testConstructionTopLeftSize( self ): | |
| 28 r = Rect( (1,2), (3,4) ) | |
| 29 self.assertEqual( 1, r.left ) | |
| 30 self.assertEqual( 2, r.top ) | |
| 31 self.assertEqual( 3, r.width ) | |
| 32 self.assertEqual( 4, r.height ) | |
| 33 | |
| 34 def testCalculatedAttributes( self ): | |
| 35 r = Rect( 1, 2, 3, 4 ) | |
| 36 | |
| 37 self.assertEqual( r.left+r.width, r.right ) | |
| 38 self.assertEqual( r.top+r.height, r.bottom ) | |
| 39 self.assertEqual( (r.width,r.height), r.size ) | |
| 40 self.assertEqual( (r.left,r.top), r.topleft ) | |
| 41 self.assertEqual( (r.right,r.top), r.topright ) | |
| 42 self.assertEqual( (r.left,r.bottom), r.bottomleft ) | |
| 43 self.assertEqual( (r.right,r.bottom), r.bottomright ) | |
| 44 | |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1547
diff
changeset
|
45 midx = r.left + r.width // 2 |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1547
diff
changeset
|
46 midy = r.top + r.height // 2 |
| 312 | 47 |
| 48 self.assertEqual( midx, r.centerx ) | |
| 49 self.assertEqual( midy, r.centery ) | |
| 50 self.assertEqual( (r.centerx,r.centery), r.center ) | |
| 51 self.assertEqual( (r.centerx,r.top), r.midtop ) | |
| 52 self.assertEqual( (r.centerx,r.bottom), r.midbottom ) | |
| 53 self.assertEqual( (r.left,r.centery), r.midleft ) | |
| 54 self.assertEqual( (r.right,r.centery), r.midright ) | |
| 55 | |
|
1148
1d1ed35fb837
Added in many test stubs, hopefully some test faeries will fill some of them out.
akalias
parents:
716
diff
changeset
|
56 def test_normalize( self ): |
| 312 | 57 r = Rect( 1, 2, -3, -6 ) |
| 58 r2 = Rect(r) | |
| 59 r2.normalize() | |
| 60 self.failUnless( r2.width >= 0 ) | |
| 61 self.failUnless( r2.height >= 0 ) | |
| 62 self.assertEqual( (abs(r.width),abs(r.height)), r2.size ) | |
| 63 self.assertEqual( (-2,-4), r2.topleft ) | |
| 64 | |
|
1198
785b822ecab8
Renamed some rect_test.py tests to match stub generator scheme
akalias
parents:
1148
diff
changeset
|
65 def test_left( self ): |
| 312 | 66 """Changing the left attribute moves the rect and does not change |
| 67 the rect's width | |
| 68 """ | |
| 69 r = Rect( 1, 2, 3, 4 ) | |
| 70 new_left = 10 | |
| 71 | |
| 72 r.left = new_left | |
| 73 self.assertEqual( new_left, r.left ) | |
| 74 self.assertEqual( Rect(new_left,2,3,4), r ) | |
| 75 | |
|
1198
785b822ecab8
Renamed some rect_test.py tests to match stub generator scheme
akalias
parents:
1148
diff
changeset
|
76 def test_right( self ): |
| 312 | 77 """Changing the right attribute moves the rect and does not change |
| 78 the rect's width | |
| 79 """ | |
| 80 r = Rect( 1, 2, 3, 4 ) | |
| 81 new_right = r.right + 20 | |
| 82 expected_left = r.left + 20 | |
| 83 old_width = r.width | |
| 84 | |
| 85 r.right = new_right | |
| 86 self.assertEqual( new_right, r.right ) | |
| 87 self.assertEqual( expected_left, r.left ) | |
| 88 self.assertEqual( old_width, r.width ) | |
| 89 | |
|
1198
785b822ecab8
Renamed some rect_test.py tests to match stub generator scheme
akalias
parents:
1148
diff
changeset
|
90 def test_top( self ): |
| 312 | 91 """Changing the top attribute moves the rect and does not change |
| 92 the rect's width | |
| 93 """ | |
| 94 r = Rect( 1, 2, 3, 4 ) | |
| 95 new_top = 10 | |
| 96 | |
| 97 r.top = new_top | |
| 98 self.assertEqual( Rect(1,new_top,3,4), r ) | |
| 99 self.assertEqual( new_top, r.top ) | |
| 100 | |
|
1198
785b822ecab8
Renamed some rect_test.py tests to match stub generator scheme
akalias
parents:
1148
diff
changeset
|
101 def test_bottom( self ): |
| 312 | 102 """Changing the bottom attribute moves the rect and does not change |
| 103 the rect's height | |
| 104 """ | |
| 105 r = Rect( 1, 2, 3, 4 ) | |
| 106 new_bottom = r.bottom + 20 | |
| 107 expected_top = r.top + 20 | |
| 108 old_height = r.height | |
| 109 | |
| 110 r.bottom = new_bottom | |
| 111 self.assertEqual( new_bottom, r.bottom ) | |
| 112 self.assertEqual( expected_top, r.top ) | |
| 113 self.assertEqual( old_height, r.height ) | |
| 114 | |
|
1198
785b822ecab8
Renamed some rect_test.py tests to match stub generator scheme
akalias
parents:
1148
diff
changeset
|
115 def test_centerx( self ): |
| 312 | 116 """Changing the centerx attribute moves the rect and does not change |
| 117 the rect's width | |
| 118 """ | |
| 119 r = Rect( 1, 2, 3, 4 ) | |
| 120 new_centerx = r.centerx + 20 | |
| 121 expected_left = r.left + 20 | |
| 122 old_width = r.width | |
| 123 | |
| 124 r.centerx = new_centerx | |
| 125 self.assertEqual( new_centerx, r.centerx ) | |
| 126 self.assertEqual( expected_left, r.left ) | |
| 127 self.assertEqual( old_width, r.width ) | |
| 128 | |
|
1198
785b822ecab8
Renamed some rect_test.py tests to match stub generator scheme
akalias
parents:
1148
diff
changeset
|
129 def test_centery( self ): |
| 312 | 130 """Changing the centerx attribute moves the rect and does not change |
| 131 the rect's width | |
| 132 """ | |
| 133 r = Rect( 1, 2, 3, 4 ) | |
| 134 new_centery = r.centery + 20 | |
| 135 expected_top = r.top + 20 | |
| 136 old_height = r.height | |
| 137 | |
| 138 r.centery = new_centery | |
| 139 self.assertEqual( new_centery, r.centery ) | |
| 140 self.assertEqual( expected_top, r.top ) | |
| 141 self.assertEqual( old_height, r.height ) | |
| 142 | |
|
1198
785b822ecab8
Renamed some rect_test.py tests to match stub generator scheme
akalias
parents:
1148
diff
changeset
|
143 def test_topleft( self ): |
| 312 | 144 """Changing the topleft attribute moves the rect and does not change |
| 145 the rect's size | |
| 146 """ | |
| 147 r = Rect( 1, 2, 3, 4 ) | |
| 148 new_topleft = (r.left+20,r.top+30) | |
| 149 old_size = r.size | |
| 150 | |
| 151 r.topleft = new_topleft | |
| 152 self.assertEqual( new_topleft, r.topleft ) | |
| 153 self.assertEqual( old_size, r.size ) | |
| 154 | |
|
1198
785b822ecab8
Renamed some rect_test.py tests to match stub generator scheme
akalias
parents:
1148
diff
changeset
|
155 def test_bottomleft( self ): |
| 312 | 156 """Changing the bottomleft attribute moves the rect and does not change |
| 157 the rect's size | |
| 158 """ | |
| 159 r = Rect( 1, 2, 3, 4 ) | |
| 160 new_bottomleft = (r.left+20,r.bottom+30) | |
| 161 expected_topleft = (r.left+20,r.top+30) | |
| 162 old_size = r.size | |
| 163 | |
| 164 r.bottomleft = new_bottomleft | |
| 165 self.assertEqual( new_bottomleft, r.bottomleft ) | |
| 166 self.assertEqual( expected_topleft, r.topleft ) | |
| 167 self.assertEqual( old_size, r.size ) | |
| 168 | |
|
1198
785b822ecab8
Renamed some rect_test.py tests to match stub generator scheme
akalias
parents:
1148
diff
changeset
|
169 def test_topright( self ): |
| 312 | 170 """Changing the bottomleft attribute moves the rect and does not change |
| 171 the rect's size | |
| 172 """ | |
| 173 r = Rect( 1, 2, 3, 4 ) | |
| 174 new_topright = (r.right+20,r.top+30) | |
| 175 expected_topleft = (r.left+20,r.top+30) | |
| 176 old_size = r.size | |
| 177 | |
| 178 r.topright = new_topright | |
| 179 self.assertEqual( new_topright, r.topright ) | |
| 180 self.assertEqual( expected_topleft, r.topleft ) | |
| 181 self.assertEqual( old_size, r.size ) | |
| 182 | |
|
1198
785b822ecab8
Renamed some rect_test.py tests to match stub generator scheme
akalias
parents:
1148
diff
changeset
|
183 def test_bottomright( self ): |
| 312 | 184 """Changing the bottomright attribute moves the rect and does not change |
| 185 the rect's size | |
| 186 """ | |
| 187 r = Rect( 1, 2, 3, 4 ) | |
| 188 new_bottomright = (r.right+20,r.bottom+30) | |
| 189 expected_topleft = (r.left+20,r.top+30) | |
| 190 old_size = r.size | |
| 191 | |
| 192 r.bottomright = new_bottomright | |
| 193 self.assertEqual( new_bottomright, r.bottomright ) | |
| 194 self.assertEqual( expected_topleft, r.topleft ) | |
| 195 self.assertEqual( old_size, r.size ) | |
| 196 | |
|
1198
785b822ecab8
Renamed some rect_test.py tests to match stub generator scheme
akalias
parents:
1148
diff
changeset
|
197 def test_center( self ): |
| 312 | 198 """Changing the center attribute moves the rect and does not change |
| 199 the rect's size | |
| 200 """ | |
| 201 r = Rect( 1, 2, 3, 4 ) | |
| 202 new_center = (r.centerx+20,r.centery+30) | |
| 203 expected_topleft = (r.left+20,r.top+30) | |
| 204 old_size = r.size | |
| 205 | |
| 206 r.center = new_center | |
| 207 self.assertEqual( new_center, r.center ) | |
| 208 self.assertEqual( expected_topleft, r.topleft ) | |
| 209 self.assertEqual( old_size, r.size ) | |
| 210 | |
|
1198
785b822ecab8
Renamed some rect_test.py tests to match stub generator scheme
akalias
parents:
1148
diff
changeset
|
211 def test_midleft( self ): |
| 312 | 212 """Changing the midleft attribute moves the rect and does not change |
| 213 the rect's size | |
| 214 """ | |
| 215 r = Rect( 1, 2, 3, 4 ) | |
| 216 new_midleft = (r.left+20,r.centery+30) | |
| 217 expected_topleft = (r.left+20,r.top+30) | |
| 218 old_size = r.size | |
| 219 | |
| 220 r.midleft = new_midleft | |
| 221 self.assertEqual( new_midleft, r.midleft ) | |
| 222 self.assertEqual( expected_topleft, r.topleft ) | |
| 223 self.assertEqual( old_size, r.size ) | |
| 224 | |
|
1198
785b822ecab8
Renamed some rect_test.py tests to match stub generator scheme
akalias
parents:
1148
diff
changeset
|
225 def test_midright( self ): |
| 312 | 226 """Changing the midright attribute moves the rect and does not change |
| 227 the rect's size | |
| 228 """ | |
| 229 r = Rect( 1, 2, 3, 4 ) | |
| 230 new_midright= (r.right+20,r.centery+30) | |
| 231 expected_topleft = (r.left+20,r.top+30) | |
| 232 old_size = r.size | |
| 233 | |
| 234 r.midright = new_midright | |
| 235 self.assertEqual( new_midright, r.midright ) | |
| 236 self.assertEqual( expected_topleft, r.topleft ) | |
| 237 self.assertEqual( old_size, r.size ) | |
| 238 | |
|
1198
785b822ecab8
Renamed some rect_test.py tests to match stub generator scheme
akalias
parents:
1148
diff
changeset
|
239 def test_midtop( self ): |
| 312 | 240 """Changing the midtop attribute moves the rect and does not change |
| 241 the rect's size | |
| 242 """ | |
| 243 r = Rect( 1, 2, 3, 4 ) | |
| 244 new_midtop= (r.centerx+20,r.top+30) | |
| 245 expected_topleft = (r.left+20,r.top+30) | |
| 246 old_size = r.size | |
| 247 | |
| 248 r.midtop = new_midtop | |
| 249 self.assertEqual( new_midtop, r.midtop ) | |
| 250 self.assertEqual( expected_topleft, r.topleft ) | |
| 251 self.assertEqual( old_size, r.size ) | |
| 252 | |
|
1198
785b822ecab8
Renamed some rect_test.py tests to match stub generator scheme
akalias
parents:
1148
diff
changeset
|
253 def test_midbottom( self ): |
| 312 | 254 """Changing the midbottom attribute moves the rect and does not change |
| 255 the rect's size | |
| 256 """ | |
| 257 r = Rect( 1, 2, 3, 4 ) | |
| 258 new_midbottom = (r.centerx+20,r.bottom+30) | |
| 259 expected_topleft = (r.left+20,r.top+30) | |
| 260 old_size = r.size | |
| 261 | |
| 262 r.midbottom = new_midbottom | |
| 263 self.assertEqual( new_midbottom, r.midbottom ) | |
| 264 self.assertEqual( expected_topleft, r.topleft ) | |
| 265 self.assertEqual( old_size, r.size ) | |
| 266 | |
|
1198
785b822ecab8
Renamed some rect_test.py tests to match stub generator scheme
akalias
parents:
1148
diff
changeset
|
267 def test_width( self ): |
| 312 | 268 "Changing the width resizes the rect from the top-left corner" |
| 269 r = Rect( 1, 2, 3, 4 ) | |
| 270 new_width = 10 | |
| 271 old_topleft = r.topleft | |
| 272 old_height = r.height | |
| 273 | |
| 274 r.width = new_width | |
| 275 self.assertEqual( new_width, r.width ) | |
| 276 self.assertEqual( old_height, r.height ) | |
| 277 self.assertEqual( old_topleft, r.topleft ) | |
| 278 | |
|
1198
785b822ecab8
Renamed some rect_test.py tests to match stub generator scheme
akalias
parents:
1148
diff
changeset
|
279 def test_height( self ): |
| 312 | 280 "Changing the height resizes the rect from the top-left corner" |
| 281 r = Rect( 1, 2, 3, 4 ) | |
| 282 new_height = 10 | |
| 283 old_topleft = r.topleft | |
| 284 old_width = r.width | |
| 285 | |
| 286 r.height = new_height | |
| 287 self.assertEqual( new_height, r.height ) | |
| 288 self.assertEqual( old_width, r.width ) | |
| 289 self.assertEqual( old_topleft, r.topleft ) | |
| 290 | |
|
1198
785b822ecab8
Renamed some rect_test.py tests to match stub generator scheme
akalias
parents:
1148
diff
changeset
|
291 def test_size( self ): |
| 312 | 292 "Changing the size resizes the rect from the top-left corner" |
| 293 r = Rect( 1, 2, 3, 4 ) | |
| 294 new_size = (10,20) | |
| 295 old_topleft = r.topleft | |
| 296 | |
| 297 r.size = new_size | |
| 298 self.assertEqual( new_size, r.size ) | |
| 299 self.assertEqual( old_topleft, r.topleft ) | |
| 300 | |
|
1148
1d1ed35fb837
Added in many test stubs, hopefully some test faeries will fill some of them out.
akalias
parents:
716
diff
changeset
|
301 def test_contains( self ): |
| 312 | 302 r = Rect( 1, 2, 3, 4 ) |
| 303 | |
| 304 self.failUnless( r.contains( Rect( 2, 3, 1, 1 ) ), | |
| 305 "r does not contain Rect(2,3,1,1)" ) | |
| 306 self.failUnless( r.contains( Rect(r) ), | |
| 307 "r does not contain the same rect as itself" ) | |
| 308 self.failUnless( r.contains( Rect(2,3,0,0) ), | |
| 309 "r does not contain an empty rect within its bounds" ) | |
| 310 self.failIf( r.contains( Rect(0,0,1,2) ), | |
| 311 "r contains Rect(0,0,1,2)" ) | |
| 312 self.failIf( r.contains( Rect(4,6,1,1) ), | |
| 313 "r contains Rect(4,6,1,1)" ) | |
| 314 self.failIf( r.contains( Rect(4,6,0,0) ), | |
| 315 "r contains Rect(4,6,0,0)" ) | |
| 316 | |
|
1148
1d1ed35fb837
Added in many test stubs, hopefully some test faeries will fill some of them out.
akalias
parents:
716
diff
changeset
|
317 def test_collidepoint( self ): |
| 312 | 318 r = Rect( 1, 2, 3, 4 ) |
| 319 | |
| 320 self.failUnless( r.collidepoint( r.left, r.top ), | |
| 321 "r does not collide with point (left,top)" ) | |
| 322 self.failIf( r.collidepoint( r.left-1, r.top ), | |
| 323 "r collides with point (left-1,top)" ) | |
| 324 self.failIf( r.collidepoint( r.left, r.top-1 ), | |
| 325 "r collides with point (left,top-1)" ) | |
| 326 self.failIf( r.collidepoint( r.left-1,r.top-1 ), | |
| 327 "r collides with point (left-1,top-1)" ) | |
| 328 | |
| 329 self.failUnless( r.collidepoint( r.right-1, r.bottom-1 ), | |
| 330 "r does not collide with point (right-1,bottom-1)") | |
| 331 self.failIf( r.collidepoint( r.right, r.bottom ), | |
| 332 "r collides with point (right,bottom)" ) | |
| 333 self.failIf( r.collidepoint( r.right-1, r.bottom ), | |
| 334 "r collides with point (right-1,bottom)" ) | |
| 335 self.failIf( r.collidepoint( r.right, r.bottom-1 ), | |
| 336 "r collides with point (right,bottom-1)" ) | |
| 337 | |
|
1148
1d1ed35fb837
Added in many test stubs, hopefully some test faeries will fill some of them out.
akalias
parents:
716
diff
changeset
|
338 def test_inflate__larger( self ): |
| 312 | 339 "The inflate method inflates around the center of the rectangle" |
| 340 r = Rect( 2, 4, 6, 8 ) | |
| 341 r2 = r.inflate( 4, 6 ) | |
| 342 | |
| 343 self.assertEqual( r.center, r2.center ) | |
| 344 self.assertEqual( r.left-2, r2.left ) | |
| 345 self.assertEqual( r.top-3, r2.top ) | |
| 346 self.assertEqual( r.right+2, r2.right ) | |
| 347 self.assertEqual( r.bottom+3, r2.bottom ) | |
| 348 self.assertEqual( r.width+4, r2.width ) | |
| 349 self.assertEqual( r.height+6, r2.height ) | |
| 350 | |
|
1148
1d1ed35fb837
Added in many test stubs, hopefully some test faeries will fill some of them out.
akalias
parents:
716
diff
changeset
|
351 def test_inflate__smaller( self ): |
| 312 | 352 "The inflate method inflates around the center of the rectangle" |
| 353 r = Rect( 2, 4, 6, 8 ) | |
| 354 r2 = r.inflate( -4, -6 ) | |
| 355 | |
| 356 self.assertEqual( r.center, r2.center ) | |
| 357 self.assertEqual( r.left+2, r2.left ) | |
| 358 self.assertEqual( r.top+3, r2.top ) | |
| 359 self.assertEqual( r.right-2, r2.right ) | |
| 360 self.assertEqual( r.bottom-3, r2.bottom ) | |
| 361 self.assertEqual( r.width-4, r2.width ) | |
| 362 self.assertEqual( r.height-6, r2.height ) | |
| 363 | |
|
1148
1d1ed35fb837
Added in many test stubs, hopefully some test faeries will fill some of them out.
akalias
parents:
716
diff
changeset
|
364 def test_inflate_ip__larger( self ): |
| 312 | 365 "The inflate_ip method inflates around the center of the rectangle" |
| 366 r = Rect( 2, 4, 6, 8 ) | |
| 367 r2 = Rect( r ) | |
| 368 r2.inflate_ip( -4, -6 ) | |
| 369 | |
| 370 self.assertEqual( r.center, r2.center ) | |
| 371 self.assertEqual( r.left+2, r2.left ) | |
| 372 self.assertEqual( r.top+3, r2.top ) | |
| 373 self.assertEqual( r.right-2, r2.right ) | |
| 374 self.assertEqual( r.bottom-3, r2.bottom ) | |
| 375 self.assertEqual( r.width-4, r2.width ) | |
| 376 self.assertEqual( r.height-6, r2.height ) | |
| 377 | |
|
1148
1d1ed35fb837
Added in many test stubs, hopefully some test faeries will fill some of them out.
akalias
parents:
716
diff
changeset
|
378 def test_inflate_ip__smaller( self ): |
| 312 | 379 "The inflate method inflates around the center of the rectangle" |
| 380 r = Rect( 2, 4, 6, 8 ) | |
| 381 r2 = Rect( r ) | |
| 382 r2.inflate_ip( -4, -6 ) | |
| 383 | |
| 384 self.assertEqual( r.center, r2.center ) | |
| 385 self.assertEqual( r.left+2, r2.left ) | |
| 386 self.assertEqual( r.top+3, r2.top ) | |
| 387 self.assertEqual( r.right-2, r2.right ) | |
| 388 self.assertEqual( r.bottom-3, r2.bottom ) | |
| 389 self.assertEqual( r.width-4, r2.width ) | |
| 390 self.assertEqual( r.height-6, r2.height ) | |
| 391 | |
|
1148
1d1ed35fb837
Added in many test stubs, hopefully some test faeries will fill some of them out.
akalias
parents:
716
diff
changeset
|
392 def test_clamp( self ): |
| 312 | 393 r = Rect(10, 10, 10, 10) |
| 394 c = Rect(19, 12, 5, 5).clamp(r) | |
| 395 self.assertEqual(c.right, r.right) | |
| 396 self.assertEqual(c.top, 12) | |
| 397 c = Rect(1, 2, 3, 4).clamp(r) | |
| 398 self.assertEqual(c.topleft, r.topleft) | |
| 399 c = Rect(5, 500, 22, 33).clamp(r) | |
| 400 self.assertEqual(c.center, r.center) | |
| 401 | |
|
1148
1d1ed35fb837
Added in many test stubs, hopefully some test faeries will fill some of them out.
akalias
parents:
716
diff
changeset
|
402 def test_clamp_ip( self ): |
| 312 | 403 r = Rect(10, 10, 10, 10) |
| 404 c = Rect(19, 12, 5, 5) | |
| 405 c.clamp_ip(r) | |
| 406 self.assertEqual(c.right, r.right) | |
| 407 self.assertEqual(c.top, 12) | |
| 408 c = Rect(1, 2, 3, 4) | |
| 409 c.clamp_ip(r) | |
| 410 self.assertEqual(c.topleft, r.topleft) | |
| 411 c = Rect(5, 500, 22, 33) | |
| 412 c.clamp_ip(r) | |
| 413 self.assertEqual(c.center, r.center) | |
| 414 | |
|
1148
1d1ed35fb837
Added in many test stubs, hopefully some test faeries will fill some of them out.
akalias
parents:
716
diff
changeset
|
415 def test_clip( self ): |
| 312 | 416 r1 = Rect( 1, 2, 3, 4 ) |
| 417 self.assertEqual( Rect( 1, 2, 2, 2 ), r1.clip( Rect(0,0,3,4) ) ) | |
| 418 self.assertEqual( Rect( 2, 2, 2, 4 ), r1.clip( Rect(2,2,10,20) ) ) | |
| 419 self.assertEqual( Rect(2,3,1,2), r1.clip( Rect(2,3,1,2) ) ) | |
| 420 self.assertEqual( (0,0), r1.clip(20,30,5,6).size ) | |
| 421 self.assertEqual( r1, r1.clip( Rect(r1) ), | |
| 422 "r1 does not clip an identical rect to itself" ) | |
| 423 | |
|
1148
1d1ed35fb837
Added in many test stubs, hopefully some test faeries will fill some of them out.
akalias
parents:
716
diff
changeset
|
424 def test_move( self ): |
| 312 | 425 r = Rect( 1, 2, 3, 4 ) |
| 426 move_x = 10 | |
| 427 move_y = 20 | |
| 428 r2 = r.move( move_x, move_y ) | |
| 429 expected_r2 = Rect(r.left+move_x,r.top+move_y,r.width,r.height) | |
| 430 self.assertEqual( expected_r2, r2 ) | |
| 431 | |
|
1148
1d1ed35fb837
Added in many test stubs, hopefully some test faeries will fill some of them out.
akalias
parents:
716
diff
changeset
|
432 def test_move_ip( self ): |
| 312 | 433 r = Rect( 1, 2, 3, 4 ) |
| 434 r2 = Rect( r ) | |
| 435 move_x = 10 | |
| 436 move_y = 20 | |
| 437 r2.move_ip( move_x, move_y ) | |
| 438 expected_r2 = Rect(r.left+move_x,r.top+move_y,r.width,r.height) | |
| 439 self.assertEqual( expected_r2, r2 ) | |
| 440 | |
|
1148
1d1ed35fb837
Added in many test stubs, hopefully some test faeries will fill some of them out.
akalias
parents:
716
diff
changeset
|
441 def test_union( self ): |
| 312 | 442 r1 = Rect( 1, 1, 1, 2 ) |
| 443 r2 = Rect( -2, -2, 1, 2 ) | |
| 444 self.assertEqual( Rect( -2, -2, 4, 5 ), r1.union(r2) ) | |
| 445 | |
|
1148
1d1ed35fb837
Added in many test stubs, hopefully some test faeries will fill some of them out.
akalias
parents:
716
diff
changeset
|
446 def test_union__with_identical_Rect( self ): |
| 312 | 447 r1 = Rect( 1, 2, 3, 4 ) |
| 448 self.assertEqual( r1, r1.union( Rect(r1) ) ) | |
| 449 | |
|
1148
1d1ed35fb837
Added in many test stubs, hopefully some test faeries will fill some of them out.
akalias
parents:
716
diff
changeset
|
450 def test_union_ip( self ): |
| 312 | 451 r1 = Rect( 1, 1, 1, 2 ) |
| 452 r2 = Rect( -2, -2, 1, 2 ) | |
| 453 r1.union_ip(r2) | |
| 454 self.assertEqual( Rect( -2, -2, 4, 5 ), r1 ) | |
| 455 | |
|
1148
1d1ed35fb837
Added in many test stubs, hopefully some test faeries will fill some of them out.
akalias
parents:
716
diff
changeset
|
456 def test_unionall( self ): |
| 312 | 457 r1 = Rect( 0, 0, 1, 1 ) |
| 458 r2 = Rect( -2, -2, 1, 1 ) | |
| 459 r3 = Rect( 2, 2, 1, 1 ) | |
| 460 | |
| 461 r4 = r1.unionall( [r2,r3] ) | |
| 462 self.assertEqual( Rect(-2, -2, 5, 5), r4 ) | |
| 463 | |
|
1148
1d1ed35fb837
Added in many test stubs, hopefully some test faeries will fill some of them out.
akalias
parents:
716
diff
changeset
|
464 def test_unionall_ip( self ): |
| 312 | 465 r1 = Rect( 0, 0, 1, 1 ) |
| 466 r2 = Rect( -2, -2, 1, 1 ) | |
| 467 r3 = Rect( 2, 2, 1, 1 ) | |
| 468 | |
| 469 r1.unionall_ip( [r2,r3] ) | |
| 470 self.assertEqual( Rect(-2, -2, 5, 5), r1 ) | |
| 471 | |
|
716
acb060da6d60
Added a test for comparisons of rects.
Rene Dudfield <renesd@gmail.com>
parents:
312
diff
changeset
|
472 |
|
acb060da6d60
Added a test for comparisons of rects.
Rene Dudfield <renesd@gmail.com>
parents:
312
diff
changeset
|
473 |
|
1148
1d1ed35fb837
Added in many test stubs, hopefully some test faeries will fill some of them out.
akalias
parents:
716
diff
changeset
|
474 def test_colliderect( self ): |
| 312 | 475 r1 = Rect(1,2,3,4) |
| 476 self.failUnless( r1.colliderect( Rect(0,0,2,3) ), | |
| 477 "r1 does not collide with Rect(0,0,2,3)" ) | |
| 478 self.failIf( r1.colliderect( Rect(0,0,1,2) ), | |
| 479 "r1 collides with Rect(0,0,1,2)" ) | |
| 480 self.failIf( r1.colliderect( Rect(r1.right,r1.bottom,2,2) ), | |
| 481 "r1 collides with Rect(r1.right,r1.bottom,2,2)" ) | |
| 482 self.failUnless( r1.colliderect( Rect(r1.left+1,r1.top+1, | |
| 483 r1.width-2,r1.height-2) ), | |
| 484 "r1 does not collide with Rect(r1.left+1,r1.top+1,"+ | |
| 485 "r1.width-2,r1.height-2)" ) | |
| 486 self.failUnless( r1.colliderect( Rect(r1.left-1,r1.top-1, | |
| 487 r1.width+2,r1.height+2) ), | |
| 488 "r1 does not collide with Rect(r1.left-1,r1.top-1,"+ | |
| 489 "r1.width+2,r1.height+2)" ) | |
| 490 self.failUnless( r1.colliderect( Rect(r1) ), | |
| 491 "r1 does not collide with an identical rect" ) | |
| 492 self.failIf( r1.colliderect( Rect(r1.right,r1.bottom,0,0) ), | |
| 493 "r1 collides with Rect(r1.right,r1.bottom,0,0)" ) | |
| 494 self.failIf( r1.colliderect( Rect(r1.right,r1.bottom,1,1) ), | |
| 495 "r1 collides with Rect(r1.right,r1.bottom,1,1)" ) | |
| 496 | |
|
716
acb060da6d60
Added a test for comparisons of rects.
Rene Dudfield <renesd@gmail.com>
parents:
312
diff
changeset
|
497 def testEquals( self ): |
|
acb060da6d60
Added a test for comparisons of rects.
Rene Dudfield <renesd@gmail.com>
parents:
312
diff
changeset
|
498 """ check to see how the rect uses __eq__ |
|
acb060da6d60
Added a test for comparisons of rects.
Rene Dudfield <renesd@gmail.com>
parents:
312
diff
changeset
|
499 """ |
|
acb060da6d60
Added a test for comparisons of rects.
Rene Dudfield <renesd@gmail.com>
parents:
312
diff
changeset
|
500 r1 = Rect(1,2,3,4) |
|
acb060da6d60
Added a test for comparisons of rects.
Rene Dudfield <renesd@gmail.com>
parents:
312
diff
changeset
|
501 r2 = Rect(10,20,30,40) |
|
acb060da6d60
Added a test for comparisons of rects.
Rene Dudfield <renesd@gmail.com>
parents:
312
diff
changeset
|
502 r3 = (10,20,30,40) |
|
acb060da6d60
Added a test for comparisons of rects.
Rene Dudfield <renesd@gmail.com>
parents:
312
diff
changeset
|
503 r4 = Rect(10,20,30,40) |
|
acb060da6d60
Added a test for comparisons of rects.
Rene Dudfield <renesd@gmail.com>
parents:
312
diff
changeset
|
504 |
|
acb060da6d60
Added a test for comparisons of rects.
Rene Dudfield <renesd@gmail.com>
parents:
312
diff
changeset
|
505 class foo (Rect): |
|
acb060da6d60
Added a test for comparisons of rects.
Rene Dudfield <renesd@gmail.com>
parents:
312
diff
changeset
|
506 def __eq__(self,other): |
|
acb060da6d60
Added a test for comparisons of rects.
Rene Dudfield <renesd@gmail.com>
parents:
312
diff
changeset
|
507 return id(self) == id(other); |
|
acb060da6d60
Added a test for comparisons of rects.
Rene Dudfield <renesd@gmail.com>
parents:
312
diff
changeset
|
508 |
|
acb060da6d60
Added a test for comparisons of rects.
Rene Dudfield <renesd@gmail.com>
parents:
312
diff
changeset
|
509 class foo2 (Rect): |
|
acb060da6d60
Added a test for comparisons of rects.
Rene Dudfield <renesd@gmail.com>
parents:
312
diff
changeset
|
510 pass |
|
acb060da6d60
Added a test for comparisons of rects.
Rene Dudfield <renesd@gmail.com>
parents:
312
diff
changeset
|
511 |
|
acb060da6d60
Added a test for comparisons of rects.
Rene Dudfield <renesd@gmail.com>
parents:
312
diff
changeset
|
512 r5 = foo(10,20,30,40) |
|
acb060da6d60
Added a test for comparisons of rects.
Rene Dudfield <renesd@gmail.com>
parents:
312
diff
changeset
|
513 r6 = foo2(10,20,30,40) |
|
acb060da6d60
Added a test for comparisons of rects.
Rene Dudfield <renesd@gmail.com>
parents:
312
diff
changeset
|
514 |
|
acb060da6d60
Added a test for comparisons of rects.
Rene Dudfield <renesd@gmail.com>
parents:
312
diff
changeset
|
515 self.assertNotEqual(r5, r2) |
|
acb060da6d60
Added a test for comparisons of rects.
Rene Dudfield <renesd@gmail.com>
parents:
312
diff
changeset
|
516 |
|
acb060da6d60
Added a test for comparisons of rects.
Rene Dudfield <renesd@gmail.com>
parents:
312
diff
changeset
|
517 # because we define equality differently for this subclass. |
|
acb060da6d60
Added a test for comparisons of rects.
Rene Dudfield <renesd@gmail.com>
parents:
312
diff
changeset
|
518 self.assertEqual(r6, r2) |
|
acb060da6d60
Added a test for comparisons of rects.
Rene Dudfield <renesd@gmail.com>
parents:
312
diff
changeset
|
519 |
|
acb060da6d60
Added a test for comparisons of rects.
Rene Dudfield <renesd@gmail.com>
parents:
312
diff
changeset
|
520 |
|
acb060da6d60
Added a test for comparisons of rects.
Rene Dudfield <renesd@gmail.com>
parents:
312
diff
changeset
|
521 rect_list = [r1,r2,r3,r4,r6] |
|
acb060da6d60
Added a test for comparisons of rects.
Rene Dudfield <renesd@gmail.com>
parents:
312
diff
changeset
|
522 |
|
acb060da6d60
Added a test for comparisons of rects.
Rene Dudfield <renesd@gmail.com>
parents:
312
diff
changeset
|
523 # see if we can remove 4 of these. |
|
acb060da6d60
Added a test for comparisons of rects.
Rene Dudfield <renesd@gmail.com>
parents:
312
diff
changeset
|
524 rect_list.remove(r2) |
|
acb060da6d60
Added a test for comparisons of rects.
Rene Dudfield <renesd@gmail.com>
parents:
312
diff
changeset
|
525 rect_list.remove(r2) |
|
acb060da6d60
Added a test for comparisons of rects.
Rene Dudfield <renesd@gmail.com>
parents:
312
diff
changeset
|
526 rect_list.remove(r2) |
|
acb060da6d60
Added a test for comparisons of rects.
Rene Dudfield <renesd@gmail.com>
parents:
312
diff
changeset
|
527 rect_list.remove(r2) |
|
acb060da6d60
Added a test for comparisons of rects.
Rene Dudfield <renesd@gmail.com>
parents:
312
diff
changeset
|
528 self.assertRaises(ValueError, rect_list.remove, r2) |
|
acb060da6d60
Added a test for comparisons of rects.
Rene Dudfield <renesd@gmail.com>
parents:
312
diff
changeset
|
529 |
|
1547
f4e8669d6af7
Patch from Sean Berry updating missing tests for Rects.
Rene Dudfield <renesd@gmail.com>
parents:
1506
diff
changeset
|
530 def test_collidedict(self): |
|
1261
f3691359950b
Made all unimplemented tests use todo_test_xxxx naming and updated the __doc__'s. Run's only implemented tests by default.
akalias
parents:
1239
diff
changeset
|
531 |
|
f3691359950b
Made all unimplemented tests use todo_test_xxxx naming and updated the __doc__'s. Run's only implemented tests by default.
akalias
parents:
1239
diff
changeset
|
532 # __doc__ (as of 2008-08-02) for pygame.rect.Rect.collidedict: |
|
f3691359950b
Made all unimplemented tests use todo_test_xxxx naming and updated the __doc__'s. Run's only implemented tests by default.
akalias
parents:
1239
diff
changeset
|
533 |
|
f3691359950b
Made all unimplemented tests use todo_test_xxxx naming and updated the __doc__'s. Run's only implemented tests by default.
akalias
parents:
1239
diff
changeset
|
534 # Rect.collidedict(dict): return (key, value) |
|
f3691359950b
Made all unimplemented tests use todo_test_xxxx naming and updated the __doc__'s. Run's only implemented tests by default.
akalias
parents:
1239
diff
changeset
|
535 # test if one rectangle in a dictionary intersects |
|
f3691359950b
Made all unimplemented tests use todo_test_xxxx naming and updated the __doc__'s. Run's only implemented tests by default.
akalias
parents:
1239
diff
changeset
|
536 # |
|
f3691359950b
Made all unimplemented tests use todo_test_xxxx naming and updated the __doc__'s. Run's only implemented tests by default.
akalias
parents:
1239
diff
changeset
|
537 # Returns the key and value of the first dictionary value that |
|
f3691359950b
Made all unimplemented tests use todo_test_xxxx naming and updated the __doc__'s. Run's only implemented tests by default.
akalias
parents:
1239
diff
changeset
|
538 # collides with the Rect. If no collisions are found, None is |
|
f3691359950b
Made all unimplemented tests use todo_test_xxxx naming and updated the __doc__'s. Run's only implemented tests by default.
akalias
parents:
1239
diff
changeset
|
539 # returned. |
|
f3691359950b
Made all unimplemented tests use todo_test_xxxx naming and updated the __doc__'s. Run's only implemented tests by default.
akalias
parents:
1239
diff
changeset
|
540 # |
|
f3691359950b
Made all unimplemented tests use todo_test_xxxx naming and updated the __doc__'s. Run's only implemented tests by default.
akalias
parents:
1239
diff
changeset
|
541 # Rect objects are not hashable and cannot be used as keys in a |
|
f3691359950b
Made all unimplemented tests use todo_test_xxxx naming and updated the __doc__'s. Run's only implemented tests by default.
akalias
parents:
1239
diff
changeset
|
542 # dictionary, only as values. |
|
f3691359950b
Made all unimplemented tests use todo_test_xxxx naming and updated the __doc__'s. Run's only implemented tests by default.
akalias
parents:
1239
diff
changeset
|
543 |
|
1547
f4e8669d6af7
Patch from Sean Berry updating missing tests for Rects.
Rene Dudfield <renesd@gmail.com>
parents:
1506
diff
changeset
|
544 r = Rect(1, 1, 10, 10) |
|
f4e8669d6af7
Patch from Sean Berry updating missing tests for Rects.
Rene Dudfield <renesd@gmail.com>
parents:
1506
diff
changeset
|
545 r1 = Rect(1, 1, 10, 10) |
|
f4e8669d6af7
Patch from Sean Berry updating missing tests for Rects.
Rene Dudfield <renesd@gmail.com>
parents:
1506
diff
changeset
|
546 r2 = Rect(50, 50, 10, 10) |
|
f4e8669d6af7
Patch from Sean Berry updating missing tests for Rects.
Rene Dudfield <renesd@gmail.com>
parents:
1506
diff
changeset
|
547 r3 = Rect(70, 70, 10, 10) |
|
f4e8669d6af7
Patch from Sean Berry updating missing tests for Rects.
Rene Dudfield <renesd@gmail.com>
parents:
1506
diff
changeset
|
548 r4 = Rect(61, 61, 10, 10) |
|
f4e8669d6af7
Patch from Sean Berry updating missing tests for Rects.
Rene Dudfield <renesd@gmail.com>
parents:
1506
diff
changeset
|
549 |
|
f4e8669d6af7
Patch from Sean Berry updating missing tests for Rects.
Rene Dudfield <renesd@gmail.com>
parents:
1506
diff
changeset
|
550 d = {1: r1, 2: r2, 3: r3} |
|
1261
f3691359950b
Made all unimplemented tests use todo_test_xxxx naming and updated the __doc__'s. Run's only implemented tests by default.
akalias
parents:
1239
diff
changeset
|
551 |
|
1547
f4e8669d6af7
Patch from Sean Berry updating missing tests for Rects.
Rene Dudfield <renesd@gmail.com>
parents:
1506
diff
changeset
|
552 rects_values = 1 |
|
f4e8669d6af7
Patch from Sean Berry updating missing tests for Rects.
Rene Dudfield <renesd@gmail.com>
parents:
1506
diff
changeset
|
553 val = r.collidedict(d, rects_values) |
|
f4e8669d6af7
Patch from Sean Berry updating missing tests for Rects.
Rene Dudfield <renesd@gmail.com>
parents:
1506
diff
changeset
|
554 self.assertTrue(val) |
|
f4e8669d6af7
Patch from Sean Berry updating missing tests for Rects.
Rene Dudfield <renesd@gmail.com>
parents:
1506
diff
changeset
|
555 self.assertEqual(len(val), 2) |
|
f4e8669d6af7
Patch from Sean Berry updating missing tests for Rects.
Rene Dudfield <renesd@gmail.com>
parents:
1506
diff
changeset
|
556 self.assertEqual(val[0], 1) |
|
f4e8669d6af7
Patch from Sean Berry updating missing tests for Rects.
Rene Dudfield <renesd@gmail.com>
parents:
1506
diff
changeset
|
557 self.assertEqual(val[1], r1) |
|
f4e8669d6af7
Patch from Sean Berry updating missing tests for Rects.
Rene Dudfield <renesd@gmail.com>
parents:
1506
diff
changeset
|
558 |
|
f4e8669d6af7
Patch from Sean Berry updating missing tests for Rects.
Rene Dudfield <renesd@gmail.com>
parents:
1506
diff
changeset
|
559 none_d = {2: r2, 3: r3} |
|
f4e8669d6af7
Patch from Sean Berry updating missing tests for Rects.
Rene Dudfield <renesd@gmail.com>
parents:
1506
diff
changeset
|
560 none_val = r.collidedict(none_d, rects_values) |
|
f4e8669d6af7
Patch from Sean Berry updating missing tests for Rects.
Rene Dudfield <renesd@gmail.com>
parents:
1506
diff
changeset
|
561 self.assertFalse(none_val) |
|
f4e8669d6af7
Patch from Sean Berry updating missing tests for Rects.
Rene Dudfield <renesd@gmail.com>
parents:
1506
diff
changeset
|
562 |
|
f4e8669d6af7
Patch from Sean Berry updating missing tests for Rects.
Rene Dudfield <renesd@gmail.com>
parents:
1506
diff
changeset
|
563 barely_d = {1: r1, 2: r2, 3: r3} |
|
f4e8669d6af7
Patch from Sean Berry updating missing tests for Rects.
Rene Dudfield <renesd@gmail.com>
parents:
1506
diff
changeset
|
564 k3, v3 = r4.collidedict(barely_d, rects_values) |
|
f4e8669d6af7
Patch from Sean Berry updating missing tests for Rects.
Rene Dudfield <renesd@gmail.com>
parents:
1506
diff
changeset
|
565 self.assertEqual(k3, 3) |
|
f4e8669d6af7
Patch from Sean Berry updating missing tests for Rects.
Rene Dudfield <renesd@gmail.com>
parents:
1506
diff
changeset
|
566 self.assertEqual(v3, r3) |
|
f4e8669d6af7
Patch from Sean Berry updating missing tests for Rects.
Rene Dudfield <renesd@gmail.com>
parents:
1506
diff
changeset
|
567 |
|
f4e8669d6af7
Patch from Sean Berry updating missing tests for Rects.
Rene Dudfield <renesd@gmail.com>
parents:
1506
diff
changeset
|
568 |
|
f4e8669d6af7
Patch from Sean Berry updating missing tests for Rects.
Rene Dudfield <renesd@gmail.com>
parents:
1506
diff
changeset
|
569 def test_collidedictall(self): |
|
1261
f3691359950b
Made all unimplemented tests use todo_test_xxxx naming and updated the __doc__'s. Run's only implemented tests by default.
akalias
parents:
1239
diff
changeset
|
570 |
|
f3691359950b
Made all unimplemented tests use todo_test_xxxx naming and updated the __doc__'s. Run's only implemented tests by default.
akalias
parents:
1239
diff
changeset
|
571 # __doc__ (as of 2008-08-02) for pygame.rect.Rect.collidedictall: |
|
f3691359950b
Made all unimplemented tests use todo_test_xxxx naming and updated the __doc__'s. Run's only implemented tests by default.
akalias
parents:
1239
diff
changeset
|
572 |
|
f3691359950b
Made all unimplemented tests use todo_test_xxxx naming and updated the __doc__'s. Run's only implemented tests by default.
akalias
parents:
1239
diff
changeset
|
573 # Rect.collidedictall(dict): return [(key, value), ...] |
|
f3691359950b
Made all unimplemented tests use todo_test_xxxx naming and updated the __doc__'s. Run's only implemented tests by default.
akalias
parents:
1239
diff
changeset
|
574 # test if all rectangles in a dictionary intersect |
|
f3691359950b
Made all unimplemented tests use todo_test_xxxx naming and updated the __doc__'s. Run's only implemented tests by default.
akalias
parents:
1239
diff
changeset
|
575 # |
|
f3691359950b
Made all unimplemented tests use todo_test_xxxx naming and updated the __doc__'s. Run's only implemented tests by default.
akalias
parents:
1239
diff
changeset
|
576 # Returns a list of all the key and value pairs that intersect with |
|
f3691359950b
Made all unimplemented tests use todo_test_xxxx naming and updated the __doc__'s. Run's only implemented tests by default.
akalias
parents:
1239
diff
changeset
|
577 # the Rect. If no collisions are found an empty dictionary is |
|
f3691359950b
Made all unimplemented tests use todo_test_xxxx naming and updated the __doc__'s. Run's only implemented tests by default.
akalias
parents:
1239
diff
changeset
|
578 # returned. |
|
f3691359950b
Made all unimplemented tests use todo_test_xxxx naming and updated the __doc__'s. Run's only implemented tests by default.
akalias
parents:
1239
diff
changeset
|
579 # |
|
f3691359950b
Made all unimplemented tests use todo_test_xxxx naming and updated the __doc__'s. Run's only implemented tests by default.
akalias
parents:
1239
diff
changeset
|
580 # Rect objects are not hashable and cannot be used as keys in a |
|
f3691359950b
Made all unimplemented tests use todo_test_xxxx naming and updated the __doc__'s. Run's only implemented tests by default.
akalias
parents:
1239
diff
changeset
|
581 # dictionary, only as values. |
|
f3691359950b
Made all unimplemented tests use todo_test_xxxx naming and updated the __doc__'s. Run's only implemented tests by default.
akalias
parents:
1239
diff
changeset
|
582 |
|
1547
f4e8669d6af7
Patch from Sean Berry updating missing tests for Rects.
Rene Dudfield <renesd@gmail.com>
parents:
1506
diff
changeset
|
583 r = Rect(1, 1, 10, 10) |
|
f4e8669d6af7
Patch from Sean Berry updating missing tests for Rects.
Rene Dudfield <renesd@gmail.com>
parents:
1506
diff
changeset
|
584 |
|
f4e8669d6af7
Patch from Sean Berry updating missing tests for Rects.
Rene Dudfield <renesd@gmail.com>
parents:
1506
diff
changeset
|
585 r2 = Rect(1, 1, 10, 10) |
|
f4e8669d6af7
Patch from Sean Berry updating missing tests for Rects.
Rene Dudfield <renesd@gmail.com>
parents:
1506
diff
changeset
|
586 r3 = Rect(5, 5, 10, 10) |
|
f4e8669d6af7
Patch from Sean Berry updating missing tests for Rects.
Rene Dudfield <renesd@gmail.com>
parents:
1506
diff
changeset
|
587 r4 = Rect(10, 10, 10, 10) |
|
f4e8669d6af7
Patch from Sean Berry updating missing tests for Rects.
Rene Dudfield <renesd@gmail.com>
parents:
1506
diff
changeset
|
588 r5 = Rect(50, 50, 10, 10) |
|
1261
f3691359950b
Made all unimplemented tests use todo_test_xxxx naming and updated the __doc__'s. Run's only implemented tests by default.
akalias
parents:
1239
diff
changeset
|
589 |
|
1547
f4e8669d6af7
Patch from Sean Berry updating missing tests for Rects.
Rene Dudfield <renesd@gmail.com>
parents:
1506
diff
changeset
|
590 rects_values = 1 |
|
f4e8669d6af7
Patch from Sean Berry updating missing tests for Rects.
Rene Dudfield <renesd@gmail.com>
parents:
1506
diff
changeset
|
591 d = {2: r2} |
|
f4e8669d6af7
Patch from Sean Berry updating missing tests for Rects.
Rene Dudfield <renesd@gmail.com>
parents:
1506
diff
changeset
|
592 l = r.collidedictall(d, rects_values) |
|
f4e8669d6af7
Patch from Sean Berry updating missing tests for Rects.
Rene Dudfield <renesd@gmail.com>
parents:
1506
diff
changeset
|
593 self.assertEqual(l, [(2, r2)]) |
|
f4e8669d6af7
Patch from Sean Berry updating missing tests for Rects.
Rene Dudfield <renesd@gmail.com>
parents:
1506
diff
changeset
|
594 |
|
f4e8669d6af7
Patch from Sean Berry updating missing tests for Rects.
Rene Dudfield <renesd@gmail.com>
parents:
1506
diff
changeset
|
595 d2 = {2: r2, 3: r3, 4: r4, 5: r5} |
|
f4e8669d6af7
Patch from Sean Berry updating missing tests for Rects.
Rene Dudfield <renesd@gmail.com>
parents:
1506
diff
changeset
|
596 l2 = r.collidedictall(d2, rects_values) |
|
f4e8669d6af7
Patch from Sean Berry updating missing tests for Rects.
Rene Dudfield <renesd@gmail.com>
parents:
1506
diff
changeset
|
597 self.assertEqual(l2, [(2, r2), (3, r3), (4, r4)]) |
|
f4e8669d6af7
Patch from Sean Berry updating missing tests for Rects.
Rene Dudfield <renesd@gmail.com>
parents:
1506
diff
changeset
|
598 |
|
f4e8669d6af7
Patch from Sean Berry updating missing tests for Rects.
Rene Dudfield <renesd@gmail.com>
parents:
1506
diff
changeset
|
599 def test_collidelist(self): |
|
1261
f3691359950b
Made all unimplemented tests use todo_test_xxxx naming and updated the __doc__'s. Run's only implemented tests by default.
akalias
parents:
1239
diff
changeset
|
600 |
|
f3691359950b
Made all unimplemented tests use todo_test_xxxx naming and updated the __doc__'s. Run's only implemented tests by default.
akalias
parents:
1239
diff
changeset
|
601 # __doc__ (as of 2008-08-02) for pygame.rect.Rect.collidelist: |
|
f3691359950b
Made all unimplemented tests use todo_test_xxxx naming and updated the __doc__'s. Run's only implemented tests by default.
akalias
parents:
1239
diff
changeset
|
602 |
|
f3691359950b
Made all unimplemented tests use todo_test_xxxx naming and updated the __doc__'s. Run's only implemented tests by default.
akalias
parents:
1239
diff
changeset
|
603 # Rect.collidelist(list): return index |
|
f3691359950b
Made all unimplemented tests use todo_test_xxxx naming and updated the __doc__'s. Run's only implemented tests by default.
akalias
parents:
1239
diff
changeset
|
604 # test if one rectangle in a list intersects |
|
f3691359950b
Made all unimplemented tests use todo_test_xxxx naming and updated the __doc__'s. Run's only implemented tests by default.
akalias
parents:
1239
diff
changeset
|
605 # |
|
f3691359950b
Made all unimplemented tests use todo_test_xxxx naming and updated the __doc__'s. Run's only implemented tests by default.
akalias
parents:
1239
diff
changeset
|
606 # Test whether the rectangle collides with any in a sequence of |
|
f3691359950b
Made all unimplemented tests use todo_test_xxxx naming and updated the __doc__'s. Run's only implemented tests by default.
akalias
parents:
1239
diff
changeset
|
607 # rectangles. The index of the first collision found is returned. If |
|
f3691359950b
Made all unimplemented tests use todo_test_xxxx naming and updated the __doc__'s. Run's only implemented tests by default.
akalias
parents:
1239
diff
changeset
|
608 # no collisions are found an index of -1 is returned. |
|
f3691359950b
Made all unimplemented tests use todo_test_xxxx naming and updated the __doc__'s. Run's only implemented tests by default.
akalias
parents:
1239
diff
changeset
|
609 |
|
1547
f4e8669d6af7
Patch from Sean Berry updating missing tests for Rects.
Rene Dudfield <renesd@gmail.com>
parents:
1506
diff
changeset
|
610 r = Rect(1, 1, 10, 10) |
|
f4e8669d6af7
Patch from Sean Berry updating missing tests for Rects.
Rene Dudfield <renesd@gmail.com>
parents:
1506
diff
changeset
|
611 l = [Rect(50, 50, 1, 1), Rect(5, 5, 10, 10), Rect(15, 15, 1, 1)] |
|
f4e8669d6af7
Patch from Sean Berry updating missing tests for Rects.
Rene Dudfield <renesd@gmail.com>
parents:
1506
diff
changeset
|
612 |
|
f4e8669d6af7
Patch from Sean Berry updating missing tests for Rects.
Rene Dudfield <renesd@gmail.com>
parents:
1506
diff
changeset
|
613 self.assertEqual(r.collidelist(l), 1) |
|
1261
f3691359950b
Made all unimplemented tests use todo_test_xxxx naming and updated the __doc__'s. Run's only implemented tests by default.
akalias
parents:
1239
diff
changeset
|
614 |
|
1547
f4e8669d6af7
Patch from Sean Berry updating missing tests for Rects.
Rene Dudfield <renesd@gmail.com>
parents:
1506
diff
changeset
|
615 f = [Rect(50, 50, 1, 1), (100, 100, 4, 4)] |
|
f4e8669d6af7
Patch from Sean Berry updating missing tests for Rects.
Rene Dudfield <renesd@gmail.com>
parents:
1506
diff
changeset
|
616 self.assertEqual(r.collidelist(f), -1) |
|
f4e8669d6af7
Patch from Sean Berry updating missing tests for Rects.
Rene Dudfield <renesd@gmail.com>
parents:
1506
diff
changeset
|
617 |
|
f4e8669d6af7
Patch from Sean Berry updating missing tests for Rects.
Rene Dudfield <renesd@gmail.com>
parents:
1506
diff
changeset
|
618 |
|
f4e8669d6af7
Patch from Sean Berry updating missing tests for Rects.
Rene Dudfield <renesd@gmail.com>
parents:
1506
diff
changeset
|
619 def test_collidelistall(self): |
|
1261
f3691359950b
Made all unimplemented tests use todo_test_xxxx naming and updated the __doc__'s. Run's only implemented tests by default.
akalias
parents:
1239
diff
changeset
|
620 |
|
f3691359950b
Made all unimplemented tests use todo_test_xxxx naming and updated the __doc__'s. Run's only implemented tests by default.
akalias
parents:
1239
diff
changeset
|
621 # __doc__ (as of 2008-08-02) for pygame.rect.Rect.collidelistall: |
|
f3691359950b
Made all unimplemented tests use todo_test_xxxx naming and updated the __doc__'s. Run's only implemented tests by default.
akalias
parents:
1239
diff
changeset
|
622 |
|
f3691359950b
Made all unimplemented tests use todo_test_xxxx naming and updated the __doc__'s. Run's only implemented tests by default.
akalias
parents:
1239
diff
changeset
|
623 # Rect.collidelistall(list): return indices |
|
f3691359950b
Made all unimplemented tests use todo_test_xxxx naming and updated the __doc__'s. Run's only implemented tests by default.
akalias
parents:
1239
diff
changeset
|
624 # test if all rectangles in a list intersect |
|
f3691359950b
Made all unimplemented tests use todo_test_xxxx naming and updated the __doc__'s. Run's only implemented tests by default.
akalias
parents:
1239
diff
changeset
|
625 # |
|
f3691359950b
Made all unimplemented tests use todo_test_xxxx naming and updated the __doc__'s. Run's only implemented tests by default.
akalias
parents:
1239
diff
changeset
|
626 # Returns a list of all the indices that contain rectangles that |
|
f3691359950b
Made all unimplemented tests use todo_test_xxxx naming and updated the __doc__'s. Run's only implemented tests by default.
akalias
parents:
1239
diff
changeset
|
627 # collide with the Rect. If no intersecting rectangles are found, an |
|
f3691359950b
Made all unimplemented tests use todo_test_xxxx naming and updated the __doc__'s. Run's only implemented tests by default.
akalias
parents:
1239
diff
changeset
|
628 # empty list is returned. |
|
f3691359950b
Made all unimplemented tests use todo_test_xxxx naming and updated the __doc__'s. Run's only implemented tests by default.
akalias
parents:
1239
diff
changeset
|
629 |
|
1547
f4e8669d6af7
Patch from Sean Berry updating missing tests for Rects.
Rene Dudfield <renesd@gmail.com>
parents:
1506
diff
changeset
|
630 r = Rect(1, 1, 10, 10) |
|
1261
f3691359950b
Made all unimplemented tests use todo_test_xxxx naming and updated the __doc__'s. Run's only implemented tests by default.
akalias
parents:
1239
diff
changeset
|
631 |
|
1547
f4e8669d6af7
Patch from Sean Berry updating missing tests for Rects.
Rene Dudfield <renesd@gmail.com>
parents:
1506
diff
changeset
|
632 l = [ |
|
f4e8669d6af7
Patch from Sean Berry updating missing tests for Rects.
Rene Dudfield <renesd@gmail.com>
parents:
1506
diff
changeset
|
633 Rect(1, 1, 10, 10), |
|
f4e8669d6af7
Patch from Sean Berry updating missing tests for Rects.
Rene Dudfield <renesd@gmail.com>
parents:
1506
diff
changeset
|
634 Rect(5, 5, 10, 10), |
|
f4e8669d6af7
Patch from Sean Berry updating missing tests for Rects.
Rene Dudfield <renesd@gmail.com>
parents:
1506
diff
changeset
|
635 Rect(15, 15, 1, 1), |
|
f4e8669d6af7
Patch from Sean Berry updating missing tests for Rects.
Rene Dudfield <renesd@gmail.com>
parents:
1506
diff
changeset
|
636 Rect(2, 2, 1, 1), |
|
f4e8669d6af7
Patch from Sean Berry updating missing tests for Rects.
Rene Dudfield <renesd@gmail.com>
parents:
1506
diff
changeset
|
637 ] |
|
f4e8669d6af7
Patch from Sean Berry updating missing tests for Rects.
Rene Dudfield <renesd@gmail.com>
parents:
1506
diff
changeset
|
638 self.assertEqual(r.collidelistall(l), [0, 1, 3]) |
|
f4e8669d6af7
Patch from Sean Berry updating missing tests for Rects.
Rene Dudfield <renesd@gmail.com>
parents:
1506
diff
changeset
|
639 |
|
f4e8669d6af7
Patch from Sean Berry updating missing tests for Rects.
Rene Dudfield <renesd@gmail.com>
parents:
1506
diff
changeset
|
640 f = [Rect(50, 50, 1, 1), Rect(20, 20, 5, 5)] |
|
f4e8669d6af7
Patch from Sean Berry updating missing tests for Rects.
Rene Dudfield <renesd@gmail.com>
parents:
1506
diff
changeset
|
641 self.assertFalse(r.collidelistall(f)) |
|
f4e8669d6af7
Patch from Sean Berry updating missing tests for Rects.
Rene Dudfield <renesd@gmail.com>
parents:
1506
diff
changeset
|
642 |
|
f4e8669d6af7
Patch from Sean Berry updating missing tests for Rects.
Rene Dudfield <renesd@gmail.com>
parents:
1506
diff
changeset
|
643 |
|
f4e8669d6af7
Patch from Sean Berry updating missing tests for Rects.
Rene Dudfield <renesd@gmail.com>
parents:
1506
diff
changeset
|
644 def test_fit(self): |
|
1261
f3691359950b
Made all unimplemented tests use todo_test_xxxx naming and updated the __doc__'s. Run's only implemented tests by default.
akalias
parents:
1239
diff
changeset
|
645 |
|
f3691359950b
Made all unimplemented tests use todo_test_xxxx naming and updated the __doc__'s. Run's only implemented tests by default.
akalias
parents:
1239
diff
changeset
|
646 # __doc__ (as of 2008-08-02) for pygame.rect.Rect.fit: |
|
f3691359950b
Made all unimplemented tests use todo_test_xxxx naming and updated the __doc__'s. Run's only implemented tests by default.
akalias
parents:
1239
diff
changeset
|
647 |
|
f3691359950b
Made all unimplemented tests use todo_test_xxxx naming and updated the __doc__'s. Run's only implemented tests by default.
akalias
parents:
1239
diff
changeset
|
648 # Rect.fit(Rect): return Rect |
|
f3691359950b
Made all unimplemented tests use todo_test_xxxx naming and updated the __doc__'s. Run's only implemented tests by default.
akalias
parents:
1239
diff
changeset
|
649 # resize and move a rectangle with aspect ratio |
|
f3691359950b
Made all unimplemented tests use todo_test_xxxx naming and updated the __doc__'s. Run's only implemented tests by default.
akalias
parents:
1239
diff
changeset
|
650 # |
|
f3691359950b
Made all unimplemented tests use todo_test_xxxx naming and updated the __doc__'s. Run's only implemented tests by default.
akalias
parents:
1239
diff
changeset
|
651 # Returns a new rectangle that is moved and resized to fit another. |
|
f3691359950b
Made all unimplemented tests use todo_test_xxxx naming and updated the __doc__'s. Run's only implemented tests by default.
akalias
parents:
1239
diff
changeset
|
652 # The aspect ratio of the original Rect is preserved, so the new |
|
f3691359950b
Made all unimplemented tests use todo_test_xxxx naming and updated the __doc__'s. Run's only implemented tests by default.
akalias
parents:
1239
diff
changeset
|
653 # rectangle may be smaller than the target in either width or height. |
|
f3691359950b
Made all unimplemented tests use todo_test_xxxx naming and updated the __doc__'s. Run's only implemented tests by default.
akalias
parents:
1239
diff
changeset
|
654 |
|
1547
f4e8669d6af7
Patch from Sean Berry updating missing tests for Rects.
Rene Dudfield <renesd@gmail.com>
parents:
1506
diff
changeset
|
655 r = Rect(10, 10, 30, 30) |
|
f4e8669d6af7
Patch from Sean Berry updating missing tests for Rects.
Rene Dudfield <renesd@gmail.com>
parents:
1506
diff
changeset
|
656 |
|
f4e8669d6af7
Patch from Sean Berry updating missing tests for Rects.
Rene Dudfield <renesd@gmail.com>
parents:
1506
diff
changeset
|
657 r2 = Rect(30, 30, 15, 10) |
|
f4e8669d6af7
Patch from Sean Berry updating missing tests for Rects.
Rene Dudfield <renesd@gmail.com>
parents:
1506
diff
changeset
|
658 |
|
f4e8669d6af7
Patch from Sean Berry updating missing tests for Rects.
Rene Dudfield <renesd@gmail.com>
parents:
1506
diff
changeset
|
659 f = r.fit(r2) |
|
f4e8669d6af7
Patch from Sean Berry updating missing tests for Rects.
Rene Dudfield <renesd@gmail.com>
parents:
1506
diff
changeset
|
660 self.assertTrue(r2.contains(f)) |
|
f4e8669d6af7
Patch from Sean Berry updating missing tests for Rects.
Rene Dudfield <renesd@gmail.com>
parents:
1506
diff
changeset
|
661 |
|
f4e8669d6af7
Patch from Sean Berry updating missing tests for Rects.
Rene Dudfield <renesd@gmail.com>
parents:
1506
diff
changeset
|
662 f2 = r2.fit(r) |
|
f4e8669d6af7
Patch from Sean Berry updating missing tests for Rects.
Rene Dudfield <renesd@gmail.com>
parents:
1506
diff
changeset
|
663 self.assertTrue(r.contains(f2)) |
|
f4e8669d6af7
Patch from Sean Berry updating missing tests for Rects.
Rene Dudfield <renesd@gmail.com>
parents:
1506
diff
changeset
|
664 |
|
f4e8669d6af7
Patch from Sean Berry updating missing tests for Rects.
Rene Dudfield <renesd@gmail.com>
parents:
1506
diff
changeset
|
665 |
|
1261
f3691359950b
Made all unimplemented tests use todo_test_xxxx naming and updated the __doc__'s. Run's only implemented tests by default.
akalias
parents:
1239
diff
changeset
|
666 |
|
1506
a60459a910fd
Bugzilla feature request 25: add Rect.copy method
Lenard Lindstrom <len-l@telus.net>
parents:
1418
diff
changeset
|
667 def test_copy(self): |
|
a60459a910fd
Bugzilla feature request 25: add Rect.copy method
Lenard Lindstrom <len-l@telus.net>
parents:
1418
diff
changeset
|
668 r = Rect(1, 2, 10, 20) |
|
a60459a910fd
Bugzilla feature request 25: add Rect.copy method
Lenard Lindstrom <len-l@telus.net>
parents:
1418
diff
changeset
|
669 c = r.copy() |
|
a60459a910fd
Bugzilla feature request 25: add Rect.copy method
Lenard Lindstrom <len-l@telus.net>
parents:
1418
diff
changeset
|
670 self.failUnlessEqual(c, r) |
|
a60459a910fd
Bugzilla feature request 25: add Rect.copy method
Lenard Lindstrom <len-l@telus.net>
parents:
1418
diff
changeset
|
671 |
| 312 | 672 if __name__ == '__main__': |
|
1418
af8675f5e463
test suite now pygame.tests subpackage as well
Lenard Lindstrom <len-l@telus.net>
parents:
1261
diff
changeset
|
673 unittest.main() |
