Beispiel #1
0
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
Beispiel #2
0
 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))
Beispiel #3
0
 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))
Beispiel #4
0
 def test_character_matrix(self):
     char_matrix = ["abc", "def", "ghi"]
     transpose = [list("adg"), list("beh"), list("cfi")]
     self.assertEqual(transpose, transpose_matrix(char_matrix))
Beispiel #5
0
 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))
Beispiel #6
0
 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))