Esempio n. 1
0
def test_a_matrix_multiplied_by_a_tuple():
    # Given
    A = Matrix(1, 2, 3, 4,
               2, 4, 4, 2,
               8, 6, 4, 1,
               0, 0, 0, 1)
    b = Tuple(1, 2, 3, 1)

    # Then
    assert A * b == Tuple(18, 24, 33, 1)
def test_a_tuple_with_w_equal_1_is_a_point():
    # Given
    a = Tuple(4.3, -4.2, 3.1, 1.0)
    # Then
    assert a.x == 4.3
    assert a.y == -4.2
    assert a.z == 3.1
    assert a.w == 1.0
    assert a.is_point()
    assert not a.is_vector()
Esempio n. 3
0
 def _multiply_by_tuple(self, other):
     other_list = other.to_list()
     elements = []
     for row in range(4):
         element = sum([
             self.at(row, 0) * other_list[0],
             self.at(row, 1) * other_list[1],
             self.at(row, 2) * other_list[2],
             self.at(row, 3) * other_list[3]
         ])
         elements.append(element)
     return Tuple(*elements)
def test_equivalence_tuple_objects():
    a = Tuple(4.3, -4.2, 3.1, 1.0)
    assert a == Tuple(4.3, -4.2, 3.1, 1.0)
    assert a != Tuple(9.9, -4.2, 3.1, 1.0)
    assert a != Tuple(4.3, 9.9, 3.1, 1.0)
    assert a != Tuple(4.3, -4.2, 9.9, 1.0)
    assert a != Tuple(4.3, -4.2, 3.1, 0.0)
    assert a != (4.3, -4.2, 3.1, 1.0)
def test_multiplying_a_tuple_by_a_scalar():
    # Given
    a = Tuple(1, -2, 3, -4)
    # Then
    assert a * 3.5 == Tuple(3.5, -7.0, 10.5, -14)
def test_negating_a_tuple():
    # Given
    a = Tuple(1, -2, 3, -4)
    # Then
    assert -a == Tuple(-1, 2, -3, 4)
def test_adding_two_tuples():
    # Given
    a1 = Tuple(3, -2, 5, 1)
    a2 = Tuple(-2, 3, 1, 0)
    # Then
    assert a1 + a2 == Tuple(1, 1, 6, 1)
def test_func_vector_creates_tuples_with_w_equal_0():
    # Given
    p = Vector(4, -4, 3)
    # Then
    assert p == Tuple(4, -4, 3, 0)
def test_func_point_creates_tuples_with_w_equal_1():
    # Given
    p = Point(4, -4, 3)
    # Then
    assert p == Tuple(4, -4, 3, 1)
def test___repr__():
    t = Tuple(1, 2, 3, 4)
    assert t.__repr__() == "1 | 2 | 3 | 4"
def test_dividing_a_tuple_by_a_scalar():
    # Given
    a = Tuple(1, -2, 3, -4)
    # Then
    assert a / 2 == Tuple(0.5, -1, 1.5, -2)
def test_multiplying_a_tuple_by_a_fraction():
    # Given
    a = Tuple(1, -2, 3, -4)
    # Then
    assert a * 0.5 == Tuple(0.5, -1, 1.5, -2)
Esempio n. 13
0
def test_multiplying_the_identity_matrix_by_a_tuple():
    # Given
    a = Tuple(1, 2, 3, 4)
    # Then
    assert identity_matrix() * a == a