Пример #1
0
 def test_crossprod(self):
     a = VMD(1.0,0.0,0.0)
     b = VMD(0.0,1.0,0.0)
     c = a.cross_prod(b)
     self.assertAlmostEquals(c[0],0.0)
     self.assertAlmostEquals(c[1],0.0)
     self.assertAlmostEquals(c[2],1.0)
Пример #2
0
 def test_equality_operators(self):
     v1 = VMD(1.0, 2.0)
     self.assertEqual(v1, v1)
     v2 = VMD(1.0, 2.0)  # different object, same value
     self.assertEqual(v1, v2)
     self.assertFalse(v1 != v2)
     v3 = VMD(1.0, -5.0)
     self.assertNotEqual(v1, v3)
Пример #3
0
    def test_normalize(self):
        a = VMD(3,4, math.sqrt(39.0))
        pre_norm = a.norm()
        self.assertEquals(pre_norm, a.normalize())

        b = VMD(3./8,4./8, math.sqrt(39.0)/8.) # normalized version
        self.assertAlmostEquals(b[0], a[0], places=6)
        self.assertAlmostEquals(b[1], a[1], places=6)
        self.assertAlmostEquals(b[2], a[2], places=6)
Пример #4
0
 def test_default_construction_gives_object_with_single_dimension(self):
     one = VMD()
     self.assertEquals(1, one.getNumDims())
Пример #5
0
 def test_angle(self):
     a = VMD(1,0,0);
     b = VMD(0,1,0);
     self.assertAlmostEqual(a.angle(b), math.pi/2, places=4);
Пример #6
0
 def test_norm2(self):
     p = VMD(1.0,-5.0,8.0);
     self.assertAlmostEquals(p.norm2(), 90.0, places=6)
Пример #7
0
 def test_scalar_prod_returns_expected_value(self):
     a = VMD(1.0,2.0,1.0)
     b = VMD(1.0,-2.0,-1.0)
     sp = a.scalar_prod(b)
     self.assertAlmostEquals(sp,-4.0)
Пример #8
0
 def test_constructors_with_dimension_pts(self):
     pts = [1]
     for i in range(2,7):
         pts.append(i)
         vector = VMD(*pts) #unpack list
         self.assertEquals(i, vector.getNumDims())
Пример #9
0
 def test_value_write_access_raises_error_for_invalid_indices(self):
     vector = VMD(1.0, 2.0)
     self.assertRaises(IndexError, vector.__setitem__, 2, 5.0)
Пример #10
-1
 def test_norm(self):
     p = VMD(1.0,-5.0,8.0);
     self.assertAlmostEquals(p.norm(), math.sqrt(90.0),places=6)