Example #1
0
 def test_addition_to_tuple_assumes_adding_a_vector(self):
     # tuple argument assumes a Vector,
     # as point addition makes no sense
     vector = (-2, 3, 1)
     point = Point(3, -2, 5)
     dest = point.add(vector)
     # a point added to a vector results in a translated point
     assert isinstance(dest, Point)
     assert dest is not point
     assert dest.to_tuple() == (1, 1, 6, 1)
Example #2
0
 def test_subtraction_of_a_point_from_a_vector_raises_type_error(self):
     v1 = Vector(3, 2, 1)
     pt = Point(5, 6, 7)
     with pytest.raises(TypeError):
         # subtract a point from a vector makes no sense
         v1.sub(pt)
Example #3
0
 def test_subtraction_of_two_points_results_in_a_vector(self):
     p1 = Point(3, 2, 1)
     p2 = Point(5, 6, 7)
     rv = p1.sub(p2)
     assert rv.to_tuple() == (-2, -4, -6, 0)
Example #4
0
 def test_addition_invalid_type_argument_raises_type_error(self):
     point = Point(-2, 3, 1)
     with pytest.raises(TypeError):
         point.add(7)  # one can not add a scalar to a point
Example #5
0
 def test_invalid_tuple_addition_raises_value_error(self):
     point = Point(-2, 3, 1)
     with pytest.raises(ValueError):
         point.add((1, 2, 3, 4))  # tuple that is not a Point or a Vector
Example #6
0
 def test_tuple_as_vector_addition_raises_value_error(self):
     point = Point(-2, 3, 1)
     with pytest.raises(ValueError):
         dest = point.add((3, -2, 5, 0))  # tuple that emulates a Vector
Example #7
0
 def test_recognizes_a_point_in_a_point_object(self):
     point = Point(1.0, 1.0, 1.0)
     assert Point.object_is_point(point)
Example #8
0
 def test_recognizes_a_point_in_a_tuple(self):
     tup = (1.0, 1.0, 1.0, 1.0)
     assert Point.tuple_is_point(tup)
Example #9
0
 def test_point_as_tuple(self):
     point = Point(1, 1, 1)
     assert point.to_tuple() == (1.0, 1.0, 1.0, 1.0)
Example #10
0
 def test_builds_a_point_from_a_tuple(self):
     point = Point.from_tuple((1, 1, 1))
     assert Point.object_is_point(point)
Example #11
0
 def test_creates_a_point_from_coordinates(self):
     point = Point(1, 1, 1)
     assert point.w == 1.0
Example #12
0
 def test_incomplete_tuple_is_not_a_point(self):
     tup = (1, 1, 1)
     assert not Point.tuple_is_point(tup)
Example #13
0
 def test_vector_tuple_is_not_a_point(self):
     tup = (1, 1, 1, 0)
     assert not Point.tuple_is_point(tup)
Example #14
0
 def test_malformed_tuple_is_not_a_point(self):
     tup = (1, 1, 1, 2)
     assert not Point.tuple_is_point(tup)
Example #15
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)
Example #16
0
 def test_point_addition_raises_type_error(self):
     p1 = Point(-2, 3, 1)
     p2 = Point(3, -2, 5)
     with pytest.raises(TypeError):
         dest = p1.add(p2)  # Adding two Points does not make sense
Example #17
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
Example #18
0
 def test_subtraction_of_a_vector_from_a_point_results_in_a_point(self):
     p1 = Point(3, 2, 1)
     v1 = Vector(5, 6, 7)
     dp = p1.sub(v1)
     assert dp.to_tuple() == (-2, -4, -6, 1)