def test_rotate_matrix(self): # Positive tests. original_matrix = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]] expected_matrix = [[13, 9, 5, 1], [14, 10, 6, 2], [15, 11, 7, 3], [16, 12, 8, 4]] self.assertEqual(expected_matrix, rotate_matrix(original_matrix)) # Negative tests. original_matrix = [] self.assertEqual(None, rotate_matrix(original_matrix)) original_matrix = [[1], []] self.assertEqual(None, rotate_matrix(original_matrix)) original_matrix = [[1, 2], [3]] self.assertEqual(None, rotate_matrix(original_matrix)) original_matrix = [[1], [2, 3]] self.assertEqual(None, rotate_matrix(original_matrix)) original_matrix = [[1]] self.assertEqual(None, rotate_matrix(original_matrix)) original_matrix = [[3, 1], [4, 2]] self.assertEqual(None, rotate_matrix(original_matrix)) original_matrix = [[7, 4, 1], [8, 5, 2], [9, 6, 3]] self.assertEqual(None, rotate_matrix(original_matrix))
def test_rotate_matrix_4(self): matrix = [ [1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]] rotated = [ [13, 9, 5, 1], [14, 10, 6, 2], [15, 11, 7, 3], [16, 12, 8, 4]] rotate_matrix(matrix) self.assertEquals(matrix, rotated)
def test_matrix_rotation_even(): matrix = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]] output = [[13, 9, 5, 1], [14, 10, 6, 2], [15, 11, 7, 3], [16, 12, 8, 4]] assert output == rotate_matrix(matrix)
def generate_magic_squares_three_by_three(): magic_squares = [] m = magic_square.solve(3) magic_squares.append(copy.deepcopy(m)) for _ in range(3): rotate_matrix.rotate_matrix(m) magic_squares.append(copy.deepcopy(m)) flip_matrix.flip_matrix_horizontal(m) magic_squares.append(copy.deepcopy(m)) for _ in range(3): rotate_matrix.rotate_matrix(m) magic_squares.append(copy.deepcopy(m)) return magic_squares
def test_rotate_matrix_6(self): matrix = [ [1, 2, 3, 4, 5, 6], [7, 8, 9, 10, 11, 12], [13, 14, 15, 16, 17, 18], [19, 20, 21, 22, 23, 24], [25, 26, 27, 28, 29, 30], [31, 32, 33, 34, 35, 36]] rotated = [ [31, 25, 19, 13, 7, 1], [32, 26, 20, 14, 8, 2], [33, 27, 21, 15, 9, 3], [34, 28, 22, 16, 10, 4], [35, 29, 23, 17, 11, 5], [36, 30, 24, 18, 12, 6]] rotate_matrix(matrix) self.assertEquals(matrix, rotated)
def test_matrix_rotation_odd(): arr = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] output = [ [7, 4, 1], [8, 5, 2], [9, 6, 3], ] assert output == rotate_matrix(arr)
def test_empty_matrix(self): matrix = [] rotate_matrix(matrix) self.assertEquals(matrix, [])