-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcipher_test.go
175 lines (154 loc) · 8.09 KB
/
cipher_test.go
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
package monastic
import "testing"
func TestNewCipher(t *testing.T) {
for _, tt := range []struct {
n int
err error
}{
{-1, ErrValueTooSmall},
{0, ErrValueTooSmall},
{1, nil},
{9, nil},
{9999, nil},
{10000, ErrValueTooLarge},
} {
if _, err := NewCipher(tt.n); err != tt.err {
t.Fatalf("unexpected error: %s", err)
}
}
}
func TestParts(t *testing.T) {
for _, tt := range []struct {
n int
p []uint
}{
{1, []uint{1}},
{12, []uint{10, 2}},
{123, []uint{100, 20, 3}},
{1234, []uint{1000, 200, 30, 4}},
{4567, []uint{4000, 500, 60, 7}},
{9999, []uint{9000, 900, 90, 9}},
} {
if got := Cipher(tt.n).Parts(); !equalUints(got, tt.p) {
t.Fatalf("unexpected parts: %v, want %v", got, tt.p)
}
}
}
func TestString(t *testing.T) {
for _, tt := range testCases {
if got := Cipher(tt.n).String(); got != tt.s {
t.Fatalf("\n\ngot string for %d:\n\n%s\n%q\n\nwant:\n\n%v\n%q\n\n", tt.n, got, got, tt.s, tt.s)
}
}
}
func equalUints(a, b []uint) bool {
if len(a) != len(b) {
return false
}
for i, v := range a {
if v != b[i] {
return false
}
}
return true
}
var testCases = []struct {
n int
s string
}{
{1, " ****\n * \n * \n * \n * \n * \n * \n"},
{2, " * \n * \n ****\n * \n * \n * \n * \n"},
{3, " * \n ** \n * * \n * *\n * \n * \n * \n"},
{4, " * *\n * * \n ** \n * \n * \n * \n * \n"},
{5, " ****\n * * \n ** \n * \n * \n * \n * \n"},
{6, " * *\n * *\n * *\n * \n * \n * \n * \n"},
{7, " ****\n * *\n * *\n * \n * \n * \n * \n"},
{8, " * *\n * *\n ****\n * \n * \n * \n * \n"},
{9, " ****\n * *\n ****\n * \n * \n * \n * \n"},
{10, "**** \n * \n * \n * \n * \n * \n * \n"},
{11, "*******\n * \n * \n * \n * \n * \n * \n"},
{12, "**** \n * \n ****\n * \n * \n * \n * \n"},
{13, "**** \n ** \n * * \n * *\n * \n * \n * \n"},
{14, "**** *\n * * \n ** \n * \n * \n * \n * \n"},
{15, "*******\n * * \n ** \n * \n * \n * \n * \n"},
{16, "**** *\n * *\n * *\n * \n * \n * \n * \n"},
{17, "*******\n * *\n * *\n * \n * \n * \n * \n"},
{18, "**** *\n * *\n ****\n * \n * \n * \n * \n"},
{19, "*******\n * *\n ****\n * \n * \n * \n * \n"},
{20, " * \n * \n**** \n * \n * \n * \n * \n"},
{30, " * \n ** \n * * \n* * \n * \n * \n * \n"},
{40, "* * \n * * \n ** \n * \n * \n * \n * \n"},
{50, "**** \n * * \n ** \n * \n * \n * \n * \n"},
{60, "* * \n* * \n* * \n * \n * \n * \n * \n"},
{70, "**** \n* * \n* * \n * \n * \n * \n * \n"},
{80, "* * \n* * \n**** \n * \n * \n * \n * \n"},
{90, "**** \n* * \n**** \n * \n * \n * \n * \n"},
{100, " * \n * \n * \n * \n * \n * \n ****\n"},
{200, " * \n * \n * \n * \n ****\n * \n * \n"},
{300, " * \n * \n * \n * *\n * * \n ** \n * \n"},
{400, " * \n * \n * \n * \n ** \n * * \n * *\n"},
{500, " * \n * \n * \n * \n ** \n * * \n ****\n"},
{600, " * \n * \n * \n * \n * *\n * *\n * *\n"},
{700, " * \n * \n * \n * \n * *\n * *\n ****\n"},
{800, " * \n * \n * \n * \n ****\n * *\n * *\n"},
{900, " * \n * \n * \n * \n ****\n * *\n ****\n"},
{1000, " * \n * \n * \n * \n * \n * \n**** \n"},
{2000, " * \n * \n * \n * \n**** \n * \n * \n"},
{3000, " * \n * \n * \n* * \n * * \n ** \n * \n"},
{4000, " * \n * \n * \n * \n ** \n * * \n* * \n"},
{5000, " * \n * \n * \n * \n ** \n * * \n**** \n"},
{6000, " * \n * \n * \n * \n* * \n* * \n* * \n"},
{7000, " * \n * \n * \n * \n* * \n* * \n**** \n"},
{8000, " * \n * \n * \n * \n**** \n* * \n* * \n"},
{9000, " * \n * \n * \n * \n**** \n* * \n**** \n"},
{1, " ****\n * \n * \n * \n * \n * \n * \n"},
{10, "**** \n * \n * \n * \n * \n * \n * \n"},
{100, " * \n * \n * \n * \n * \n * \n ****\n"},
{1000, " * \n * \n * \n * \n * \n * \n**** \n"},
{2, " * \n * \n ****\n * \n * \n * \n * \n"},
{20, " * \n * \n**** \n * \n * \n * \n * \n"},
{200, " * \n * \n * \n * \n ****\n * \n * \n"},
{2000, " * \n * \n * \n * \n**** \n * \n * \n"},
{3, " * \n ** \n * * \n * *\n * \n * \n * \n"},
{30, " * \n ** \n * * \n* * \n * \n * \n * \n"},
{300, " * \n * \n * \n * *\n * * \n ** \n * \n"},
{3000, " * \n * \n * \n* * \n * * \n ** \n * \n"},
{4, " * *\n * * \n ** \n * \n * \n * \n * \n"},
{40, "* * \n * * \n ** \n * \n * \n * \n * \n"},
{400, " * \n * \n * \n * \n ** \n * * \n * *\n"},
{4000, " * \n * \n * \n * \n ** \n * * \n* * \n"},
{5, " ****\n * * \n ** \n * \n * \n * \n * \n"},
{50, "**** \n * * \n ** \n * \n * \n * \n * \n"},
{500, " * \n * \n * \n * \n ** \n * * \n ****\n"},
{5000, " * \n * \n * \n * \n ** \n * * \n**** \n"},
{6, " * *\n * *\n * *\n * \n * \n * \n * \n"},
{60, "* * \n* * \n* * \n * \n * \n * \n * \n"},
{600, " * \n * \n * \n * \n * *\n * *\n * *\n"},
{6000, " * \n * \n * \n * \n* * \n* * \n* * \n"},
{7, " ****\n * *\n * *\n * \n * \n * \n * \n"},
{70, "**** \n* * \n* * \n * \n * \n * \n * \n"},
{700, " * \n * \n * \n * \n * *\n * *\n ****\n"},
{7000, " * \n * \n * \n * \n* * \n* * \n**** \n"},
{8, " * *\n * *\n ****\n * \n * \n * \n * \n"},
{80, "* * \n* * \n**** \n * \n * \n * \n * \n"},
{800, " * \n * \n * \n * \n ****\n * *\n * *\n"},
{8000, " * \n * \n * \n * \n**** \n* * \n* * \n"},
{9, " ****\n * *\n ****\n * \n * \n * \n * \n"},
{90, "**** \n* * \n**** \n * \n * \n * \n * \n"},
{900, " * \n * \n * \n * \n ****\n * *\n ****\n"},
{9000, " * \n * \n * \n * \n**** \n* * \n**** \n"},
{1111, "*******\n * \n * \n * \n * \n * \n*******\n"},
{2222, " * \n * \n*******\n * \n*******\n * \n * \n"},
{3333, " * \n *** \n * * * \n* * *\n * * * \n *** \n * \n"},
{4444, "* * *\n * * * \n *** \n * \n *** \n * * * \n* * *\n"},
{5555, "*******\n * * * \n *** \n * \n *** \n * * * \n*******\n"},
{6666, "* * *\n* * *\n* * *\n * \n* * *\n* * *\n* * *\n"},
{7777, "*******\n* * *\n* * *\n * \n* * *\n* * *\n*******\n"},
{8888, "* * *\n* * *\n*******\n * \n*******\n* * *\n* * *\n"},
{9999, "*******\n* * *\n*******\n * \n*******\n* * *\n*******\n"},
{1993, "**** \n* ** \n**** * \n * *\n ****\n * *\n*******\n"},
{4723, " * \n ** \n**** * \n * *\n ** *\n * * *\n* ****\n"},
{6859, "*******\n * * *\n *****\n * \n* ****\n* * *\n* * *\n"},
{7085, "* ****\n* * * \n***** \n * \n* * \n* * \n**** \n"},
{9433, " * \n *** \n * * * \n* * *\n***** \n* * * \n**** *\n"},
}