Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply to vector unit tests #112

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions tests/objects/test_matrix33.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,18 @@ def test_operators_number(self):
self.assertTrue(np.array_equal(m / 2., matrix33.create_identity()[:] / 2.0))
self.assertTrue(np.array_equal(m / fv[0]['f'], matrix33.create_identity()[:] / 2.0))
self.assertTrue(np.array_equal(m / fv[0]['i'], matrix33.create_identity()[:] / 2.0))

def test_apply_to_vector_list(self):

# transform 5 3D vectors by a matrix33
list_of_vectors = np.array([np.array([np.cos(i), np.sin(i), 0]) for i in range(5)])
theoretical_result = np.array([np.array([2 * np.cos(i), 3 * np.sin(i), 0]) for i in range(5)])
matrix3 = np.array([[2, 0, 0, 0], [0, 3, 0, 0], [0, 0, 4, 0]])
self.assertTrue(np.array_equal(theoretical_result, matrix33.apply_to_vector(matrix3, list_of_vectors)))

# transforming 4D vectors by a matrix33 should throw a value error
list_of_vectors = np.array([np.array([np.cos(i), np.sin(i), 0, 1]) for i in range(5)])
self.assertRaises(ValueError, lambda: matrix33.apply_to_vector(matrix3, list_of_vectors))

def test_accessors(self):
m = Matrix33(np.arange(self._size))
Expand Down
14 changes: 14 additions & 0 deletions tests/objects/test_matrix44.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,20 @@ def test_operators_vector4(self):
# divide
self.assertRaises(ValueError, lambda: m / v)

def test_apply_to_vector_list(self):

# transform 5 3D vectors by a matrix44
list_of_vectors = np.array([np.array([np.cos(i), np.sin(i), 0]) for i in range(5)])
theoretical_result = np.array([np.array([2 * np.cos(i), 3 * np.sin(i), 0]) for i in range(5)])
matrix4 = np.array([[2, 0, 0, 0], [0, 3, 0, 0], [0, 0, 4, 0], [0, 0, 0, 1]])
self.assertTrue(np.array_equal(theoretical_result, matrix44.apply_to_vector(matrix4, list_of_vectors)))

# transform 5 4D vectors by a matrix44
list_of_vectors = np.array([np.array([np.cos(i), np.sin(i), 0, 1]) for i in range(5)])
theoretical_result = np.array([np.array([2 * np.cos(i), 3 * np.sin(i), 0, 1]) for i in range(5)])
matrix4 = np.array([[2, 0, 0, 0], [0, 3, 0, 0], [0, 0, 4, 0], [0, 0, 0, 1]])
self.assertTrue(np.array_equal(theoretical_result, matrix44.apply_to_vector(matrix4, list_of_vectors)))

def test_operators_number(self):
m = Matrix44.identity()
fv = np.empty((1,), dtype=[('i', np.int16, 1),('f', np.float32, 1)])
Expand Down