def test_rotate_matrix(self): tests = [ ([[]], [[]]), ([[1]], [[1]]), ([[1, 2], [4, 3]], [[4, 1], [3, 2]]), ([[1, 2, 3], [8, 9, 4], [7, 6, 5]], [[7, 8, 1], [6, 9, 2], [5, 4, 3]]), ([[1, 2, 3, 4], [12, 13, 14, 5], [11, 16, 15, 6], [10, 9, 8, 7]], [[10, 11, 12, 1], [9, 16, 13, 2], [8, 15, 14, 3], [7, 6, 5, 4]]), ] for i in range(len(tests)): actual = rotate_matrix(tests[i][0]) expected = tests[i][1] self.assertEqual( actual, expected, 'case {} failed, test={}, actual={}'.format( i, tests[i], actual))
def test_4_x_4(self): original = [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]] rotated = [[4, 3, 2, 1], [4, 3, 2, 1], [4, 3, 2, 1], [4, 3, 2, 1]] self.assertEqual(subject.rotate_matrix(original), rotated)
def test_3_x_3(self): original = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] rotated = [[7, 4, 1], [8, 5, 2], [9, 6, 3]] self.assertEqual(subject.rotate_matrix(original), rotated)
def test_2_x_2(self): original = [[1, 2], [3, 4]] rotated = [[3, 1], [4, 2]] self.assertEqual(subject.rotate_matrix(original), rotated)
def test_empty(self): self.assertEqual(subject.rotate_matrix([]), False)