def encode(string): if string == "": return "" clean_string = strip_string(string) width = square_width(clean_string) # working up to here character_matrix = make_chunks(clean_string, width) character_matrix = transpose_matrix(character_matrix) encoded_message = join_character_matrix(character_matrix) return encoded_message
def test_truncated_matrix_transposition(self): matrix = [[1, 2, 3], [4, 5, 6], [7]] transposed = [[1, 4, 7], [2, 5], [3, 6]] self.assertEqual(transposed, transpose_matrix(matrix))
def test_matrix_transposition(self): matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] transposed = [[1, 4, 7], [2, 5, 8], [3, 6, 9]] self.assertEqual(transposed, transpose_matrix(matrix))
def test_character_matrix(self): char_matrix = ["abc", "def", "ghi"] transpose = [list("adg"), list("beh"), list("cfi")] self.assertEqual(transpose, transpose_matrix(char_matrix))
def test_skinny_matrix_transposition(self): transposed = [[1, 2, 3], [4, 5, 6]] matrix = [[1, 4], [2, 5], [3, 6]] self.assertEqual(transposed, transpose_matrix(matrix))
def test_non_square_matrix_transposition(self): matrix = [[1, 2, 3], [4, 5, 6]] transposed = [[1, 4], [2, 5], [3, 6]] self.assertEqual(transposed, transpose_matrix(matrix))