|
1 | 1 | import unittest
|
2 | 2 |
|
3 |
| -from pygame import Vector2 |
| 3 | +from pygame import Vector2, Vector3 |
4 | 4 |
|
5 | 5 | from pygame.geometry import Circle
|
6 | 6 |
|
@@ -206,6 +206,59 @@ def test_copy(self):
|
206 | 206 | # check c2 is not c
|
207 | 207 | self.assertIsNot(c_2, c)
|
208 | 208 |
|
| 209 | + def test_collidepoint_argtype(self): |
| 210 | + """tests if the function correctly handles incorrect types as parameters""" |
| 211 | + invalid_types = (None, [], "1", (1,), Vector3(1, 1, 1), 1) |
| 212 | + |
| 213 | + c = Circle(10, 10, 4) |
| 214 | + |
| 215 | + for value in invalid_types: |
| 216 | + with self.assertRaises(TypeError): |
| 217 | + c.collidepoint(value) |
| 218 | + |
| 219 | + def test_collidepoint_argnum(self): |
| 220 | + c = Circle(10, 10, 4) |
| 221 | + args = [tuple(range(x)) for x in range(3, 13)] |
| 222 | + |
| 223 | + # no params |
| 224 | + with self.assertRaises(TypeError): |
| 225 | + c.collidepoint() |
| 226 | + |
| 227 | + # too many params |
| 228 | + for arg in args: |
| 229 | + with self.assertRaises(TypeError): |
| 230 | + c.collidepoint(*arg) |
| 231 | + |
| 232 | + def test_collidepoint(self): |
| 233 | + c = Circle(0, 0, 5) |
| 234 | + |
| 235 | + p1 = (3, 3) |
| 236 | + p2 = (10, 10) |
| 237 | + p3 = Vector2(3, 3) |
| 238 | + p4 = Vector2(10, 10) |
| 239 | + |
| 240 | + # colliding single |
| 241 | + self.assertTrue(c.collidepoint(p1), "Expected True, point should collide here") |
| 242 | + self.assertTrue(c.collidepoint(p3), "Expected True, point should collide here") |
| 243 | + |
| 244 | + # not colliding single |
| 245 | + self.assertFalse( |
| 246 | + c.collidepoint(p2), "Expected False, point should not collide here" |
| 247 | + ) |
| 248 | + self.assertFalse( |
| 249 | + c.collidepoint(p4), "Expected False, point should not collide here" |
| 250 | + ) |
| 251 | + |
| 252 | + # colliding 2 args |
| 253 | + self.assertTrue( |
| 254 | + c.collidepoint(3, 3), "Expected True, point should collide here" |
| 255 | + ) |
| 256 | + |
| 257 | + # not colliding 2 args |
| 258 | + self.assertFalse( |
| 259 | + c.collidepoint(10, 10), "Expected False, point should not collide here" |
| 260 | + ) |
| 261 | + |
209 | 262 |
|
210 | 263 | if __name__ == "__main__":
|
211 | 264 | unittest.main()
|
0 commit comments