1- import unittest
21import math
3-
2+ import unittest
43from math import sqrt
5- from pygame import Vector2 , Vector3 , Rect , FRect
64
5+ from pygame import Vector2 , Vector3 , Rect , FRect
76from pygame .geometry import Circle
87
98
@@ -308,7 +307,7 @@ def test_area_update(self):
308307 self .assertEqual (c .area , math .pi * 4 )
309308
310309 c .r_sqr = 100
311- self .assertEqual (c .area , math .pi * (10 ** 2 ))
310+ self .assertEqual (c .area , math .pi * (10 ** 2 ))
312311
313312 def test_area_invalid_value (self ):
314313 """Ensures the area handles invalid values correctly."""
@@ -1176,8 +1175,11 @@ def test_contains_argnum(self):
11761175 def test_contains_return_type (self ):
11771176 """Tests if the function returns the correct type"""
11781177 c = Circle (10 , 10 , 4 )
1178+ items = [Circle (3 , 4 , 15 ), (0 , 0 ), Vector2 (0 , 0 ), Rect (0 , 0 , 10 , 10 ),
1179+ FRect (0 , 0 , 10 , 10 )]
11791180
1180- self .assertIsInstance (c .contains (Circle (10 , 10 , 4 )), bool )
1181+ for item in items :
1182+ self .assertIsInstance (c .contains (item ), bool )
11811183
11821184 def test_contains_circle (self ):
11831185 """Ensures that the contains method correctly determines if a circle is
@@ -1190,6 +1192,10 @@ def test_contains_circle(self):
11901192 # self
11911193 self .assertTrue (c .contains (c ))
11921194
1195+ # self-like
1196+ c_s = Circle (c )
1197+ self .assertTrue (c .contains (c_s ))
1198+
11931199 # contained circle
11941200 self .assertTrue (c .contains (c2 ))
11951201
@@ -1210,10 +1216,12 @@ def test_contains_point(self):
12101216 p1 = (10 , 10 )
12111217 p2 = (10 , 15 )
12121218 p3 = (100 , 100 )
1219+ p4 = (c .x + math .sin (math .pi / 4 ) * c .r , c .y + math .cos (math .pi / 4 ) * c .r )
12131220
1214- p1v = Vector2 (10 , 10 )
1215- p2v = Vector2 (10 , 15 )
1216- p3v = Vector2 (100 , 100 )
1221+ p1v = Vector2 (p1 )
1222+ p2v = Vector2 (p2 )
1223+ p3v = Vector2 (p3 )
1224+ p4v = Vector2 (p4 )
12171225
12181226 # contained point
12191227 self .assertTrue (c .contains (p1 ))
@@ -1222,13 +1230,19 @@ def test_contains_point(self):
12221230 self .assertFalse (c .contains (p2 ))
12231231 self .assertFalse (c .contains (p3 ))
12241232
1233+ # on the edge
1234+ self .assertTrue (c .contains (p4 ))
1235+
12251236 # contained point
12261237 self .assertTrue (c .contains (p1v ))
12271238
12281239 # not contained point
12291240 self .assertFalse (c .contains (p2v ))
12301241 self .assertFalse (c .contains (p3v ))
12311242
1243+ # on the edge
1244+ self .assertTrue (c .contains (p4v ))
1245+
12321246 def test_contains_rect_frect (self ):
12331247 """Ensures that the contains method correctly determines if a rect is
12341248 contained within the circle"""
@@ -1237,9 +1251,17 @@ def test_contains_rect_frect(self):
12371251 r2 = Rect (10 , 10 , 10 , 10 )
12381252 r3 = Rect (10 , 10 , 5 , 5 )
12391253
1254+ angle = math .pi / 4
1255+ x = c .x - math .sin (angle ) * c .r
1256+ y = c .y - math .cos (angle ) * c .r
1257+ rx = c .x + math .sin (angle ) * c .r
1258+ ry = c .y + math .cos (angle ) * c .r
1259+ r_edge = Rect (x , y , rx - x , ry - y )
1260+
12401261 fr1 = FRect (0 , 0 , 3 , 3 )
12411262 fr2 = FRect (10 , 10 , 10 , 10 )
12421263 fr3 = FRect (10 , 10 , 5 , 5 )
1264+ fr_edge = FRect (x , y , rx - x , ry - y )
12431265
12441266 # contained rect
12451267 self .assertTrue (c .contains (r1 ))
@@ -1248,13 +1270,19 @@ def test_contains_rect_frect(self):
12481270 self .assertFalse (c .contains (r2 ))
12491271 self .assertFalse (c .contains (r3 ))
12501272
1273+ # on the edge
1274+ self .assertTrue (c .contains (r_edge ))
1275+
12511276 # contained rect
12521277 self .assertTrue (c .contains (fr1 ))
12531278
12541279 # not contained rect
12551280 self .assertFalse (c .contains (fr2 ))
12561281 self .assertFalse (c .contains (fr3 ))
12571282
1283+ # on the edge
1284+ self .assertTrue (c .contains (fr_edge ))
1285+
12581286
12591287if __name__ == "__main__" :
12601288 unittest .main ()
0 commit comments