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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
396682959bc7 unit test
pygame
parents:
diff changeset
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
396682959bc7 unit test
pygame
parents:
diff changeset
17 from pygame import Rect
396682959bc7 unit test
pygame
parents:
diff changeset
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
396682959bc7 unit test
pygame
parents:
diff changeset
20 def testConstructionXYWidthHeight( self ):
396682959bc7 unit test
pygame
parents:
diff changeset
21 r = Rect(1,2,3,4)
396682959bc7 unit test
pygame
parents:
diff changeset
22 self.assertEqual( 1, r.left )
396682959bc7 unit test
pygame
parents:
diff changeset
23 self.assertEqual( 2, r.top )
396682959bc7 unit test
pygame
parents:
diff changeset
24 self.assertEqual( 3, r.width )
396682959bc7 unit test
pygame
parents:
diff changeset
25 self.assertEqual( 4, r.height )
396682959bc7 unit test
pygame
parents:
diff changeset
26
396682959bc7 unit test
pygame
parents:
diff changeset
27 def testConstructionTopLeftSize( self ):
396682959bc7 unit test
pygame
parents:
diff changeset
28 r = Rect( (1,2), (3,4) )
396682959bc7 unit test
pygame
parents:
diff changeset
29 self.assertEqual( 1, r.left )
396682959bc7 unit test
pygame
parents:
diff changeset
30 self.assertEqual( 2, r.top )
396682959bc7 unit test
pygame
parents:
diff changeset
31 self.assertEqual( 3, r.width )
396682959bc7 unit test
pygame
parents:
diff changeset
32 self.assertEqual( 4, r.height )
396682959bc7 unit test
pygame
parents:
diff changeset
33
396682959bc7 unit test
pygame
parents:
diff changeset
34 def testCalculatedAttributes( self ):
396682959bc7 unit test
pygame
parents:
diff changeset
35 r = Rect( 1, 2, 3, 4 )
396682959bc7 unit test
pygame
parents:
diff changeset
36
396682959bc7 unit test
pygame
parents:
diff changeset
37 self.assertEqual( r.left+r.width, r.right )
396682959bc7 unit test
pygame
parents:
diff changeset
38 self.assertEqual( r.top+r.height, r.bottom )
396682959bc7 unit test
pygame
parents:
diff changeset
39 self.assertEqual( (r.width,r.height), r.size )
396682959bc7 unit test
pygame
parents:
diff changeset
40 self.assertEqual( (r.left,r.top), r.topleft )
396682959bc7 unit test
pygame
parents:
diff changeset
41 self.assertEqual( (r.right,r.top), r.topright )
396682959bc7 unit test
pygame
parents:
diff changeset
42 self.assertEqual( (r.left,r.bottom), r.bottomleft )
396682959bc7 unit test
pygame
parents:
diff changeset
43 self.assertEqual( (r.right,r.bottom), r.bottomright )
396682959bc7 unit test
pygame
parents:
diff changeset
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
396682959bc7 unit test
pygame
parents:
diff changeset
47
396682959bc7 unit test
pygame
parents:
diff changeset
48 self.assertEqual( midx, r.centerx )
396682959bc7 unit test
pygame
parents:
diff changeset
49 self.assertEqual( midy, r.centery )
396682959bc7 unit test
pygame
parents:
diff changeset
50 self.assertEqual( (r.centerx,r.centery), r.center )
396682959bc7 unit test
pygame
parents:
diff changeset
51 self.assertEqual( (r.centerx,r.top), r.midtop )
396682959bc7 unit test
pygame
parents:
diff changeset
52 self.assertEqual( (r.centerx,r.bottom), r.midbottom )
396682959bc7 unit test
pygame
parents:
diff changeset
53 self.assertEqual( (r.left,r.centery), r.midleft )
396682959bc7 unit test
pygame
parents:
diff changeset
54 self.assertEqual( (r.right,r.centery), r.midright )
396682959bc7 unit test
pygame
parents:
diff changeset
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
396682959bc7 unit test
pygame
parents:
diff changeset
57 r = Rect( 1, 2, -3, -6 )
396682959bc7 unit test
pygame
parents:
diff changeset
58 r2 = Rect(r)
396682959bc7 unit test
pygame
parents:
diff changeset
59 r2.normalize()
396682959bc7 unit test
pygame
parents:
diff changeset
60 self.failUnless( r2.width >= 0 )
396682959bc7 unit test
pygame
parents:
diff changeset
61 self.failUnless( r2.height >= 0 )
396682959bc7 unit test
pygame
parents:
diff changeset
62 self.assertEqual( (abs(r.width),abs(r.height)), r2.size )
396682959bc7 unit test
pygame
parents:
diff changeset
63 self.assertEqual( (-2,-4), r2.topleft )
396682959bc7 unit test
pygame
parents:
diff changeset
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
396682959bc7 unit test
pygame
parents:
diff changeset
66 """Changing the left attribute moves the rect and does not change
396682959bc7 unit test
pygame
parents:
diff changeset
67 the rect's width
396682959bc7 unit test
pygame
parents:
diff changeset
68 """
396682959bc7 unit test
pygame
parents:
diff changeset
69 r = Rect( 1, 2, 3, 4 )
396682959bc7 unit test
pygame
parents:
diff changeset
70 new_left = 10
396682959bc7 unit test
pygame
parents:
diff changeset
71
396682959bc7 unit test
pygame
parents:
diff changeset
72 r.left = new_left
396682959bc7 unit test
pygame
parents:
diff changeset
73 self.assertEqual( new_left, r.left )
396682959bc7 unit test
pygame
parents:
diff changeset
74 self.assertEqual( Rect(new_left,2,3,4), r )
396682959bc7 unit test
pygame
parents:
diff changeset
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
396682959bc7 unit test
pygame
parents:
diff changeset
77 """Changing the right attribute moves the rect and does not change
396682959bc7 unit test
pygame
parents:
diff changeset
78 the rect's width
396682959bc7 unit test
pygame
parents:
diff changeset
79 """
396682959bc7 unit test
pygame
parents:
diff changeset
80 r = Rect( 1, 2, 3, 4 )
396682959bc7 unit test
pygame
parents:
diff changeset
81 new_right = r.right + 20
396682959bc7 unit test
pygame
parents:
diff changeset
82 expected_left = r.left + 20
396682959bc7 unit test
pygame
parents:
diff changeset
83 old_width = r.width
396682959bc7 unit test
pygame
parents:
diff changeset
84
396682959bc7 unit test
pygame
parents:
diff changeset
85 r.right = new_right
396682959bc7 unit test
pygame
parents:
diff changeset
86 self.assertEqual( new_right, r.right )
396682959bc7 unit test
pygame
parents:
diff changeset
87 self.assertEqual( expected_left, r.left )
396682959bc7 unit test
pygame
parents:
diff changeset
88 self.assertEqual( old_width, r.width )
396682959bc7 unit test
pygame
parents:
diff changeset
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
396682959bc7 unit test
pygame
parents:
diff changeset
91 """Changing the top attribute moves the rect and does not change
396682959bc7 unit test
pygame
parents:
diff changeset
92 the rect's width
396682959bc7 unit test
pygame
parents:
diff changeset
93 """
396682959bc7 unit test
pygame
parents:
diff changeset
94 r = Rect( 1, 2, 3, 4 )
396682959bc7 unit test
pygame
parents:
diff changeset
95 new_top = 10
396682959bc7 unit test
pygame
parents:
diff changeset
96
396682959bc7 unit test
pygame
parents:
diff changeset
97 r.top = new_top
396682959bc7 unit test
pygame
parents:
diff changeset
98 self.assertEqual( Rect(1,new_top,3,4), r )
396682959bc7 unit test
pygame
parents:
diff changeset
99 self.assertEqual( new_top, r.top )
396682959bc7 unit test
pygame
parents:
diff changeset
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
396682959bc7 unit test
pygame
parents:
diff changeset
102 """Changing the bottom attribute moves the rect and does not change
396682959bc7 unit test
pygame
parents:
diff changeset
103 the rect's height
396682959bc7 unit test
pygame
parents:
diff changeset
104 """
396682959bc7 unit test
pygame
parents:
diff changeset
105 r = Rect( 1, 2, 3, 4 )
396682959bc7 unit test
pygame
parents:
diff changeset
106 new_bottom = r.bottom + 20
396682959bc7 unit test
pygame
parents:
diff changeset
107 expected_top = r.top + 20
396682959bc7 unit test
pygame
parents:
diff changeset
108 old_height = r.height
396682959bc7 unit test
pygame
parents:
diff changeset
109
396682959bc7 unit test
pygame
parents:
diff changeset
110 r.bottom = new_bottom
396682959bc7 unit test
pygame
parents:
diff changeset
111 self.assertEqual( new_bottom, r.bottom )
396682959bc7 unit test
pygame
parents:
diff changeset
112 self.assertEqual( expected_top, r.top )
396682959bc7 unit test
pygame
parents:
diff changeset
113 self.assertEqual( old_height, r.height )
396682959bc7 unit test
pygame
parents:
diff changeset
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
396682959bc7 unit test
pygame
parents:
diff changeset
116 """Changing the centerx attribute moves the rect and does not change
396682959bc7 unit test
pygame
parents:
diff changeset
117 the rect's width
396682959bc7 unit test
pygame
parents:
diff changeset
118 """
396682959bc7 unit test
pygame
parents:
diff changeset
119 r = Rect( 1, 2, 3, 4 )
396682959bc7 unit test
pygame
parents:
diff changeset
120 new_centerx = r.centerx + 20
396682959bc7 unit test
pygame
parents:
diff changeset
121 expected_left = r.left + 20
396682959bc7 unit test
pygame
parents:
diff changeset
122 old_width = r.width
396682959bc7 unit test
pygame
parents:
diff changeset
123
396682959bc7 unit test
pygame
parents:
diff changeset
124 r.centerx = new_centerx
396682959bc7 unit test
pygame
parents:
diff changeset
125 self.assertEqual( new_centerx, r.centerx )
396682959bc7 unit test
pygame
parents:
diff changeset
126 self.assertEqual( expected_left, r.left )
396682959bc7 unit test
pygame
parents:
diff changeset
127 self.assertEqual( old_width, r.width )
396682959bc7 unit test
pygame
parents:
diff changeset
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
396682959bc7 unit test
pygame
parents:
diff changeset
130 """Changing the centerx attribute moves the rect and does not change
396682959bc7 unit test
pygame
parents:
diff changeset
131 the rect's width
396682959bc7 unit test
pygame
parents:
diff changeset
132 """
396682959bc7 unit test
pygame
parents:
diff changeset
133 r = Rect( 1, 2, 3, 4 )
396682959bc7 unit test
pygame
parents:
diff changeset
134 new_centery = r.centery + 20
396682959bc7 unit test
pygame
parents:
diff changeset
135 expected_top = r.top + 20
396682959bc7 unit test
pygame
parents:
diff changeset
136 old_height = r.height
396682959bc7 unit test
pygame
parents:
diff changeset
137
396682959bc7 unit test
pygame
parents:
diff changeset
138 r.centery = new_centery
396682959bc7 unit test
pygame
parents:
diff changeset
139 self.assertEqual( new_centery, r.centery )
396682959bc7 unit test
pygame
parents:
diff changeset
140 self.assertEqual( expected_top, r.top )
396682959bc7 unit test
pygame
parents:
diff changeset
141 self.assertEqual( old_height, r.height )
396682959bc7 unit test
pygame
parents:
diff changeset
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
396682959bc7 unit test
pygame
parents:
diff changeset
144 """Changing the topleft attribute moves the rect and does not change
396682959bc7 unit test
pygame
parents:
diff changeset
145 the rect's size
396682959bc7 unit test
pygame
parents:
diff changeset
146 """
396682959bc7 unit test
pygame
parents:
diff changeset
147 r = Rect( 1, 2, 3, 4 )
396682959bc7 unit test
pygame
parents:
diff changeset
148 new_topleft = (r.left+20,r.top+30)
396682959bc7 unit test
pygame
parents:
diff changeset
149 old_size = r.size
396682959bc7 unit test
pygame
parents:
diff changeset
150
396682959bc7 unit test
pygame
parents:
diff changeset
151 r.topleft = new_topleft
396682959bc7 unit test
pygame
parents:
diff changeset
152 self.assertEqual( new_topleft, r.topleft )
396682959bc7 unit test
pygame
parents:
diff changeset
153 self.assertEqual( old_size, r.size )
396682959bc7 unit test
pygame
parents:
diff changeset
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
396682959bc7 unit test
pygame
parents:
diff changeset
156 """Changing the bottomleft attribute moves the rect and does not change
396682959bc7 unit test
pygame
parents:
diff changeset
157 the rect's size
396682959bc7 unit test
pygame
parents:
diff changeset
158 """
396682959bc7 unit test
pygame
parents:
diff changeset
159 r = Rect( 1, 2, 3, 4 )
396682959bc7 unit test
pygame
parents:
diff changeset
160 new_bottomleft = (r.left+20,r.bottom+30)
396682959bc7 unit test
pygame
parents:
diff changeset
161 expected_topleft = (r.left+20,r.top+30)
396682959bc7 unit test
pygame
parents:
diff changeset
162 old_size = r.size
396682959bc7 unit test
pygame
parents:
diff changeset
163
396682959bc7 unit test
pygame
parents:
diff changeset
164 r.bottomleft = new_bottomleft
396682959bc7 unit test
pygame
parents:
diff changeset
165 self.assertEqual( new_bottomleft, r.bottomleft )
396682959bc7 unit test
pygame
parents:
diff changeset
166 self.assertEqual( expected_topleft, r.topleft )
396682959bc7 unit test
pygame
parents:
diff changeset
167 self.assertEqual( old_size, r.size )
396682959bc7 unit test
pygame
parents:
diff changeset
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
396682959bc7 unit test
pygame
parents:
diff changeset
170 """Changing the bottomleft attribute moves the rect and does not change
396682959bc7 unit test
pygame
parents:
diff changeset
171 the rect's size
396682959bc7 unit test
pygame
parents:
diff changeset
172 """
396682959bc7 unit test
pygame
parents:
diff changeset
173 r = Rect( 1, 2, 3, 4 )
396682959bc7 unit test
pygame
parents:
diff changeset
174 new_topright = (r.right+20,r.top+30)
396682959bc7 unit test
pygame
parents:
diff changeset
175 expected_topleft = (r.left+20,r.top+30)
396682959bc7 unit test
pygame
parents:
diff changeset
176 old_size = r.size
396682959bc7 unit test
pygame
parents:
diff changeset
177
396682959bc7 unit test
pygame
parents:
diff changeset
178 r.topright = new_topright
396682959bc7 unit test
pygame
parents:
diff changeset
179 self.assertEqual( new_topright, r.topright )
396682959bc7 unit test
pygame
parents:
diff changeset
180 self.assertEqual( expected_topleft, r.topleft )
396682959bc7 unit test
pygame
parents:
diff changeset
181 self.assertEqual( old_size, r.size )
396682959bc7 unit test
pygame
parents:
diff changeset
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
396682959bc7 unit test
pygame
parents:
diff changeset
184 """Changing the bottomright attribute moves the rect and does not change
396682959bc7 unit test
pygame
parents:
diff changeset
185 the rect's size
396682959bc7 unit test
pygame
parents:
diff changeset
186 """
396682959bc7 unit test
pygame
parents:
diff changeset
187 r = Rect( 1, 2, 3, 4 )
396682959bc7 unit test
pygame
parents:
diff changeset
188 new_bottomright = (r.right+20,r.bottom+30)
396682959bc7 unit test
pygame
parents:
diff changeset
189 expected_topleft = (r.left+20,r.top+30)
396682959bc7 unit test
pygame
parents:
diff changeset
190 old_size = r.size
396682959bc7 unit test
pygame
parents:
diff changeset
191
396682959bc7 unit test
pygame
parents:
diff changeset
192 r.bottomright = new_bottomright
396682959bc7 unit test
pygame
parents:
diff changeset
193 self.assertEqual( new_bottomright, r.bottomright )
396682959bc7 unit test
pygame
parents:
diff changeset
194 self.assertEqual( expected_topleft, r.topleft )
396682959bc7 unit test
pygame
parents:
diff changeset
195 self.assertEqual( old_size, r.size )
396682959bc7 unit test
pygame
parents:
diff changeset
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
396682959bc7 unit test
pygame
parents:
diff changeset
198 """Changing the center attribute moves the rect and does not change
396682959bc7 unit test
pygame
parents:
diff changeset
199 the rect's size
396682959bc7 unit test
pygame
parents:
diff changeset
200 """
396682959bc7 unit test
pygame
parents:
diff changeset
201 r = Rect( 1, 2, 3, 4 )
396682959bc7 unit test
pygame
parents:
diff changeset
202 new_center = (r.centerx+20,r.centery+30)
396682959bc7 unit test
pygame
parents:
diff changeset
203 expected_topleft = (r.left+20,r.top+30)
396682959bc7 unit test
pygame
parents:
diff changeset
204 old_size = r.size
396682959bc7 unit test
pygame
parents:
diff changeset
205
396682959bc7 unit test
pygame
parents:
diff changeset
206 r.center = new_center
396682959bc7 unit test
pygame
parents:
diff changeset
207 self.assertEqual( new_center, r.center )
396682959bc7 unit test
pygame
parents:
diff changeset
208 self.assertEqual( expected_topleft, r.topleft )
396682959bc7 unit test
pygame
parents:
diff changeset
209 self.assertEqual( old_size, r.size )
396682959bc7 unit test
pygame
parents:
diff changeset
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
396682959bc7 unit test
pygame
parents:
diff changeset
212 """Changing the midleft attribute moves the rect and does not change
396682959bc7 unit test
pygame
parents:
diff changeset
213 the rect's size
396682959bc7 unit test
pygame
parents:
diff changeset
214 """
396682959bc7 unit test
pygame
parents:
diff changeset
215 r = Rect( 1, 2, 3, 4 )
396682959bc7 unit test
pygame
parents:
diff changeset
216 new_midleft = (r.left+20,r.centery+30)
396682959bc7 unit test
pygame
parents:
diff changeset
217 expected_topleft = (r.left+20,r.top+30)
396682959bc7 unit test
pygame
parents:
diff changeset
218 old_size = r.size
396682959bc7 unit test
pygame
parents:
diff changeset
219
396682959bc7 unit test
pygame
parents:
diff changeset
220 r.midleft = new_midleft
396682959bc7 unit test
pygame
parents:
diff changeset
221 self.assertEqual( new_midleft, r.midleft )
396682959bc7 unit test
pygame
parents:
diff changeset
222 self.assertEqual( expected_topleft, r.topleft )
396682959bc7 unit test
pygame
parents:
diff changeset
223 self.assertEqual( old_size, r.size )
396682959bc7 unit test
pygame
parents:
diff changeset
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
396682959bc7 unit test
pygame
parents:
diff changeset
226 """Changing the midright attribute moves the rect and does not change
396682959bc7 unit test
pygame
parents:
diff changeset
227 the rect's size
396682959bc7 unit test
pygame
parents:
diff changeset
228 """
396682959bc7 unit test
pygame
parents:
diff changeset
229 r = Rect( 1, 2, 3, 4 )
396682959bc7 unit test
pygame
parents:
diff changeset
230 new_midright= (r.right+20,r.centery+30)
396682959bc7 unit test
pygame
parents:
diff changeset
231 expected_topleft = (r.left+20,r.top+30)
396682959bc7 unit test
pygame
parents:
diff changeset
232 old_size = r.size
396682959bc7 unit test
pygame
parents:
diff changeset
233
396682959bc7 unit test
pygame
parents:
diff changeset
234 r.midright = new_midright
396682959bc7 unit test
pygame
parents:
diff changeset
235 self.assertEqual( new_midright, r.midright )
396682959bc7 unit test
pygame
parents:
diff changeset
236 self.assertEqual( expected_topleft, r.topleft )
396682959bc7 unit test
pygame
parents:
diff changeset
237 self.assertEqual( old_size, r.size )
396682959bc7 unit test
pygame
parents:
diff changeset
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
396682959bc7 unit test
pygame
parents:
diff changeset
240 """Changing the midtop attribute moves the rect and does not change
396682959bc7 unit test
pygame
parents:
diff changeset
241 the rect's size
396682959bc7 unit test
pygame
parents:
diff changeset
242 """
396682959bc7 unit test
pygame
parents:
diff changeset
243 r = Rect( 1, 2, 3, 4 )
396682959bc7 unit test
pygame
parents:
diff changeset
244 new_midtop= (r.centerx+20,r.top+30)
396682959bc7 unit test
pygame
parents:
diff changeset
245 expected_topleft = (r.left+20,r.top+30)
396682959bc7 unit test
pygame
parents:
diff changeset
246 old_size = r.size
396682959bc7 unit test
pygame
parents:
diff changeset
247
396682959bc7 unit test
pygame
parents:
diff changeset
248 r.midtop = new_midtop
396682959bc7 unit test
pygame
parents:
diff changeset
249 self.assertEqual( new_midtop, r.midtop )
396682959bc7 unit test
pygame
parents:
diff changeset
250 self.assertEqual( expected_topleft, r.topleft )
396682959bc7 unit test
pygame
parents:
diff changeset
251 self.assertEqual( old_size, r.size )
396682959bc7 unit test
pygame
parents:
diff changeset
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
396682959bc7 unit test
pygame
parents:
diff changeset
254 """Changing the midbottom attribute moves the rect and does not change
396682959bc7 unit test
pygame
parents:
diff changeset
255 the rect's size
396682959bc7 unit test
pygame
parents:
diff changeset
256 """
396682959bc7 unit test
pygame
parents:
diff changeset
257 r = Rect( 1, 2, 3, 4 )
396682959bc7 unit test
pygame
parents:
diff changeset
258 new_midbottom = (r.centerx+20,r.bottom+30)
396682959bc7 unit test
pygame
parents:
diff changeset
259 expected_topleft = (r.left+20,r.top+30)
396682959bc7 unit test
pygame
parents:
diff changeset
260 old_size = r.size
396682959bc7 unit test
pygame
parents:
diff changeset
261
396682959bc7 unit test
pygame
parents:
diff changeset
262 r.midbottom = new_midbottom
396682959bc7 unit test
pygame
parents:
diff changeset
263 self.assertEqual( new_midbottom, r.midbottom )
396682959bc7 unit test
pygame
parents:
diff changeset
264 self.assertEqual( expected_topleft, r.topleft )
396682959bc7 unit test
pygame
parents:
diff changeset
265 self.assertEqual( old_size, r.size )
396682959bc7 unit test
pygame
parents:
diff changeset
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
396682959bc7 unit test
pygame
parents:
diff changeset
268 "Changing the width resizes the rect from the top-left corner"
396682959bc7 unit test
pygame
parents:
diff changeset
269 r = Rect( 1, 2, 3, 4 )
396682959bc7 unit test
pygame
parents:
diff changeset
270 new_width = 10
396682959bc7 unit test
pygame
parents:
diff changeset
271 old_topleft = r.topleft
396682959bc7 unit test
pygame
parents:
diff changeset
272 old_height = r.height
396682959bc7 unit test
pygame
parents:
diff changeset
273
396682959bc7 unit test
pygame
parents:
diff changeset
274 r.width = new_width
396682959bc7 unit test
pygame
parents:
diff changeset
275 self.assertEqual( new_width, r.width )
396682959bc7 unit test
pygame
parents:
diff changeset
276 self.assertEqual( old_height, r.height )
396682959bc7 unit test
pygame
parents:
diff changeset
277 self.assertEqual( old_topleft, r.topleft )
396682959bc7 unit test
pygame
parents:
diff changeset
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
396682959bc7 unit test
pygame
parents:
diff changeset
280 "Changing the height resizes the rect from the top-left corner"
396682959bc7 unit test
pygame
parents:
diff changeset
281 r = Rect( 1, 2, 3, 4 )
396682959bc7 unit test
pygame
parents:
diff changeset
282 new_height = 10
396682959bc7 unit test
pygame
parents:
diff changeset
283 old_topleft = r.topleft
396682959bc7 unit test
pygame
parents:
diff changeset
284 old_width = r.width
396682959bc7 unit test
pygame
parents:
diff changeset
285
396682959bc7 unit test
pygame
parents:
diff changeset
286 r.height = new_height
396682959bc7 unit test
pygame
parents:
diff changeset
287 self.assertEqual( new_height, r.height )
396682959bc7 unit test
pygame
parents:
diff changeset
288 self.assertEqual( old_width, r.width )
396682959bc7 unit test
pygame
parents:
diff changeset
289 self.assertEqual( old_topleft, r.topleft )
396682959bc7 unit test
pygame
parents:
diff changeset
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
396682959bc7 unit test
pygame
parents:
diff changeset
292 "Changing the size resizes the rect from the top-left corner"
396682959bc7 unit test
pygame
parents:
diff changeset
293 r = Rect( 1, 2, 3, 4 )
396682959bc7 unit test
pygame
parents:
diff changeset
294 new_size = (10,20)
396682959bc7 unit test
pygame
parents:
diff changeset
295 old_topleft = r.topleft
396682959bc7 unit test
pygame
parents:
diff changeset
296
396682959bc7 unit test
pygame
parents:
diff changeset
297 r.size = new_size
396682959bc7 unit test
pygame
parents:
diff changeset
298 self.assertEqual( new_size, r.size )
396682959bc7 unit test
pygame
parents:
diff changeset
299 self.assertEqual( old_topleft, r.topleft )
396682959bc7 unit test
pygame
parents:
diff changeset
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
396682959bc7 unit test
pygame
parents:
diff changeset
302 r = Rect( 1, 2, 3, 4 )
396682959bc7 unit test
pygame
parents:
diff changeset
303
396682959bc7 unit test
pygame
parents:
diff changeset
304 self.failUnless( r.contains( Rect( 2, 3, 1, 1 ) ),
396682959bc7 unit test
pygame
parents:
diff changeset
305 "r does not contain Rect(2,3,1,1)" )
396682959bc7 unit test
pygame
parents:
diff changeset
306 self.failUnless( r.contains( Rect(r) ),
396682959bc7 unit test
pygame
parents:
diff changeset
307 "r does not contain the same rect as itself" )
396682959bc7 unit test
pygame
parents:
diff changeset
308 self.failUnless( r.contains( Rect(2,3,0,0) ),
396682959bc7 unit test
pygame
parents:
diff changeset
309 "r does not contain an empty rect within its bounds" )
396682959bc7 unit test
pygame
parents:
diff changeset
310 self.failIf( r.contains( Rect(0,0,1,2) ),
396682959bc7 unit test
pygame
parents:
diff changeset
311 "r contains Rect(0,0,1,2)" )
396682959bc7 unit test
pygame
parents:
diff changeset
312 self.failIf( r.contains( Rect(4,6,1,1) ),
396682959bc7 unit test
pygame
parents:
diff changeset
313 "r contains Rect(4,6,1,1)" )
396682959bc7 unit test
pygame
parents:
diff changeset
314 self.failIf( r.contains( Rect(4,6,0,0) ),
396682959bc7 unit test
pygame
parents:
diff changeset
315 "r contains Rect(4,6,0,0)" )
396682959bc7 unit test
pygame
parents:
diff changeset
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
396682959bc7 unit test
pygame
parents:
diff changeset
318 r = Rect( 1, 2, 3, 4 )
396682959bc7 unit test
pygame
parents:
diff changeset
319
396682959bc7 unit test
pygame
parents:
diff changeset
320 self.failUnless( r.collidepoint( r.left, r.top ),
396682959bc7 unit test
pygame
parents:
diff changeset
321 "r does not collide with point (left,top)" )
396682959bc7 unit test
pygame
parents:
diff changeset
322 self.failIf( r.collidepoint( r.left-1, r.top ),
396682959bc7 unit test
pygame
parents:
diff changeset
323 "r collides with point (left-1,top)" )
396682959bc7 unit test
pygame
parents:
diff changeset
324 self.failIf( r.collidepoint( r.left, r.top-1 ),
396682959bc7 unit test
pygame
parents:
diff changeset
325 "r collides with point (left,top-1)" )
396682959bc7 unit test
pygame
parents:
diff changeset
326 self.failIf( r.collidepoint( r.left-1,r.top-1 ),
396682959bc7 unit test
pygame
parents:
diff changeset
327 "r collides with point (left-1,top-1)" )
396682959bc7 unit test
pygame
parents:
diff changeset
328
396682959bc7 unit test
pygame
parents:
diff changeset
329 self.failUnless( r.collidepoint( r.right-1, r.bottom-1 ),
396682959bc7 unit test
pygame
parents:
diff changeset
330 "r does not collide with point (right-1,bottom-1)")
396682959bc7 unit test
pygame
parents:
diff changeset
331 self.failIf( r.collidepoint( r.right, r.bottom ),
396682959bc7 unit test
pygame
parents:
diff changeset
332 "r collides with point (right,bottom)" )
396682959bc7 unit test
pygame
parents:
diff changeset
333 self.failIf( r.collidepoint( r.right-1, r.bottom ),
396682959bc7 unit test
pygame
parents:
diff changeset
334 "r collides with point (right-1,bottom)" )
396682959bc7 unit test
pygame
parents:
diff changeset
335 self.failIf( r.collidepoint( r.right, r.bottom-1 ),
396682959bc7 unit test
pygame
parents:
diff changeset
336 "r collides with point (right,bottom-1)" )
396682959bc7 unit test
pygame
parents:
diff changeset
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
396682959bc7 unit test
pygame
parents:
diff changeset
339 "The inflate method inflates around the center of the rectangle"
396682959bc7 unit test
pygame
parents:
diff changeset
340 r = Rect( 2, 4, 6, 8 )
396682959bc7 unit test
pygame
parents:
diff changeset
341 r2 = r.inflate( 4, 6 )
396682959bc7 unit test
pygame
parents:
diff changeset
342
396682959bc7 unit test
pygame
parents:
diff changeset
343 self.assertEqual( r.center, r2.center )
396682959bc7 unit test
pygame
parents:
diff changeset
344 self.assertEqual( r.left-2, r2.left )
396682959bc7 unit test
pygame
parents:
diff changeset
345 self.assertEqual( r.top-3, r2.top )
396682959bc7 unit test
pygame
parents:
diff changeset
346 self.assertEqual( r.right+2, r2.right )
396682959bc7 unit test
pygame
parents:
diff changeset
347 self.assertEqual( r.bottom+3, r2.bottom )
396682959bc7 unit test
pygame
parents:
diff changeset
348 self.assertEqual( r.width+4, r2.width )
396682959bc7 unit test
pygame
parents:
diff changeset
349 self.assertEqual( r.height+6, r2.height )
396682959bc7 unit test
pygame
parents:
diff changeset
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
396682959bc7 unit test
pygame
parents:
diff changeset
352 "The inflate method inflates around the center of the rectangle"
396682959bc7 unit test
pygame
parents:
diff changeset
353 r = Rect( 2, 4, 6, 8 )
396682959bc7 unit test
pygame
parents:
diff changeset
354 r2 = r.inflate( -4, -6 )
396682959bc7 unit test
pygame
parents:
diff changeset
355
396682959bc7 unit test
pygame
parents:
diff changeset
356 self.assertEqual( r.center, r2.center )
396682959bc7 unit test
pygame
parents:
diff changeset
357 self.assertEqual( r.left+2, r2.left )
396682959bc7 unit test
pygame
parents:
diff changeset
358 self.assertEqual( r.top+3, r2.top )
396682959bc7 unit test
pygame
parents:
diff changeset
359 self.assertEqual( r.right-2, r2.right )
396682959bc7 unit test
pygame
parents:
diff changeset
360 self.assertEqual( r.bottom-3, r2.bottom )
396682959bc7 unit test
pygame
parents:
diff changeset
361 self.assertEqual( r.width-4, r2.width )
396682959bc7 unit test
pygame
parents:
diff changeset
362 self.assertEqual( r.height-6, r2.height )
396682959bc7 unit test
pygame
parents:
diff changeset
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
396682959bc7 unit test
pygame
parents:
diff changeset
365 "The inflate_ip method inflates around the center of the rectangle"
396682959bc7 unit test
pygame
parents:
diff changeset
366 r = Rect( 2, 4, 6, 8 )
396682959bc7 unit test
pygame
parents:
diff changeset
367 r2 = Rect( r )
396682959bc7 unit test
pygame
parents:
diff changeset
368 r2.inflate_ip( -4, -6 )
396682959bc7 unit test
pygame
parents:
diff changeset
369
396682959bc7 unit test
pygame
parents:
diff changeset
370 self.assertEqual( r.center, r2.center )
396682959bc7 unit test
pygame
parents:
diff changeset
371 self.assertEqual( r.left+2, r2.left )
396682959bc7 unit test
pygame
parents:
diff changeset
372 self.assertEqual( r.top+3, r2.top )
396682959bc7 unit test
pygame
parents:
diff changeset
373 self.assertEqual( r.right-2, r2.right )
396682959bc7 unit test
pygame
parents:
diff changeset
374 self.assertEqual( r.bottom-3, r2.bottom )
396682959bc7 unit test
pygame
parents:
diff changeset
375 self.assertEqual( r.width-4, r2.width )
396682959bc7 unit test
pygame
parents:
diff changeset
376 self.assertEqual( r.height-6, r2.height )
396682959bc7 unit test
pygame
parents:
diff changeset
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
396682959bc7 unit test
pygame
parents:
diff changeset
379 "The inflate method inflates around the center of the rectangle"
396682959bc7 unit test
pygame
parents:
diff changeset
380 r = Rect( 2, 4, 6, 8 )
396682959bc7 unit test
pygame
parents:
diff changeset
381 r2 = Rect( r )
396682959bc7 unit test
pygame
parents:
diff changeset
382 r2.inflate_ip( -4, -6 )
396682959bc7 unit test
pygame
parents:
diff changeset
383
396682959bc7 unit test
pygame
parents:
diff changeset
384 self.assertEqual( r.center, r2.center )
396682959bc7 unit test
pygame
parents:
diff changeset
385 self.assertEqual( r.left+2, r2.left )
396682959bc7 unit test
pygame
parents:
diff changeset
386 self.assertEqual( r.top+3, r2.top )
396682959bc7 unit test
pygame
parents:
diff changeset
387 self.assertEqual( r.right-2, r2.right )
396682959bc7 unit test
pygame
parents:
diff changeset
388 self.assertEqual( r.bottom-3, r2.bottom )
396682959bc7 unit test
pygame
parents:
diff changeset
389 self.assertEqual( r.width-4, r2.width )
396682959bc7 unit test
pygame
parents:
diff changeset
390 self.assertEqual( r.height-6, r2.height )
396682959bc7 unit test
pygame
parents:
diff changeset
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
396682959bc7 unit test
pygame
parents:
diff changeset
393 r = Rect(10, 10, 10, 10)
396682959bc7 unit test
pygame
parents:
diff changeset
394 c = Rect(19, 12, 5, 5).clamp(r)
396682959bc7 unit test
pygame
parents:
diff changeset
395 self.assertEqual(c.right, r.right)
396682959bc7 unit test
pygame
parents:
diff changeset
396 self.assertEqual(c.top, 12)
396682959bc7 unit test
pygame
parents:
diff changeset
397 c = Rect(1, 2, 3, 4).clamp(r)
396682959bc7 unit test
pygame
parents:
diff changeset
398 self.assertEqual(c.topleft, r.topleft)
396682959bc7 unit test
pygame
parents:
diff changeset
399 c = Rect(5, 500, 22, 33).clamp(r)
396682959bc7 unit test
pygame
parents:
diff changeset
400 self.assertEqual(c.center, r.center)
396682959bc7 unit test
pygame
parents:
diff changeset
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
396682959bc7 unit test
pygame
parents:
diff changeset
403 r = Rect(10, 10, 10, 10)
396682959bc7 unit test
pygame
parents:
diff changeset
404 c = Rect(19, 12, 5, 5)
396682959bc7 unit test
pygame
parents:
diff changeset
405 c.clamp_ip(r)
396682959bc7 unit test
pygame
parents:
diff changeset
406 self.assertEqual(c.right, r.right)
396682959bc7 unit test
pygame
parents:
diff changeset
407 self.assertEqual(c.top, 12)
396682959bc7 unit test
pygame
parents:
diff changeset
408 c = Rect(1, 2, 3, 4)
396682959bc7 unit test
pygame
parents:
diff changeset
409 c.clamp_ip(r)
396682959bc7 unit test
pygame
parents:
diff changeset
410 self.assertEqual(c.topleft, r.topleft)
396682959bc7 unit test
pygame
parents:
diff changeset
411 c = Rect(5, 500, 22, 33)
396682959bc7 unit test
pygame
parents:
diff changeset
412 c.clamp_ip(r)
396682959bc7 unit test
pygame
parents:
diff changeset
413 self.assertEqual(c.center, r.center)
396682959bc7 unit test
pygame
parents:
diff changeset
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
396682959bc7 unit test
pygame
parents:
diff changeset
416 r1 = Rect( 1, 2, 3, 4 )
396682959bc7 unit test
pygame
parents:
diff changeset
417 self.assertEqual( Rect( 1, 2, 2, 2 ), r1.clip( Rect(0,0,3,4) ) )
396682959bc7 unit test
pygame
parents:
diff changeset
418 self.assertEqual( Rect( 2, 2, 2, 4 ), r1.clip( Rect(2,2,10,20) ) )
396682959bc7 unit test
pygame
parents:
diff changeset
419 self.assertEqual( Rect(2,3,1,2), r1.clip( Rect(2,3,1,2) ) )
396682959bc7 unit test
pygame
parents:
diff changeset
420 self.assertEqual( (0,0), r1.clip(20,30,5,6).size )
396682959bc7 unit test
pygame
parents:
diff changeset
421 self.assertEqual( r1, r1.clip( Rect(r1) ),
396682959bc7 unit test
pygame
parents:
diff changeset
422 "r1 does not clip an identical rect to itself" )
396682959bc7 unit test
pygame
parents:
diff changeset
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
396682959bc7 unit test
pygame
parents:
diff changeset
425 r = Rect( 1, 2, 3, 4 )
396682959bc7 unit test
pygame
parents:
diff changeset
426 move_x = 10
396682959bc7 unit test
pygame
parents:
diff changeset
427 move_y = 20
396682959bc7 unit test
pygame
parents:
diff changeset
428 r2 = r.move( move_x, move_y )
396682959bc7 unit test
pygame
parents:
diff changeset
429 expected_r2 = Rect(r.left+move_x,r.top+move_y,r.width,r.height)
396682959bc7 unit test
pygame
parents:
diff changeset
430 self.assertEqual( expected_r2, r2 )
396682959bc7 unit test
pygame
parents:
diff changeset
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
396682959bc7 unit test
pygame
parents:
diff changeset
433 r = Rect( 1, 2, 3, 4 )
396682959bc7 unit test
pygame
parents:
diff changeset
434 r2 = Rect( r )
396682959bc7 unit test
pygame
parents:
diff changeset
435 move_x = 10
396682959bc7 unit test
pygame
parents:
diff changeset
436 move_y = 20
396682959bc7 unit test
pygame
parents:
diff changeset
437 r2.move_ip( move_x, move_y )
396682959bc7 unit test
pygame
parents:
diff changeset
438 expected_r2 = Rect(r.left+move_x,r.top+move_y,r.width,r.height)
396682959bc7 unit test
pygame
parents:
diff changeset
439 self.assertEqual( expected_r2, r2 )
396682959bc7 unit test
pygame
parents:
diff changeset
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
396682959bc7 unit test
pygame
parents:
diff changeset
442 r1 = Rect( 1, 1, 1, 2 )
396682959bc7 unit test
pygame
parents:
diff changeset
443 r2 = Rect( -2, -2, 1, 2 )
396682959bc7 unit test
pygame
parents:
diff changeset
444 self.assertEqual( Rect( -2, -2, 4, 5 ), r1.union(r2) )
396682959bc7 unit test
pygame
parents:
diff changeset
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
396682959bc7 unit test
pygame
parents:
diff changeset
447 r1 = Rect( 1, 2, 3, 4 )
396682959bc7 unit test
pygame
parents:
diff changeset
448 self.assertEqual( r1, r1.union( Rect(r1) ) )
396682959bc7 unit test
pygame
parents:
diff changeset
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
396682959bc7 unit test
pygame
parents:
diff changeset
451 r1 = Rect( 1, 1, 1, 2 )
396682959bc7 unit test
pygame
parents:
diff changeset
452 r2 = Rect( -2, -2, 1, 2 )
396682959bc7 unit test
pygame
parents:
diff changeset
453 r1.union_ip(r2)
396682959bc7 unit test
pygame
parents:
diff changeset
454 self.assertEqual( Rect( -2, -2, 4, 5 ), r1 )
396682959bc7 unit test
pygame
parents:
diff changeset
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
396682959bc7 unit test
pygame
parents:
diff changeset
457 r1 = Rect( 0, 0, 1, 1 )
396682959bc7 unit test
pygame
parents:
diff changeset
458 r2 = Rect( -2, -2, 1, 1 )
396682959bc7 unit test
pygame
parents:
diff changeset
459 r3 = Rect( 2, 2, 1, 1 )
396682959bc7 unit test
pygame
parents:
diff changeset
460
396682959bc7 unit test
pygame
parents:
diff changeset
461 r4 = r1.unionall( [r2,r3] )
396682959bc7 unit test
pygame
parents:
diff changeset
462 self.assertEqual( Rect(-2, -2, 5, 5), r4 )
396682959bc7 unit test
pygame
parents:
diff changeset
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
396682959bc7 unit test
pygame
parents:
diff changeset
465 r1 = Rect( 0, 0, 1, 1 )
396682959bc7 unit test
pygame
parents:
diff changeset
466 r2 = Rect( -2, -2, 1, 1 )
396682959bc7 unit test
pygame
parents:
diff changeset
467 r3 = Rect( 2, 2, 1, 1 )
396682959bc7 unit test
pygame
parents:
diff changeset
468
396682959bc7 unit test
pygame
parents:
diff changeset
469 r1.unionall_ip( [r2,r3] )
396682959bc7 unit test
pygame
parents:
diff changeset
470 self.assertEqual( Rect(-2, -2, 5, 5), r1 )
396682959bc7 unit test
pygame
parents:
diff changeset
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
396682959bc7 unit test
pygame
parents:
diff changeset
475 r1 = Rect(1,2,3,4)
396682959bc7 unit test
pygame
parents:
diff changeset
476 self.failUnless( r1.colliderect( Rect(0,0,2,3) ),
396682959bc7 unit test
pygame
parents:
diff changeset
477 "r1 does not collide with Rect(0,0,2,3)" )
396682959bc7 unit test
pygame
parents:
diff changeset
478 self.failIf( r1.colliderect( Rect(0,0,1,2) ),
396682959bc7 unit test
pygame
parents:
diff changeset
479 "r1 collides with Rect(0,0,1,2)" )
396682959bc7 unit test
pygame
parents:
diff changeset
480 self.failIf( r1.colliderect( Rect(r1.right,r1.bottom,2,2) ),
396682959bc7 unit test
pygame
parents:
diff changeset
481 "r1 collides with Rect(r1.right,r1.bottom,2,2)" )
396682959bc7 unit test
pygame
parents:
diff changeset
482 self.failUnless( r1.colliderect( Rect(r1.left+1,r1.top+1,
396682959bc7 unit test
pygame
parents:
diff changeset
483 r1.width-2,r1.height-2) ),
396682959bc7 unit test
pygame
parents:
diff changeset
484 "r1 does not collide with Rect(r1.left+1,r1.top+1,"+
396682959bc7 unit test
pygame
parents:
diff changeset
485 "r1.width-2,r1.height-2)" )
396682959bc7 unit test
pygame
parents:
diff changeset
486 self.failUnless( r1.colliderect( Rect(r1.left-1,r1.top-1,
396682959bc7 unit test
pygame
parents:
diff changeset
487 r1.width+2,r1.height+2) ),
396682959bc7 unit test
pygame
parents:
diff changeset
488 "r1 does not collide with Rect(r1.left-1,r1.top-1,"+
396682959bc7 unit test
pygame
parents:
diff changeset
489 "r1.width+2,r1.height+2)" )
396682959bc7 unit test
pygame
parents:
diff changeset
490 self.failUnless( r1.colliderect( Rect(r1) ),
396682959bc7 unit test
pygame
parents:
diff changeset
491 "r1 does not collide with an identical rect" )
396682959bc7 unit test
pygame
parents:
diff changeset
492 self.failIf( r1.colliderect( Rect(r1.right,r1.bottom,0,0) ),
396682959bc7 unit test
pygame
parents:
diff changeset
493 "r1 collides with Rect(r1.right,r1.bottom,0,0)" )
396682959bc7 unit test
pygame
parents:
diff changeset
494 self.failIf( r1.colliderect( Rect(r1.right,r1.bottom,1,1) ),
396682959bc7 unit test
pygame
parents:
diff changeset
495 "r1 collides with Rect(r1.right,r1.bottom,1,1)" )
396682959bc7 unit test
pygame
parents:
diff changeset
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
396682959bc7 unit test
pygame
parents:
diff changeset
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()