Refactor all and add some tests for the calculations
This commit is contained in:
1
tests/__init__.py
Normal file
1
tests/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
|
||||
37
tests/test_calculator.py
Normal file
37
tests/test_calculator.py
Normal file
@@ -0,0 +1,37 @@
|
||||
import unittest
|
||||
import numpy as np
|
||||
import calculator
|
||||
|
||||
|
||||
class TestCalculator(unittest.TestCase):
|
||||
def test_proj(self):
|
||||
vec = np.array([123, 325, 1])
|
||||
self.assertEqual(np.array([123, 0, 0]).all(), calculator.proj(vec, 1).all())
|
||||
|
||||
vec = np.array([234, -2134, 12])
|
||||
self.assertEqual(np.array([-2134, 0, 0]).all(), calculator.proj(vec, 2).all())
|
||||
|
||||
vec = np.array([-21, 34, 82])
|
||||
self.assertEqual(np.array([0, 0, 82]).all(), calculator.proj(vec, 3).all())
|
||||
|
||||
def test_rotate(self):
|
||||
vec = np.array([1, 0, 0])
|
||||
self.assertEqual(np.array([0, 1, 0]).all(), calculator.rotate(vec).all())
|
||||
|
||||
def test_agl(self):
|
||||
vec1 = np.array([1, 0, 0])
|
||||
vec2 = np.array([1, 0, 0])
|
||||
self.assertEqual(0, calculator.agl(vec1, vec2))
|
||||
|
||||
vec1 = np.array([1, 0, 0])
|
||||
vec2 = np.array([0, 1, 0])
|
||||
self.assertEqual(90, calculator.agl(vec1, vec2))
|
||||
|
||||
def test_get_angles(self):
|
||||
source = np.array([0, 50, 0])
|
||||
target = np.array([0, 50, 0])
|
||||
self.assertEqual((90, 90), calculator.get_angles(source, target))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user