Beispiel #1
0
    def test_tuple_point(self):

        ap = rtTuple(4.3, -4.2, 3.1, 1)
        ap2 = rtTuple(4.3, -4.2, 3.1, -1)

        self.assertNotEqual(ap, ap2, 'These tuples should not be equal')
        self.assertEqual(ap.x, 4.3, 'x should be 4.3')
        self.assertEqual(ap.y, -4.2, 'y should be -4.2')
        self.assertEqual(ap.z, 3.1, 'z should be 3.1')
        self.assertEqual(ap.w, 1, 'w should be 1')

        self.assertTrue(ap.is_point(), 'This should be a point')
        self.assertFalse(ap.is_vector(), 'This should not be a vector')
    def test_matrix_multiplication(self):
        '''
        TODO: 
            - scalar multiplication
            - matrix multiplication
            - tuple multiplication
        '''
        matrix_list = [[1, 2, 3, 4], [5.5, 6.5, 7.5, 8.5], [9, 10, 11, 12],
                       [13.5, 14.5, 15.5, 16.5]]

        matrix_list2 = [[2, 4, 6, 8], [11, 13, 15, 17], [18, 20, 22, 24],
                        [27, 29, 31, 33]]

        M1 = matrix(matrix_list)
        M2 = matrix(matrix_list2)
        scalar1 = 2

        self.assertEqual(scalar1 * M1, M2, 'This multiplication should word')

        matrix_list_A = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 8, 7, 6],
                         [5, 4, 3, 2]]

        matrix_list_B = [[-2, 1, 2, 3], [3, 2, 1, -1], [4, 3, 6, 5],
                         [1, 2, 7, 8]]

        matrix_list_AB = [[20, 22, 50, 48], [44, 54, 114, 108],
                          [40, 58, 110, 102], [16, 26, 46, 42]]

        Ma = matrix(matrix_list_A)
        Mb = matrix(matrix_list_B)
        Mc = matrix(matrix_list_AB)

        self.assertEqual(Ma * Mb, Mc, 'This multiplication should be equal')

        matrix_list_t = [[1, 2, 3, 4], [2, 4, 4, 2], [8, 6, 4, 1],
                         [0, 0, 0, 1]]

        Mt = matrix(matrix_list_t)
        tuple_input = rtTuple(1, 2, 3, 1)
        tuple_output = rtTuple(18, 24, 33, 1)

        self.assertEqual(Mt * tuple_input, tuple_output,
                         'this should be a tuple')
Beispiel #3
0
    def test_tuple_vector(self):

        av = rtTuple(4.3, -4.2, 3.1, 0)

        self.assertEqual(av.x, 4.3, 'x should be 4.3')
        self.assertEqual(av.y, -4.2, 'y should be -4.2')
        self.assertEqual(av.z, 3.1, 'z should be 3.1')
        self.assertEqual(av.w, 0, 'w should be 0')

        self.assertFalse(av.is_point(), 'This should not be a point')
        self.assertTrue(av.is_vector(), 'This should be a vector')
    def test_identity_matrix(self):

        matrix_list = [[0, 1, 2, 4], [1, 2, 4, 8], [2, 4, 8, 16],
                       [4, 8, 16, 32]]

        Mt = matrix(matrix_list)

        self.assertEqual(identity_matrix * Mt, Mt,
                         'The identity should not alter the Matrix')

        tuple_list = [1, 2, 3, 4]

        Tt = rtTuple(*tuple_list)

        self.assertEqual(identity_matrix * Tt, Tt,
                         'The identity should not alter the tuple')
Beispiel #5
0
 def test_function_vector(self):
     av = vector(1, 1, 1)
     atuple = rtTuple(1, 1, 1, 0)
     scalar = math.sqrt(3)
     self.assertEqual(av, atuple, 'This should be a point')
     self.assertEqual(abs(av), scalar, 'The abs value should be {scalar}')
Beispiel #6
0
 def test_function_point(self):
     ap = point(1, 1, 1)
     atuple = rtTuple(1, 1, 1, 1)
     self.assertEqual(ap, atuple, 'This should be a point')