Пример #1
0
 def test_invalid_tuple_addition_raises_value_error(self):
     vector = Vector(-2, 3, 1)
     with pytest.raises(ValueError):
         vector.add((1, 2, 3, 4))  # tuple that is not a Point or a Vector
Пример #2
0
 def test_addition_invalid_type_argument_raises_type_error(self):
     vector = Vector(-2, 3, 1)
     with pytest.raises(TypeError):
         # one can not add a scalar to a vector
         vector.add(1)
Пример #3
0
 def test_tuple_as_point_addition_results_in_new_tuple(self):
     start = (3, -2, 5, 1)  # emulates a Point
     vector = Vector(-2, 3, 1)
     dest = vector.add(start)
     assert isinstance(dest, tuple)
     assert dest is not start
Пример #4
0
 def test_tuple_as_vector_addition_results_in_new_tuple(self):
     v1 = (3, -2, 5, 0)  # emulates a Vector
     v2 = Vector(-2, 3, 1)
     vr = v2.add(v1)
     assert isinstance(vr, tuple)
     assert vr is not v1
Пример #5
0
 def test_point_addition_results_in_new_point_object(self):
     starting_point = Point(3, -2, 5)
     vector = Vector(-2, 3, 1)
     destination = vector.add(starting_point)
     assert isinstance(destination, Point)
     assert destination is not starting_point
Пример #6
0
 def test_vector_addition_results_in_new_vector_object(self):
     v1 = Vector(2, 3, 1)
     v2 = Vector(3, 2, 1)
     vr = v1.add(v2)
     assert isinstance(vr, Vector)
     assert vr is not v1
Пример #7
0
 def test_addition_to_tuple_as_vector(self):
     v1 = Vector(2, 3, 1)
     v2 = (3, 2, 1, 0)
     vr = v1.add(v2)
     # a vector added to a vector results in a resulting vector (w=0)
     assert vr == (5, 5, 2, 0)
Пример #8
0
 def test_addition_to_vector_object(self):
     v1 = Vector(2, 3, 1)
     v2 = Vector(3, 2, 1)
     vr = v1.add(v2)
     # a vector added to a vector results in a resulting vector (w=0)
     assert vr.to_tuple() == (5, 5, 2, 0)
Пример #9
0
 def test_addition_to_point_object(self):
     point = Point(3, -2, 5)
     vector = Vector(-2, 3, 1)
     destination = vector.add(point)
     # a point added to a vector results in a translated point (w=1)
     assert destination.to_tuple() == (1, 1, 6, 1)