Пример #1
0
def vector_example():
    v1 = Vector(1, 3, 4)
    v2 = Vector(2, 5, 6)
    print("Vector representation: ", v1)
    print("Multiplication with constant number 3: ", v1 * 3)
    print("Multiplication of 2 vectors: ")
    print("First vector: ", v1)
    print("Second vector: ", v2)
    print("Multiplication result: ", v1 * v2)
    print("Sum result(same vectors): ", v1 + v2)
    print("Length of first vector: ", len(v1))
    print("Checking for equality: ", v1 == v2)
    print("Subtraction of two vectors: ", v1 - v2)
    print("Result of taking value by index from first vector: \nv1[2] = ",
          v1[2])
Пример #2
0
 def test_add(self):
     first = Vector(3, 2, 1)
     second = Vector(3, 6, 2)
     self.assertEqual(first + second, Vector(6, 8, 3))
Пример #3
0
 def test_index(self):
     vector = Vector(2, 5, -10, 5)
     self.assertEqual(vector[2], -10)
Пример #4
0
 def test_equal(self):
     self.assertEqual(Vector(-1, 5, 2, 10), Vector(-1, 5, 2, 10))
Пример #5
0
 def test_len(self):
     vector = Vector(-4, -1, 0)
     self.assertEqual(len(vector), 3)
Пример #6
0
 def test_mul_vect(self):
     first = Vector(7, 5, 9, 6)
     second = Vector(3, -5, 1, 5)
     self.assertEqual(first * second, Vector(21, -25, 9, 30))
Пример #7
0
 def test_mul_const(self):
     vector = Vector(4, 3, 1)
     self.assertEqual(vector * 10, Vector(40, 30, 10))
Пример #8
0
 def test_sub(self):
     first = Vector(3, 2)
     second = Vector(5, 2)
     self.assertEqual(first - second, Vector(-2, 0))
Пример #9
0
 def setUp(self):
     self.first_vector = Vector(1, 3, 5, 6)
     self.second_vector = Vector(2, 5, 8, 1)