|
| 1 | +import unittest |
| 2 | +from strassen_matrix_multiplication import split_matrix |
| 3 | + |
| 4 | + |
| 5 | +class TestSplitMatrix(unittest.TestCase): |
| 6 | + |
| 7 | + def test_4x4_matrix(self): |
| 8 | + matrix = [ |
| 9 | + [4, 3, 2, 4], |
| 10 | + [2, 3, 1, 1], |
| 11 | + [6, 5, 4, 3], |
| 12 | + [8, 4, 1, 6] |
| 13 | + ] |
| 14 | + expected = ( |
| 15 | + [[4, 3], [2, 3]], |
| 16 | + [[2, 4], [1, 1]], |
| 17 | + [[6, 5], [8, 4]], |
| 18 | + [[4, 3], [1, 6]] |
| 19 | + ) |
| 20 | + self.assertEqual(split_matrix(matrix), expected) |
| 21 | + |
| 22 | + def test_8x8_matrix(self): |
| 23 | + matrix = [ |
| 24 | + [4, 3, 2, 4, 4, 3, 2, 4], |
| 25 | + [2, 3, 1, 1, 2, 3, 1, 1], |
| 26 | + [6, 5, 4, 3, 6, 5, 4, 3], |
| 27 | + [8, 4, 1, 6, 8, 4, 1, 6], |
| 28 | + [4, 3, 2, 4, 4, 3, 2, 4], |
| 29 | + [2, 3, 1, 1, 2, 3, 1, 1], |
| 30 | + [6, 5, 4, 3, 6, 5, 4, 3], |
| 31 | + [8, 4, 1, 6, 8, 4, 1, 6] |
| 32 | + ] |
| 33 | + expected = ( |
| 34 | + [[4, 3, 2, 4], [2, 3, 1, 1], [6, 5, 4, 3], [8, 4, 1, 6]], |
| 35 | + [[4, 3, 2, 4], [2, 3, 1, 1], [6, 5, 4, 3], [8, 4, 1, 6]], |
| 36 | + [[4, 3, 2, 4], [2, 3, 1, 1], [6, 5, 4, 3], [8, 4, 1, 6]], |
| 37 | + [[4, 3, 2, 4], [2, 3, 1, 1], [6, 5, 4, 3], [8, 4, 1, 6]] |
| 38 | + ) |
| 39 | + self.assertEqual(split_matrix(matrix), expected) |
| 40 | + |
| 41 | + def test_invalid_odd_matrix(self): |
| 42 | + matrix = [ |
| 43 | + [1, 2, 3], |
| 44 | + [4, 5, 6], |
| 45 | + [7, 8, 9] |
| 46 | + ] |
| 47 | + with self.assertRaises(Exception): |
| 48 | + split_matrix(matrix) |
| 49 | + |
| 50 | + def test_invalid_non_square_matrix(self): |
| 51 | + matrix = [ |
| 52 | + [1, 2, 3, 4], |
| 53 | + [5, 6, 7, 8], |
| 54 | + [9, 10, 11, 12] |
| 55 | + ] |
| 56 | + with self.assertRaises(Exception): |
| 57 | + split_matrix(matrix) |
| 58 | + |
| 59 | + |
| 60 | +if __name__ == "__main__": |
| 61 | + unittest.main() |
0 commit comments