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]])
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]])
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]])
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]])
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)
def test_matrix_unique_paths(self): matrix = matrix_operations.Matrix() self.assertEqual(matrix.count_unique_paths(3, 3), 6)
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]])