def test_rotate_matrix_any_degree_anticlockwise(self): for degree in self.degrees: rotated_matrix = rotate_matrix( matrix=self.matrix, degree=degree, clockwise=False) self.assertEqual( rotated_matrix, self.anticlockwise_any_degree_result_dictionary[degree])
def test_rotate_matrix_degree_1_anticlockwise(self): rotated_matrix = rotate_matrix( matrix=self.matrix, degree=1, clockwise=False) self.assertEqual(rotated_matrix, [['2', '3', '4', '5', '6', '7', '8'], ['1', '26', '27', '28', '29', '30', '9'], ['24', '25', '42', '43', '44', '31', '10'], ['23', '40', '41', '49', '45', '32', '11'], ['22', '39', '48', '47', '46', '33', '12'], ['21', '38', '37', '36', '35', '34', '13'], ['20', '19', '18', '17', '16', '15', '14']])
BASE_PATH = FILE_PATH.parent IMAGE_PATH = BASE_PATH / 'images' path = (IMAGE_PATH / 'Kills_skull_64x64.png').absolute() path = path.as_posix() image = cv2.imread(path) red_channel = image[:, :, 2] matrix = red_channel.tolist() image_name = 'Kill_skull_64x64_red_channel.png' path = (IMAGE_PATH / image_name).absolute() path = path.as_posix() cv2.imwrite(path, red_channel) rotated_matrix = rotate_matrix(matrix, degree=15, clockwise=True) rotated_matrix = np.array(rotated_matrix) image_name = 'Kill_skull_64x64_red_channel_rotated_15_degree_clockwise.png' path = (IMAGE_PATH / image_name).absolute() path = path.as_posix() cv2.imwrite(path, rotated_matrix) rotated_matrix = rotate_matrix(matrix, degree=30, clockwise=True) rotated_matrix = np.array(rotated_matrix) image_name = 'Kill_skull_64x64_red_channel_rotated_30_degree_clockwise.png' path = (IMAGE_PATH / image_name).absolute() path = path.as_posix() cv2.imwrite(path, rotated_matrix) rotated_matrix = rotate_matrix(matrix, degree=45, clockwise=True) rotated_matrix = np.array(rotated_matrix)
def test_rotate_matrix_shape_any_degree_anticlockwise(self): for degree in self.degrees: rotated_matrix = rotate_matrix( matrix=self.matrix, degree=degree, clockwise=False) self.assertEqual(self.array_shape(rotated_matrix), self.array_shape(self.matrix))
def test_rotate_matrix_shape_degree_1_anticlockwise(self): rotated_matrix = rotate_matrix( matrix=self.matrix, degree=1, clockwise=False) self.assertEqual(self.array_shape(rotated_matrix), self.array_shape(self.matrix))