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