2f4db2b6b71dbf500b0dee1cef172cdf163840d6
1 # Copyright 2014 MINES ParisTech
3 # This file is part of LinPy.
5 # LinPy is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # LinPy is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with LinPy. If not, see <http://www.gnu.org/licenses/>.
21 from ..geometry
import *
22 from ..linexprs
import Symbol
23 from ..polyhedra
import Eq
26 class TestPoint(unittest
.TestCase
):
32 self
.pt1
= Point({self
.x
: 10, self
.y
: 5, self
.z
: 1})
33 self
.pt2
= Point({self
.x
: 15, self
.y
: 40, self
.z
: 60})
34 self
.vec1
= Vector({self
.x
: 20, self
.y
: 30, self
.z
: 40})
37 self
.assertEqual(self
.pt1
+ self
.vec1
, Point({self
.x
: 30, self
.y
: 35, self
.z
: 41}))
38 with self
.assertRaises(TypeError):
42 self
.assertEqual(self
.pt1
, self
.pt1
)
43 self
.assertNotEqual(self
.pt1
, self
.pt2
)
44 self
.assertNotEqual(self
.pt1
, self
.vec1
)
47 self
.assertEqual(self
.pt1
- self
.pt2
, Vector({self
.x
: -5, self
.y
: -35, self
.z
: -59}))
48 self
.assertEqual(self
.pt1
- self
.vec1
, Point({self
.x
: -10, self
.y
: -25, self
.z
: -39}))
50 def test_aspolyhedron(self
):
51 self
.assertEqual(self
.pt1
.aspolyhedron(), Eq(self
.x
, 10) & Eq(self
.y
, 5) & Eq(self
.z
, 1))
54 class TestVector(unittest
.TestCase
):
60 self
.pt1
= Point({self
.x
: 10, self
.y
: 5, self
.z
: 1})
61 self
.pt2
= Point({self
.x
: 15, self
.y
: 40, self
.z
: 60})
62 self
.vec1
= Vector({self
.x
: 20, self
.y
: 30, self
.z
: 40})
63 self
.vec2
= Vector({self
.x
: 45, self
.y
: 70, self
.z
: 80})
66 self
.assertEqual(self
.vec1
+ self
.pt1
, Point({self
.x
: 30, self
.y
: 35, self
.z
: 41}))
67 self
.assertEqual(self
.vec1
+ self
.vec2
, Vector({self
.x
: 65, self
.y
: 100, self
.z
: 120}))
70 self
.assertEqual(math
.degrees(self
.vec1
.angle(self
.vec1
)), 0)
71 self
.assertAlmostEqual(math
.degrees(self
.vec1
.angle(self
.vec2
)), 4.15129, places
=5)
72 self
.assertAlmostEqual(math
.degrees(self
.vec2
.angle(self
.vec1
)), 4.15129, places
=5)
75 self
.assertEqual(self
.vec1
.cross(self
.vec2
), Vector({self
.x
: -400, self
.y
: 200, self
.z
: 50}))
78 self
.assertEqual(self
.vec1
/ 10, Vector({self
.x
: 2, self
.y
: 3, self
.z
: 4}))
81 self
.assertEqual(self
.vec1
.dot(self
.vec2
), 6200)
84 self
.assertEqual(self
.vec1
, self
.vec1
)
85 self
.assertNotEqual(self
.vec1
, self
.vec2
)
88 self
.assertEqual(75 * self
.vec1
, Vector({self
.x
: 1500, self
.y
: 2250, self
.z
: 3000}))
89 self
.assertEqual(self
.vec1
* 75, Vector({self
.x
: 1500, self
.y
: 2250, self
.z
: 3000}))
92 self
.assertEqual(-self
.vec1
, Vector({self
.x
: -20, self
.y
: -30, self
.z
: -40}))
95 self
.assertAlmostEqual(self
.vec1
.norm(), 53.85165, places
=5)
98 self
.assertEqual(self
.vec1
.norm2(), 2900)
100 def test_asunit(self
):
101 unit
= self
.vec1
.asunit()
102 self
.assertAlmostEqual(unit
[self
.x
], 0.37139, 5)
103 self
.assertAlmostEqual(unit
[self
.y
], 0.55709, 5)
104 self
.assertAlmostEqual(unit
[self
.z
], 0.74278, 5)
107 self
.assertEqual(self
.vec1
- self
.pt1
, Point({self
.x
: 10, self
.y
: 25, self
.z
: 39}))
108 self
.assertEqual(self
.vec1
- self
.vec2
, Vector({self
.x
: -25, self
.y
: -40, self
.z
: -40}))