Add docstrings.
[python-bulletml.git] / tests / test_collision.py
1 import collections
2
3 from tests import TestCase, add
4
5 from bulletml import collision
6
7 Dummy = collections.namedtuple("Dummy", "x y px py radius")
8
9 class Toverlaps(TestCase):
10 def test_inside(self):
11 self.failUnless(collision.overlaps(
12 Dummy(0, 0, 0, 0, 10),
13 Dummy(0, 0, 0, 0, 1)))
14
15 def test_near(self):
16 self.failUnless(collision.overlaps(
17 Dummy(0, 0, 0, 0, 1),
18 Dummy(0.5, 0.5, 0, 0, 1)))
19
20 def test_far(self):
21 self.failIf(collision.overlaps(
22 Dummy(0, 0, 0, 0, 1),
23 Dummy(20, 20, 0, 0, 1)))
24 add(Toverlaps)
25
26 class Tcollides(TestCase):
27 def test_cross(self):
28 a = Dummy(0, 0, 100, 100, 1)
29 b = Dummy(0, 100, 100, 0, 1)
30 self.failUnless(collision.collides(a, b))
31
32 def test_miss(self):
33 a = Dummy(0, 0, 100, 75, 1)
34 b = Dummy(0, 100, 75, 0, 1)
35 self.failIf(collision.collides(a, b))
36
37 def test_stationary(self):
38 a = Dummy(100, 0, 100, 0, 1)
39 b = Dummy(0, 100, 100, 0, 1)
40 self.failUnless(collision.collides(a, b))
41 add(Tcollides)
42
43 class Tcollides_all(TestCase):
44 def test_cross(self):
45 a = Dummy(0, 0, 100, 100, 1)
46 b = Dummy(100, 100, 0, 100, 1)
47 c = Dummy(0, 100, 100, 0, 1)
48 collides = collision.collides_all(a, [a, b, c])
49 self.failUnlessEqual(collides, [a, c])
50 add(Tcollides_all)