def main(): a = Vector([0, 1, 2, 3, 4]) b = Vector([4, 3, 2, 1, 0]) print('Vector a: %s' % a) print('Vector b: %s' % b) print('Vector a+2: %s' % (a + 2)) print('Vector a+b: %s' % (a + b))
def main(): a = Vector([0, 1, 2, 3, 4]) b = Vector([4, 3, 2, 1, 0]) print('Vector a: %s' % a) print('Vector b: %s' % b) print('Vector a+2: %s' % (a + 2)) print('Vector a+b: %s' % (a + b)) m = Matrix((3, 3)) print(m) m1 = Matrix.ident(4) print(m1) print(m1 + m1)
def test_setitem(self): vec1 = Vector([4, 2, 1, 5]) vec1[2] = 10 self.assertListEqual(vec1.get(), [4, 2, 10, 5]) vec2 = Vector([1, 2, 3]) vec2[5] = 7 self.assertListEqual(vec2.get(), [1, 2, 3, 0, 0, 7])
def test_hash(self): self.assertEqual(Vector([2, 6, 5]).__hash__(), 13)
def test_cmp(self): a = Vector([0, 1, 2, 3]) b = Vector([0, 1, 2, 3]) self.assertEqual(a.__cmp__(b), 0) a.__setitem__(1, 10) self.assertEqual(a.__cmp__(b), 1) b.__setitem__(1, 11) self.assertEqual(a.__cmp__(b), -1)
def test_xor(self): arr = [0, 1, 2, 3] vec = Vector(arr) self.assertListEqual((vec ^ 7).get(), [x ^ 7 for x in vec])
def test_sub(self): a = Vector([0, 1, 2, 3]) b = Vector([3, 2, 1, 0]) c = a - b self.assertListEqual(c.get(), [-3, -1, 1, 3])
def test_add(self): a = Vector([0, 1, 2, 3]) b = Vector([3, 2, 1, 0]) c = a + b self.assertEqual(c.get(), [3, 3, 3, 3])
def test_from_size(self): self.assertEqual(Vector.from_size(3).get(), [0, 0, 0])
def test_from_arr(self): self.assertEqual(Vector.from_arr([0, 1, 2]).get(), [0, 1, 2])
def test_xor(self): a = Vector([0, 1, 2, 3]) self.assertEqual(a.__xor__(2).get(), [2, 3, 0, 1])
def test_mul(self): a = Vector([0, 1, 2, 3]) self.assertEqual(a.__mul__(10).get(), [0, 10, 20, 30])
def test_sub(self): a = Vector([0, 1, 2, 3]) b = Vector([1, 2]) self.assertEqual(a.__sub__(b).get(), [0, 3])
def test_reversed(self): a = Vector([0, 1, 2, 3]) self.assertEqual(a.__reversed__().get(), [3, 2, 1, 0])
def test_neg(self): a = Vector([0, 1, 2, 3]) self.assertEqual(a.__neg__().get(), [0, -1, -2, -3])
def test_neg(self): self.assertEqual((-Vector([1, 1, 1])).get(), [-1, -1, -1])
def test_reversed(self): vec = Vector([1, 5, 6]) self.assertEqual(list(reversed(vec)), [6, 5, 1])
def test_set(self): arr = [1, 2, 3] vec = Vector() self.assertListEqual(vec.set(arr).get(), arr)
def test_dot(self): a = Vector([1, 2]) b = Vector([2, -1]) self.assertEqual(a.dot(b), 0)
def test_get(self): arr = [3, 4, 5] vec = Vector(arr) self.assertEqual(vec.get(), arr)
def test_mul(self): vec = Vector([0, 1, 2, 3]) self.assertListEqual((vec * 2).get(), [0, 2, 4, 6])
def test_len(self): self.assertEqual(len(Vector([1, 2, 3])), 3)
def test_length(self): vec1 = Vector([0, 3, 4]) vec2 = Vector([10, 0, 0]) self.assertEqual(vec1.length(), 5) self.assertEqual(vec2.length(), 10)
def test_repr(self): self.assertEqual(Vector([0, 1, 2]).__repr__(), "[0, 1, 2]")
def test_getitem(self): self.assertEqual(Vector([0, 2, 1, 3])[2], 1)
def test_setitem(self): a = Vector([0, 1, 2, 3]) a.__setitem__(1, 10) self.assertEqual(a.__getitem__(1), 10)