예제 #1
0
 def test_magnitude(self):
     self.assertEqual(_Vector(2, 3).magnitude, sqrt(13))
     self.assertEqual(_Vector(2, 1, 7).magnitude, sqrt(54))
예제 #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)
예제 #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))
예제 #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))
예제 #5
0
 def test_scalar_division(self):
     u = _Vector(2, 8, 4)
     self.assertEqual(u / 2, _Vector(1, 4, 2))
예제 #6
0
 def test_subtract_scalar(self):
     u = _Vector(2, 7, 4)
     self.assertIs(u.__sub__(3), NotImplemented)
예제 #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))
예제 #8
0
 def test_add_scalar(self):
     u = _Vector(2, 7, 4)
     self.assertIs(u.__add__(3), NotImplemented)
예제 #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))
예제 #10
0
 def test_len(self):
     u = _Vector(1, 2, 3)
     self.assertEqual(len(u), 3)