Exemple #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.))
     np.testing.assert_allclose((d * c).cart, b.cart)
     np.testing.assert_allclose((d * (0, 1, 0)).cart, b.cart)
     np.testing.assert_allclose(((0, 1, 0) * d).cart, b.cart)
Exemple #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.))
     np.testing.assert_allclose((d + c).cart, b.cart)
     np.testing.assert_allclose((d + (0, 1, 0)).cart, b.cart)
     np.testing.assert_allclose(((0, 1, 0) + d).cart, b.cart)
Exemple #3
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)
Exemple #4
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)
Exemple #5
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)
Exemple #6
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.]))
Exemple #7
0
 def test_normalize(self):
     """Normalize a cartesian vector."""
     d = CCoordinate((2., 0., 0.))
     self.assertTrue(np.allclose(d.normalize().cart, [1, 0, 0]))
Exemple #8
0
 def test_norm(self):
     """Euclidean norm of a cartesian vector."""
     d = CCoordinate((1, 0, 0))
     self.assertEqual(d.norm(), 1.0)
Exemple #9
0
 def test_repr(self):
     """Check the representation."""
     d = CCoordinate((0, 0, 0))
     self.assertEqual(repr(d), "[0 0 0]")
Exemple #10
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)
Exemple #11
0
 def test_eq(self):
     """Test equality of two cartesian vectors."""
     d = CCoordinate((1., 0., 0.))
     c = CCoordinate((0., 1., 0.))
     assert not c.__eq__(d)
Exemple #12
0
 def test_normalize(self):
     """Normalize a cartesian vector."""
     d = CCoordinate((2., 0., 0.))
     np.testing.assert_allclose(d.normalize().cart, [1, 0, 0])
 def test_str(self):
     """Check the string representation
     """
     d = CCoordinate((0, 0, 0))
     self.assertEqual(str(d), "[0 0 0]")