1"""This will test our functions on the n-sphere 2 3""" 4from __future__ import absolute_import, division, print_function, unicode_literals 5 6import numpy as np 7 8from kinematics import sphere 9 10def test_two_sphere_random_vector_norm(): 11 vec = sphere.rand(2) 12 np.testing.assert_almost_equal(np.linalg.norm(vec), 1) 13 14def test_two_sphere_tangent_vector(): 15 vec = sphere.rand(2) 16 vecd = sphere.tan_rand(vec, 9) 17 18 np.testing.assert_almost_equal(np.dot(vec, vecd), 0) 19 20class TestPerturbedVector(): 21 22 q = sphere.rand(2) 23 half_angle = 5 24 qp = sphere.perturb_vec(q, half_angle) 25 26 def test_angle(self): 27 """Ensure the angle is always less than half_angle 28 """ 29 angle = np.arccos(np.dot(self.q, self.qp)) * 180 / np.pi 30 np.testing.assert_array_less(angle, self.half_angle) 31 32 def test_norm(self): 33 np.testing.assert_allclose(np.linalg.norm(self.qp), 1) 34 35