-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcases_test.go
183 lines (181 loc) · 3.81 KB
/
cases_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
176
177
178
179
180
181
182
183
package allyourbase
// Source: exercism/problem-specifications
// Commit: c21ffd7 all-your-base: improve "input base is one" test
// Problem Specifications Version: 2.3.0
var testCases = []struct {
description string
inputBase int
inputDigits []int
outputBase int
expected []int
err string
}{
{
description: "single bit one to decimal",
inputBase: 2,
inputDigits: []int{1},
outputBase: 10,
expected: []int{1},
err: "",
},
{
description: "binary to single decimal",
inputBase: 2,
inputDigits: []int{1, 0, 1},
outputBase: 10,
expected: []int{5},
err: "",
},
{
description: "single decimal to binary",
inputBase: 10,
inputDigits: []int{5},
outputBase: 2,
expected: []int{1, 0, 1},
err: "",
},
{
description: "binary to multiple decimal",
inputBase: 2,
inputDigits: []int{1, 0, 1, 0, 1, 0},
outputBase: 10,
expected: []int{4, 2},
err: "",
},
{
description: "decimal to binary",
inputBase: 10,
inputDigits: []int{4, 2},
outputBase: 2,
expected: []int{1, 0, 1, 0, 1, 0},
err: "",
},
{
description: "trinary to hexadecimal",
inputBase: 3,
inputDigits: []int{1, 1, 2, 0},
outputBase: 16,
expected: []int{2, 10},
err: "",
},
{
description: "hexadecimal to trinary",
inputBase: 16,
inputDigits: []int{2, 10},
outputBase: 3,
expected: []int{1, 1, 2, 0},
err: "",
},
{
description: "15-bit integer",
inputBase: 97,
inputDigits: []int{3, 46, 60},
outputBase: 73,
expected: []int{6, 10, 45},
err: "",
},
{
description: "empty list",
inputBase: 2,
inputDigits: []int{},
outputBase: 10,
expected: []int{0},
err: "",
},
{
description: "single zero",
inputBase: 10,
inputDigits: []int{0},
outputBase: 2,
expected: []int{0},
err: "",
},
{
description: "multiple zeros",
inputBase: 10,
inputDigits: []int{0, 0, 0},
outputBase: 2,
expected: []int{0},
err: "",
},
{
description: "leading zeros",
inputBase: 7,
inputDigits: []int{0, 6, 0},
outputBase: 10,
expected: []int{4, 2},
err: "",
},
{
description: "input base is one",
inputBase: 1,
inputDigits: []int{0},
outputBase: 10,
expected: []int(nil),
err: "input base must be >= 2",
},
{
description: "input base is zero",
inputBase: 0,
inputDigits: []int{},
outputBase: 10,
expected: []int(nil),
err: "input base must be >= 2",
},
{
description: "input base is negative",
inputBase: -2,
inputDigits: []int{1},
outputBase: 10,
expected: []int(nil),
err: "input base must be >= 2",
},
{
description: "negative digit",
inputBase: 2,
inputDigits: []int{1, -1, 1, 0, 1, 0},
outputBase: 10,
expected: []int(nil),
err: "all digits must satisfy 0 <= d < input base",
},
{
description: "invalid positive digit",
inputBase: 2,
inputDigits: []int{1, 2, 1, 0, 1, 0},
outputBase: 10,
expected: []int(nil),
err: "all digits must satisfy 0 <= d < input base",
},
{
description: "output base is one",
inputBase: 2,
inputDigits: []int{1, 0, 1, 0, 1, 0},
outputBase: 1,
expected: []int(nil),
err: "output base must be >= 2",
},
{
description: "output base is zero",
inputBase: 10,
inputDigits: []int{7},
outputBase: 0,
expected: []int(nil),
err: "output base must be >= 2",
},
{
description: "output base is negative",
inputBase: 2,
inputDigits: []int{1},
outputBase: -7,
expected: []int(nil),
err: "output base must be >= 2",
},
{
description: "both bases are negative",
inputBase: -2,
inputDigits: []int{1},
outputBase: -7,
expected: []int(nil),
err: "input base must be >= 2",
},
}