5 Unit tests for the rotmat library 8 from __future__
import absolute_import, division, print_function
9 from math
import radians, degrees
23 """Constructor, set up some data that is reused in many tests""" 24 super(VectorTest, self).
__init__(*args, **kwargs)
28 """Test the constructor functionality""" 35 assert str(v1) ==
"Vector3(1.00, 0.20, -3.00)" 39 """Test simple maths""" 43 assert v1 + v2 ==
Vector3(2, 5, 0)
44 assert v1 - v2 ==
Vector3(0, -1, -6)
45 assert (v1 * 3) ==
Vector3(3, 6, -9)
48 assert v1 % v2 ==
Vector3(15.00, -6.00, 1.00)
49 np.testing.assert_almost_equal(v2.length(), 4.358898943540674)
50 assert v2.normalized().close(
Vector3(0.23, 0.69, 0.69), tol=1e-2)
51 np.testing.assert_almost_equal(v1.angle(v2), 1.693733631245806)
61 """Constructor, set up some data that is reused in many tests""" 62 super(MatrixTest, self).
__init__(*args, **kwargs)
65 """Test the constructor functionality""" 69 assert str(m1) ==
'Matrix3((1.00, 0.00, 0.00), (1.00, 5.00, 0.00), (1.00, 0.00, -7.00))' 70 assert str(m2) ==
'Matrix3((1.00, 0.00, 0.00), (0.00, 1.00, 0.00), (0.00, 0.00, 1.00))' 83 '''check that from_euler() and to_euler() are consistent''' 85 for r
in range(-179, 179, 10):
86 for p
in range(-89, 89, 10):
87 for y
in range(-179, 179, 10):
88 m.from_euler(radians(r), radians(p), radians(y))
89 (r2, p2, y2) = m.to_euler()
91 v2 =
Vector3(degrees(r2), degrees(p2), degrees(y2))
93 assert diff.length() < 1.0e-12
96 '''check that from_euler312() and to_euler312() are consistent''' 98 for r
in range(-89, 89, 10):
99 for p
in range(-179, 179, 10):
100 for y
in range(-179, 179, 10):
101 m.from_euler312(radians(r), radians(p), radians(y))
102 (r2, p2, y2) = m.to_euler312()
104 v2 =
Vector3(degrees(r2), degrees(p2), degrees(y2))
106 assert diff.length() < 1.0e-12
114 np.testing.assert_almost_equal(m1.trace(), 2.19115332535)
116 m1.rotate(
Vector3(0.2,-0.98,0))
124 m1.from_axis_angle(axis, angle)
128 Vector3(-0.71, 0.00, 0.71)), tol=1e-2)
131 '''test the from_two_vectors() method''' 134 v2 =
Vector3(random.uniform(-5, 5), random.uniform(-5, 5), random.uniform(-5, 5))
136 m.from_two_vectors(v1, v2)
138 diff = v3.normalized() - v2.normalized()
139 (r, p, y) = m.to_euler()
140 assert diff.length() < 0.001
146 Class to test Line and Plane classes 150 """Constructor, set up some data that is reused in many tests""" 151 super(LinePlaneTest, self).
__init__(*args, **kwargs)
154 '''testing line/plane intersection''' 157 p = line.plane_intersection(plane)
158 assert p.close(
Vector3(11.11, 11.11, 0.00), tol=1e-2)
160 if __name__ ==
'__main__':
def test_constructor(self)
def __init__(self, args, kwargs)
def test_two_vectors(self)
def test_constructor(self)
def __init__(self, args, kwargs)
def __init__(self, args, kwargs)