def test_mul(self):
        """Test multiplying (element-wise) cartesian vectors.
        """
        d = CCoordinate((1., 0., 0.))
        c = CCoordinate((0., 1., 0.))
        b = CCoordinate((0., 0., 0.))
        self.assertTrue(np.allclose((d * c).cart, b.cart))
        self.assertTrue(np.allclose((d * (0, 1, 0)).cart, b.cart))

        self.assertTrue(np.allclose(((0, 1, 0) * d).cart, b.cart))
    def test_add(self):
        """Test adding cartesian vectors.
        """
        d = CCoordinate((1., 0., 0.))
        c = CCoordinate((0., 1., 0.))
        b = CCoordinate((1., 1., 0.))
        self.assertTrue(np.allclose((d + c).cart, b.cart))

        self.assertTrue(np.allclose((d + (0, 1, 0)).cart, b.cart))

        self.assertTrue(np.allclose(((0, 1, 0) + d).cart, b.cart))
 def test_dot(self):
     """Test the dot product of two cartesian vectors.
     """
     d = CCoordinate((1., 0., 0.))
     c = CCoordinate((0., 1., 0.))
     self.assertEqual(d.dot(c), 0)
 def test_cross(self):
     """Test cross product in cartesian coordinates
     """
     d = CCoordinate((1., 0., 0.))
     c = CCoordinate((0., 1., 0.))
     self.assertTrue(np.allclose(d.cross(c).cart, [0., 0., 1.]))
 def test_normalize(self):
     """Normalize a cartesian vector
     """
     d = CCoordinate((2, 0, 0))
     self.assertTrue(np.allclose(d.normalize().cart, [1, 0, 0]))
 def test_norm(self):
     """Euclidean norm of a cartesian vector
     """
     d = CCoordinate((1, 0, 0))
     self.assertEqual(d.norm(), 1.0)
 def test_to_spherical(self):
     """Test converting to spherical coordinates.
     """
     d = CCoordinate((1., 0., 0.))
     c = SCoordinate(0, 0)
     self.assertEqual(d.to_spherical(), c)
 def test_ne(self):
     """Test inequality of two cartesian vectors.
     """
     d = CCoordinate((1., 0., 0.))
     c = CCoordinate((0., 1., 0.))
     self.assertTrue(c != d)
 def test_dot(self):
     """Test the dot product of two cartesian vectors.
     """
     d = CCoordinate((1., 0., 0.))
     c = CCoordinate((0., 1., 0.))
     self.assertEqual(d.dot(c), 0)
 def test_cross(self):
     """Test cross product in cartesian coordinates
     """
     d = CCoordinate((1., 0., 0.))
     c = CCoordinate((0., 1., 0.))
     self.assertTrue(np.allclose(d.cross(c).cart, [0., 0., 1.]))
 def test_normalize(self):
     """Normalize a cartesian vector
     """
     d = CCoordinate((2., 0., 0.))
     self.assertTrue(np.allclose(d.normalize().cart, [1, 0, 0]))
 def test_norm(self):
     """Euclidean norm of a cartesian vector
     """
     d = CCoordinate((1, 0, 0))
     self.assertEqual(d.norm(), 1.0)
 def test_repr(self):
     """Check the representation
     """
     d = CCoordinate((0, 0, 0))
     self.assertEqual(repr(d), "[0 0 0]")
 def test_to_spherical(self):
     """Test converting to spherical coordinates.
     """
     d = CCoordinate((1., 0., 0.))
     c = SCoordinate(0, 0)
     self.assertEqual(d.to_spherical(), c)
 def test_eq(self):
     """Test equality of two cartesian vectors.
     """
     d = CCoordinate((1., 0., 0.))
     c = CCoordinate((0., 1., 0.))
     self.assertFalse(c == d)