4 from ..geometry
import *
5 from ..linexprs
import Symbol
6 from ..polyhedra
import Eq
9 class TestPoint(unittest
.TestCase
):
15 self
.pt1
= Point({self
.x
: 10, self
.y
: 5, self
.z
: 1})
16 self
.pt2
= Point({self
.x
: 15, self
.y
: 40, self
.z
: 60})
17 self
.vec1
= Vector({self
.x
: 20, self
.y
: 30, self
.z
: 40})
20 self
.assertEqual(self
.pt1
+ self
.vec1
, Point({self
.x
: 30, self
.y
: 35, self
.z
: 41}))
21 with self
.assertRaises(TypeError):
25 self
.assertEqual(self
.pt1
, self
.pt1
)
26 self
.assertNotEqual(self
.pt1
, self
.pt2
)
27 self
.assertNotEqual(self
.pt1
, self
.vec1
)
30 self
.assertEqual(self
.pt1
- self
.pt2
, Vector({self
.x
: -5, self
.y
: -35, self
.z
: -59}))
31 self
.assertEqual(self
.pt1
- self
.vec1
, Point({self
.x
: -10, self
.y
: -25, self
.z
: -39}))
33 def test_aspolyhedron(self
):
34 self
.assertEqual(self
.pt1
.aspolyhedron(), Eq(self
.x
, 10) & Eq(self
.y
, 5) & Eq(self
.z
, 1))
37 class TestVector(unittest
.TestCase
):
43 self
.pt1
= Point({self
.x
: 10, self
.y
: 5, self
.z
: 1})
44 self
.pt2
= Point({self
.x
: 15, self
.y
: 40, self
.z
: 60})
45 self
.vec1
= Vector({self
.x
: 20, self
.y
: 30, self
.z
: 40})
46 self
.vec2
= Vector({self
.x
: 45, self
.y
: 70, self
.z
: 80})
49 self
.assertEqual(self
.vec1
+ self
.pt1
, Point({self
.x
: 30, self
.y
: 35, self
.z
: 41}))
50 self
.assertEqual(self
.vec1
+ self
.vec2
, Vector({self
.x
: 65, self
.y
: 100, self
.z
: 120}))
53 self
.assertEqual(math
.degrees(self
.vec1
.angle(self
.vec1
)), 0)
54 self
.assertAlmostEqual(math
.degrees(self
.vec1
.angle(self
.vec2
)), 4.15129, places
=5)
55 self
.assertAlmostEqual(math
.degrees(self
.vec2
.angle(self
.vec1
)), 4.15129, places
=5)
58 self
.assertEqual(self
.vec1
.cross(self
.vec2
), Vector({self
.x
: -400, self
.y
: 200, self
.z
: 50}))
61 self
.assertEqual(self
.vec1
/ 10, Vector({self
.x
: 2, self
.y
: 3, self
.z
: 4}))
64 self
.assertEqual(self
.vec1
.dot(self
.vec2
), 6200)
67 self
.assertEqual(self
.vec1
, self
.vec1
)
68 self
.assertNotEqual(self
.vec1
, self
.vec2
)
71 self
.assertEqual(75 * self
.vec1
, Vector({self
.x
: 1500, self
.y
: 2250, self
.z
: 3000}))
72 self
.assertEqual(self
.vec1
* 75, Vector({self
.x
: 1500, self
.y
: 2250, self
.z
: 3000}))
75 self
.assertEqual(-self
.vec1
, Vector({self
.x
: -20, self
.y
: -30, self
.z
: -40}))
78 self
.assertAlmostEqual(self
.vec1
.norm(), 53.85165, places
=5)
81 self
.assertEqual(self
.vec1
.norm2(), 2900)
83 def test_asunit(self
):
84 unit
= self
.vec1
.asunit()
85 self
.assertAlmostEqual(unit
[self
.x
], 0.37139, 5)
86 self
.assertAlmostEqual(unit
[self
.y
], 0.55709, 5)
87 self
.assertAlmostEqual(unit
[self
.z
], 0.74278, 5)
90 self
.assertEqual(self
.vec1
- self
.pt1
, Point({self
.x
: 10, self
.y
: 25, self
.z
: 39}))
91 self
.assertEqual(self
.vec1
- self
.vec2
, Vector({self
.x
: -25, self
.y
: -40, self
.z
: -40}))