93891b917b
- added __neg__ - added cross for Vertex * Vertex - added tests for these - moved the cube docstring up into the cube generating function
66 lines
1.9 KiB
Python
66 lines
1.9 KiB
Python
import unittest
|
|
|
|
from surf.geometry import Vertex, cross
|
|
|
|
|
|
class TestVertexOperations(unittest.TestCase):
|
|
|
|
def setUp(self):
|
|
self.origin = Vertex(0, 0, 0)
|
|
self.v1 = Vertex(-1, -1, -1)
|
|
self.v2 = Vertex(1, 1, 1)
|
|
|
|
self.v3 = Vertex(5, 4, 3)
|
|
self.v4 = Vertex(10, -2, 13)
|
|
self.v5 = Vertex(-4, 15.3, 100)
|
|
|
|
def test_addition(self):
|
|
added_v = self.v1 + self.v2
|
|
self.assertEqual(added_v, self.origin)
|
|
self.assertEqual(self.v3 + self.v4, Vertex(15, 2, 16))
|
|
|
|
def test_summation(self):
|
|
v = sum((self.v1, self.v2, self.v3, self.v4), Vertex())
|
|
self.assertEqual(v, Vertex(15, 2, 16))
|
|
v = sum((self.v1, self.v2, self.v3, self.v4, self.v5), Vertex())
|
|
self.assertEqual(v, Vertex(11, 17.3, 116))
|
|
|
|
def test_division(self):
|
|
v1 = self.v1 / 2
|
|
v2 = self.v1 / 2.0
|
|
self.assertEqual(v1, v2)
|
|
|
|
def test_multiply(self):
|
|
self.assertEqual(type(self.v1 * 2), Vertex)
|
|
self.assertEqual(type(self.v1 * self.v1), Vertex)
|
|
self.assertEqual(self.v1 * 2, Vertex(-2, -2, -2))
|
|
self.assertEqual(self.v1 * self.v1, Vertex(0, 0, 0))
|
|
self.assertEqual(self.v1 * self.v2, Vertex(0, 0, 0))
|
|
self.assertEqual(self.v3 * self.v4, Vertex(58, -35, -50))
|
|
|
|
|
|
def test_cross(self):
|
|
i = Vertex(1, 0, 0)
|
|
j = Vertex(0, 1, 0)
|
|
k = Vertex(0, 0, 1)
|
|
|
|
self.assertEqual(i * j, k)
|
|
self.assertEqual(j * k, i)
|
|
self.assertEqual(k * i, j)
|
|
|
|
self.assertEqual(j * i, -k)
|
|
self.assertEqual(k * j, -i)
|
|
self.assertEqual(i * k, -j)
|
|
|
|
self.assertEqual(i * i, self.origin)
|
|
self.assertEqual(j * j, self.origin)
|
|
self.assertEqual(k * k, self.origin)
|
|
|
|
def test_negative(self):
|
|
self.assertEqual(-self.v1, self.v2)
|
|
self.assertEqual(-self.v2, self.v1)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main(verbosity=3)
|