-
Notifications
You must be signed in to change notification settings - Fork 0
/
transpose_test.py
118 lines (102 loc) · 3.31 KB
/
transpose_test.py
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import unittest
from transpose import transpose
# Tests adapted from `problem-specifications//canonical-data.json`
class TransposeTest(unittest.TestCase):
def test_empty_string(self):
lines = []
expected = []
self.assertEqual(transpose("\n".join(lines)), "\n".join(expected))
def test_two_characters_in_a_row(self):
lines = ["A1"]
expected = ["A", "1"]
self.assertEqual(transpose("\n".join(lines)), "\n".join(expected))
def test_two_characters_in_a_column(self):
lines = ["A", "1"]
expected = ["A1"]
self.assertEqual(transpose("\n".join(lines)), "\n".join(expected))
def test_simple(self):
lines = ["ABC", "123"]
expected = ["A1", "B2", "C3"]
self.assertEqual(transpose("\n".join(lines)), "\n".join(expected))
def test_single_line(self):
lines = ["Single line."]
expected = ["S", "i", "n", "g", "l", "e", " ", "l", "i", "n", "e", "."]
self.assertEqual(transpose("\n".join(lines)), "\n".join(expected))
def test_first_line_longer_than_second_line(self):
lines = ["The fourth line.", "The fifth line."]
expected = [
"TT",
"hh",
"ee",
" ",
"ff",
"oi",
"uf",
"rt",
"th",
"h ",
" l",
"li",
"in",
"ne",
"e.",
".",
]
self.assertEqual(transpose("\n".join(lines)), "\n".join(expected))
def test_second_line_longer_than_first_line(self):
lines = ["The first line.", "The second line."]
expected = [
"TT",
"hh",
"ee",
" ",
"fs",
"ie",
"rc",
"so",
"tn",
" d",
"l ",
"il",
"ni",
"en",
".e",
" .",
]
self.assertEqual(transpose("\n".join(lines)), "\n".join(expected))
def test_mixed_line_length(self):
lines = ["The longest line.", "A long line.", "A longer line.", "A line."]
expected = [
"TAAA",
"h ",
"elll",
" ooi",
"lnnn",
"ogge",
"n e.",
"glr",
"ei ",
"snl",
"tei",
" .n",
"l e",
"i .",
"n",
"e",
".",
]
self.assertEqual(transpose("\n".join(lines)), "\n".join(expected))
def test_square(self):
lines = ["HEART", "EMBER", "ABUSE", "RESIN", "TREND"]
expected = ["HEART", "EMBER", "ABUSE", "RESIN", "TREND"]
self.assertEqual(transpose("\n".join(lines)), "\n".join(expected))
def test_rectangle(self):
lines = ["FRACTURE", "OUTLINED", "BLOOMING", "SEPTETTE"]
expected = ["FOBS", "RULE", "ATOP", "CLOT", "TIME", "UNIT", "RENT", "EDGE"]
self.assertEqual(transpose("\n".join(lines)), "\n".join(expected))
def test_triangle(self):
lines = ["T", "EE", "AAA", "SSSS", "EEEEE", "RRRRRR"]
expected = ["TEASER", " EASER", " ASER", " SER", " ER", " R"]
self.assertEqual(transpose("\n".join(lines)), "\n".join(expected))
if __name__ == "__main__":
unittest.main()