Ejemplo n.º 1
0
    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))
Ejemplo n.º 2
0
    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))
Ejemplo n.º 3
0
 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)
Ejemplo n.º 4
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.]))
Ejemplo n.º 5
0
 def test_normalize(self):
     """Normalize a cartesian vector
     """
     d = CCoordinate((2, 0, 0))
     self.assertTrue(np.allclose(d.normalize().cart, [1, 0, 0]))
Ejemplo n.º 6
0
 def test_norm(self):
     """Euclidean norm of a cartesian vector
     """
     d = CCoordinate((1, 0, 0))
     self.assertEqual(d.norm(), 1.0)
Ejemplo n.º 7
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)
Ejemplo n.º 8
0
 def test_ne(self):
     """Test inequality of two cartesian vectors.
     """
     d = CCoordinate((1., 0., 0.))
     c = CCoordinate((0., 1., 0.))
     self.assertTrue(c != d)
Ejemplo n.º 9
0
 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)
Ejemplo n.º 10
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.]))
Ejemplo n.º 11
0
 def test_normalize(self):
     """Normalize a cartesian vector
     """
     d = CCoordinate((2., 0., 0.))
     self.assertTrue(np.allclose(d.normalize().cart, [1, 0, 0]))
Ejemplo n.º 12
0
 def test_norm(self):
     """Euclidean norm of a cartesian vector
     """
     d = CCoordinate((1, 0, 0))
     self.assertEqual(d.norm(), 1.0)
Ejemplo n.º 13
0
 def test_repr(self):
     """Check the representation
     """
     d = CCoordinate((0, 0, 0))
     self.assertEqual(repr(d), "[0 0 0]")
Ejemplo n.º 14
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)
Ejemplo n.º 15
0
 def test_eq(self):
     """Test equality of two cartesian vectors.
     """
     d = CCoordinate((1., 0., 0.))
     c = CCoordinate((0., 1., 0.))
     self.assertFalse(c == d)