def test_normalize(self): q = Quaternion(w, x, y, z) q0 = Quaternion(0, 0, 0, 0) q1 = Quaternion(1, 2, 3, 4) self.assertEqual(q1.normalize(), Quaternion(1, 2, 3, 4) * (1 / q1.norm())) self.assertEqual( q.normalize(), Quaternion(w, x, y, z) / sqrt(w**2 + x**2 + y**2 + z**2)) self.assertNotEqual( q.normalize(), Quaternion(w, x, y, z) / sqrt(w**4 + x**4 + y**4 + z**4)) self.assertNotEqual( q0.normalize(), Quaternion(0, 0, 0, 0) / sqrt(0**2 + 0**2 + 0**2 + 0**2))
def test_norm(self): #By definition ||q|| = sqrt(w^2 + x^2 + y^2 + z^2). Tested from definition with both sqrt and raise to the power 0.5. q = Quaternion(w, x, y, z) self.assertEqual(q.norm(), sqrt(w**2 + x**2 + y**2 + z**2)) self.assertEqual(q.norm(), (w**2 + x**2 + y**2 + z**2)**0.5)