]>
gitweb.michael.orlitzky.com - dead/census-tools.git/blob - src/Tests/Unit/GeometryTest.py
7 class TwoVectorTest(unittest
.TestCase
):
11 Add a couple of test vectors and check that they sum
15 v2
= TwoVector(100, -19)
16 self
.assertTrue(v2
== (v1
+v2
))
18 v1
= TwoVector(23, -10)
19 v2
= TwoVector(-23, 10)
20 zero
= TwoVector(0, 0)
21 self
.assertTrue((v1
+v2
) == zero
)
24 def testDotProduct(self
):
26 The dot product of a vector v with a vector to which it's
27 perpendicular, v_perp, should always be zero.
29 The dot product of any vector with the zero vector should be
32 v1
= TwoVector(235, -2352)
33 v2
= TwoVector(9382335.024, -235235.1242)
34 self
.assertEqual(0, v1
.dot_product(v1
.perpendicular()))
35 self
.assertEqual(0, v2
.dot_product(v2
.perpendicular()))
37 zero
= TwoVector(0, 0)
38 self
.assertEqual(0, v1
.dot_product(zero
))
42 class PolygonTest(unittest
.TestCase
):
46 We defined our own __eq__ method; make sure it works.
48 unit_square1
= Polygon([ (0,0), (1,0), (1,1), (0,1) ])
49 unit_square2
= Polygon([ (0,0), (1,0), (1,1), (0,1) ])
50 self
.assertTrue(unit_square1
== unit_square2
)
52 hexagon
= Polygon([ (1,0),
57 (0.5, -sqrt(3)/2.0) ])
59 self
.assertFalse(unit_square1
== hexagon
)
64 Drag the unit square 5 units to the right.
66 unit_square
= Polygon([ (0,0), (1,0), (1,1), (0,1) ])
68 result
= unit_square
.drag(v
)
69 expected_result
= Polygon([ (0,0), (6,0), (6,1), (0,1) ])
70 self
.assertTrue(result
== expected_result
)
74 def testDragVertices(self
):
76 A diamond shape has nice drag vertices which we can calculate
79 diamond
= Polygon([ (0,1), (-1,0), (0,-1), (1,0) ])
81 # First, we drag it to the right along the x-axis.
82 drag_vector
= TwoVector(5,0)
83 dvs
= set(diamond
.drag_vertices(drag_vector
))
84 expected_dvs
= set([(0,1), (0,-1)])
85 self
.assertTrue(dvs
== expected_dvs
)
88 drag_vector
= TwoVector(0,5)
89 dvs
= set(diamond
.drag_vertices(drag_vector
))
90 expected_dvs
= set([(1,0), (-1,0)])
91 self
.assertTrue(dvs
== expected_dvs
)
95 suite
= unittest
.TestSuite()
96 suite
.addTest(unittest
.makeSuite(TwoVectorTest
))
97 suite
.addTest(unittest
.makeSuite(PolygonTest
))