def testpositive(self): w = copy.deepcopy(self.w) w.positive() self.assertEqual(w, self.w) a = copy.deepcopy(self.a) a.positive() self.assertEqual(a, vectors.Vector(1, 2, -3)) self.assertEqual(self.a, vectors.Vector(-1, -2, 3))
def setUp(self): unittest.TestCase.setUp(self) self.u = vectors.Vector3D(1, 2, 3) self.v = vectors.Vector3D([4, 5, 6]) self.w = vectors.Vector(1, 0, 0) self.x = vectors.Vector(1, 0, 0, 0, -5, 6) self.a = vectors.Vector(-1, -2, 3) self.b = vectors.Vector(0, 0, -1, -2, 3)
def test__delitem__(self): del self.u[1] del self.x[1] del self.x[1] self.assertEqual(len(self.u), 2) self.assertEqual(self.u, vectors.Vector(1, 3)) self.assertEqual(len(self.x), 4) self.assertEqual(self.x, vectors.Vector(1, 0, -5, 6))
def test__sub__(self): self.assertEqual(self.v - self.u, vectors.Vector(3, 3, 3)) self.assertEqual(self.v - self.u, self.v + -self.u) self.assertNotEqual(self.v - self.u, self.u - self.v) func = lambda a, b: a - b self.assertRaises(vectors.VectorOperationError, func, self.x, self.u)
def setUp(self): unittest.TestCase.setUp(self) self.u = vectors.Vector(1, 2, 3) self.v = vectors.Vector([4, 5, 6]) self.w = vectors.Vector(1, 0, 0) self.x = vectors.Vector(1, 0, 0, 0, -5, 6) self.y = vectors.Vector([1, 2, 3, 4]) self.z = vectors.Vector(8, 9) self.a = vectors.Vector(-1, -2, 3)
def test__getslice__(self): self.assertEqual(self.u[1:], vectors.Vector(2, 3)) self.assertEqual(self.v[-2:], vectors.Vector(5, 6)) self.assertEqual(self.y[2:-1], vectors.Vector(3)) self.assertEqual(self.z[:], vectors.Vector(8, 9))
def testcross(self): self.assertEqual(vectors.cross(self.u, self.v), vectors.Vector(-3, 6, -3)) self.assertEqual(vectors.cross(self.u, self.u), vectors.Vector(0, 0, 0))
def testpositive(self): self.assertEqual(vectors.positive(self.a), vectors.Vector(1, 2, -3)) self.assertEqual(vectors.positive(self.b), vectors.Vector(0, 0, 1, 2, -3)) self.assertEqual(vectors.positive(self.u), self.u)
def test__mul__(self): self.assertEqual(2 * self.u, vectors.Vector(2, 4, 6)) self.assertEqual(2 * self.w, vectors.Vector(2, 0, 0)) self.assertEqual(2 * self.u, self.u * 2)
def test__neg__(self): self.assertEqual(-self.u, vectors.Vector(-1, -2, -3)) self.assertEqual(-self.x, vectors.Vector(-1, 0, 0, 0, 5, -6))
def test__add__(self): self.assertEqual(self.u + self.w, vectors.Vector(2, 2, 3)) self.assertEqual(self.u + self.v, self.v + self.u) func = lambda a, b: a + b self.assertRaises(vectors.VectorOperationError, func, self.x, self.u)