예제 #1
0
    def test_matrix_rotate(self):
        X = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]]

        matrix = matrix_operations.Matrix(X)
        self.assertEqual(
            matrix.rotate(),
            [[5, 1, 2, 3], [9, 10, 6, 4], [13, 11, 7, 8], [14, 15, 16, 12]])
예제 #2
0
    def test_matrix_subtraction(self):
        X = [[12, 7, 3], [4, 5, 6], [7, 8, 9]]

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

        matrix = matrix_operations.Matrix(X, Y)
        self.assertEqual(matrix.subtract(),
                         [[7, -1, 2], [-2, -2, 3], [3, 3, 0]])
예제 #3
0
    def test_matrix_addition(self):
        X = [[12, 7, 3], [4, 5, 6], [7, 8, 9]]

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

        matrix = matrix_operations.Matrix(X, Y)
        self.assertEqual(matrix.add(),
                         [[17, 15, 4], [10, 12, 9], [11, 13, 18]])
예제 #4
0
    def test_matrix_multiplication(self):
        X = [[12, 7, 3], [4, 5, 6], [7, 8, 9]]

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

        matrix = matrix_operations.Matrix(X, Y)
        self.assertEqual(
            matrix.multiply(),
            [[114, 160, 60, 27], [74, 97, 73, 14], [119, 157, 112, 23]])
예제 #5
0
    def test_matrix_exceptions(self):
        X = [[12, 7, 3], [4, 5, 6], [7, 8, 9]]

        Y = [[5, 8], [6, 7], [4, 5]]

        matrix = matrix_operations.Matrix(X, Y)

        # test exception
        self.assertRaises(Exception, matrix.add)
        self.assertRaises(Exception, matrix.subtract)
예제 #6
0
 def test_matrix_unique_paths(self):
     matrix = matrix_operations.Matrix()
     self.assertEqual(matrix.count_unique_paths(3, 3), 6)
예제 #7
0
    def test_matrix_transpose(self):
        X = [[12, 7], [4, 5], [3, 8]]

        matrix = matrix_operations.Matrix(X)
        self.assertEqual(matrix.transpose(), [[12, 4, 3], [7, 5, 8]])