Exemple #1
0
 def test_magnitude(self):
     self.assertEqual(_Vector(2, 3).magnitude, sqrt(13))
     self.assertEqual(_Vector(2, 1, 7).magnitude, sqrt(54))
Exemple #2
0
 def test_dot_multiplication(self):
     u = _Vector(2, 7, 4)
     v = _Vector(5, 8, 2)
     self.assertEqual(u * v, 74)
     self.assertEqual(v * u, 74)
Exemple #3
0
 def test_equality(self):
     self.assertEqual(_Vector(2, 7, 4), _Vector(2, 7, 4))
     self.assertEqual(_Vector(2, 7, 4) * 2, _Vector(4, 14, 8))
Exemple #4
0
 def test_scalar_multiplication(self):
     u = _Vector(2, 7, 4)
     self.assertEqual(u * 3, _Vector(6, 21, 12))
     self.assertEqual(3 * u, _Vector(6, 21, 12))
Exemple #5
0
 def test_scalar_division(self):
     u = _Vector(2, 8, 4)
     self.assertEqual(u / 2, _Vector(1, 4, 2))
Exemple #6
0
 def test_subtract_scalar(self):
     u = _Vector(2, 7, 4)
     self.assertIs(u.__sub__(3), NotImplemented)
Exemple #7
0
 def test_subtract_vectors(self):
     u = _Vector(2, 7, 4)
     v = _Vector(5, 8, 2)
     self.assertEqual(u - v, _Vector(-3, -1, 2))
Exemple #8
0
 def test_add_scalar(self):
     u = _Vector(2, 7, 4)
     self.assertIs(u.__add__(3), NotImplemented)
Exemple #9
0
 def test_add_vectors(self):
     u = _Vector(2, 7, 4)
     v = _Vector(5, 8, 2)
     self.assertEqual(u + v, _Vector(7, 15, 6))
Exemple #10
0
 def test_len(self):
     u = _Vector(1, 2, 3)
     self.assertEqual(len(u), 3)