-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathint_test.go
361 lines (314 loc) · 10.6 KB
/
int_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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
package assert
import "testing"
func TestThatIntIsZeroHasNoErrors(t *testing.T) {
assert, mockT := setupWithMockT(t)
assert.ThatInt(0).IsZero().IsZero()
mockT.HasNoErrors()
}
func TestThatIntIsZeroHasErrorMessages(t *testing.T) {
assert, mockT := setupWithMockT(t)
assert.ThatInt(6).IsZero().IsZero()
mockT.HasErrorMessages(
"Expected zero, but was <6>.",
"Expected zero, but was <6>.",
)
}
func TestThatIntIsNonZeroHasNoErrors(t *testing.T) {
assert, mockT := setupWithMockT(t)
assert.ThatInt(-1).IsNonZero()
assert.ThatInt(1).IsNonZero()
mockT.HasNoErrors()
}
func TestThatIntIsNonZeroHasErrorMessages(t *testing.T) {
assert, mockT := setupWithMockT(t)
assert.ThatInt(0).IsNonZero().IsNonZero()
mockT.HasErrorMessages(
"Expected nonzero, but was zero.",
"Expected nonzero, but was zero.",
)
}
func TestThatIntIsEqualToHasNoErrors(t *testing.T) {
assert, mockT := setupWithMockT(t)
assert.ThatInt(1).IsEqualTo(1).IsEqualTo(1)
mockT.HasNoErrors()
}
func TestThatIntIsEqualToHasErrorMessages(t *testing.T) {
assert, mockT := setupWithMockT(t)
assert.ThatInt(1).IsEqualTo(2).IsEqualTo(3)
mockT.HasErrorMessages(
"Expected integer equal to <2>, but was <1>.",
"Expected integer equal to <3>, but was <1>.",
)
}
func TestThatIntIsNotEqualToHasNoErrors(t *testing.T) {
assert, mockT := setupWithMockT(t)
assert.ThatInt(5).IsNotEqualTo(4).IsNotEqualTo(6)
mockT.HasNoErrors()
}
func TestThatIntIsNotEqualToHasErrorMessages(t *testing.T) {
assert, mockT := setupWithMockT(t)
assert.ThatInt(-5).IsNotEqualTo(-5).IsNotEqualTo(-5)
mockT.HasErrorMessages(
"Expected integer not equal to <-5>, but was equal.",
"Expected integer not equal to <-5>, but was equal.",
)
}
func TestThatIntIsPositiveHasNoErrors(t *testing.T) {
assert, mockT := setupWithMockT(t)
assert.ThatInt(1).IsPositive()
assert.ThatInt(10).IsPositive()
mockT.HasNoErrors()
}
func TestThatIntIsPositiveHasErrorMessages(t *testing.T) {
assert, mockT := setupWithMockT(t)
assert.ThatInt(0).IsPositive()
assert.ThatInt(-10).IsPositive()
mockT.HasErrorMessages(
"Expected positive integer, but was <0>.",
"Expected positive integer, but was <-10>.",
)
}
func TestThatIntIsNonPositiveHasNoErrors(t *testing.T) {
assert, mockT := setupWithMockT(t)
assert.ThatInt(0).IsNonPositive()
assert.ThatInt(-30).IsNonPositive()
mockT.HasNoErrors()
}
func TestThatIntIsNonPositiveHasErrorMessages(t *testing.T) {
assert, mockT := setupWithMockT(t)
assert.ThatInt(1).IsNonPositive()
assert.ThatInt(30).IsNonPositive()
mockT.HasErrorMessages(
"Expected nonpositive integer, but was <1>.",
"Expected nonpositive integer, but was <30>.",
)
}
func TestThatIntIsNegativeHasNoErrors(t *testing.T) {
assert, mockT := setupWithMockT(t)
assert.ThatInt(-1).IsNegative()
assert.ThatInt(-100).IsNegative()
mockT.HasNoErrors()
}
func TestThatIntIsNegativeHasErrorMessages(t *testing.T) {
assert, mockT := setupWithMockT(t)
assert.ThatInt(0).IsNegative()
assert.ThatInt(100).IsNegative()
mockT.HasErrorMessages(
"Expected negative integer, but was <0>.",
"Expected negative integer, but was <100>.",
)
}
func TestThatIntIsNonNegativeHasNoErrors(t *testing.T) {
assert, mockT := setupWithMockT(t)
assert.ThatInt(0).IsNonNegative()
assert.ThatInt(300).IsNonNegative()
mockT.HasNoErrors()
}
func TestThatIntIsNonNegativeHasErrorMessages(t *testing.T) {
assert, mockT := setupWithMockT(t)
assert.ThatInt(-1).IsNonNegative()
assert.ThatInt(-300).IsNonNegative()
mockT.HasErrorMessages(
"Expected nonnegative integer, but was <-1>.",
"Expected nonnegative integer, but was <-300>.",
)
}
func TestThatIntIsGreaterThanHasNoErrors(t *testing.T) {
assert, mockT := setupWithMockT(t)
assert.ThatInt(4).IsGreaterThan(3).IsGreaterThan(-666)
mockT.HasNoErrors()
}
func TestThatIntIsGreaterThanHasErrorMessages(t *testing.T) {
assert, mockT := setupWithMockT(t)
assert.ThatInt(4).IsGreaterThan(4).IsGreaterThan(777)
mockT.HasErrorMessages(
"Expected integer greater than <4>, but was <4>.",
"Expected integer greater than <777>, but was <4>.",
)
}
func TestThatIntIsGreaterOrEqualToHasNoErrors(t *testing.T) {
assert, mockT := setupWithMockT(t)
assert.ThatInt(-2).IsGreaterOrEqualTo(-2).IsGreaterOrEqualTo(-128)
mockT.HasNoErrors()
}
func TestThatIntIsGreaterOrEqualToHasErrorMessages(t *testing.T) {
assert, mockT := setupWithMockT(t)
assert.ThatInt(-2).IsGreaterOrEqualTo(-1).IsGreaterOrEqualTo(128)
mockT.HasErrorMessages(
"Expected integer greater or equal to <-1>, but was <-2>.",
"Expected integer greater or equal to <128>, but was <-2>.",
)
}
func TestThatIntIsLessThanHasNoErrors(t *testing.T) {
assert, mockT := setupWithMockT(t)
assert.ThatInt(28).IsLessThan(29).IsLessThan(999)
mockT.HasNoErrors()
}
func TestThatIntIsLessThanHasErrorMessages(t *testing.T) {
assert, mockT := setupWithMockT(t)
assert.ThatInt(28).IsLessThan(28).IsLessThan(0)
mockT.HasErrorMessages(
"Expected integer lesser than <28>, but was <28>.",
"Expected integer lesser than <0>, but was <28>.",
)
}
func TestThatIntIsLessOrEqualToHasNoErrors(t *testing.T) {
assert, mockT := setupWithMockT(t)
assert.ThatInt(-6).IsLessOrEqualTo(-6).IsLessOrEqualTo(6)
mockT.HasNoErrors()
}
func TestThatIntIsLessOrEqualToHasErrorMessages(t *testing.T) {
assert, mockT := setupWithMockT(t)
assert.ThatInt(-6).IsLessOrEqualTo(-7).IsLessOrEqualTo(-128)
mockT.HasErrorMessages(
"Expected integer lesser or equal to <-7>, but was <-6>.",
"Expected integer lesser or equal to <-128>, but was <-6>.",
)
}
func TestThatIntIsBetweenHasNoErrors(t *testing.T) {
assert, mockT := setupWithMockT(t)
assert.ThatInt(0).IsBetween(-42, 0).IsBetween(-5, 5).IsBetween(0, 42)
mockT.HasNoErrors()
}
func TestThatIntIsBetweenHasErrorMessages(t *testing.T) {
assert, mockT := setupWithMockT(t)
assert.ThatInt(0).IsBetween(-42, -1).IsBetween(1, 42)
mockT.HasErrorMessages(
"Expected integer to be between <-42, -1>, but was <0>.",
"Expected integer to be between <1, 42>, but was <0>.",
)
}
func TestThatIntIsNotBetweenHasNoErrors(t *testing.T) {
assert, mockT := setupWithMockT(t)
assert.ThatInt(0).IsNotBetween(-42, -1).IsNotBetween(1, 42)
mockT.HasNoErrors()
}
func TestThatIntIsNotBetweenHasErrorMessages(t *testing.T) {
assert, mockT := setupWithMockT(t)
assert.ThatInt(0).IsNotBetween(-42, 0).IsNotBetween(-5, 5).IsNotBetween(0, 42)
mockT.HasErrorMessages(
"Expected integer not to be between <-42, 0>, but was <0>.",
"Expected integer not to be between <-5, 5>, but was <0>.",
"Expected integer not to be between <0, 42>, but was <0>.",
)
}
func TestThatIntIsInHasNoErrors(t *testing.T) {
assert, mockT := setupWithMockT(t)
assert.ThatInt(5).IsIn(1, 2, 3, 5, 8, 13).IsIn(2, 3, 5, 7, 11)
mockT.HasNoErrors()
}
func TestThatIntIsInHasErrorMessages(t *testing.T) {
assert, mockT := setupWithMockT(t)
assert.ThatInt(6).IsIn(1, 2, 3, 5, 8, 13).IsIn(2, 3, 5, 7, 11)
mockT.HasErrorMessages(
"Expected integer to be in (1, 2, 3, 5, 8, 13), but was <6>.",
"Expected integer to be in (2, 3, 5, 7, 11), but was <6>.",
)
}
func TestThatIntIsNotInHasNoErrors(t *testing.T) {
assert, mockT := setupWithMockT(t)
assert.ThatInt(6).IsNotIn(1, 2, 3, 5, 8, 13).IsNotIn(2, 3, 5, 7, 11)
mockT.HasNoErrors()
}
func TestThatIntIsNotInHasErrorMessages(t *testing.T) {
assert, mockT := setupWithMockT(t)
assert.ThatInt(5).IsNotIn(1, 2, 3, 5, 8, 13).IsNotIn(2, 3, 5, 7, 11)
mockT.HasErrorMessages(
"Expected integer not to be in (1, 2, 3, 5, 8, 13), but was <5>.",
"Expected integer not to be in (2, 3, 5, 7, 11), but was <5>.",
)
}
func TestThatIntIsEvenHasNoErrors(t *testing.T) {
assert, mockT := setupWithMockT(t)
assert.ThatInt(6).IsEven()
mockT.HasNoErrors()
}
func TestThatIntIsEvenHasErrorMessages(t *testing.T) {
assert, mockT := setupWithMockT(t)
assert.ThatInt(5).IsEven().IsEven()
mockT.HasErrorMessages(
"Expected integer to be even, but was <5>.",
"Expected integer to be even, but was <5>.",
)
}
func TestThatIntIsOddHasNoErrors(t *testing.T) {
assert, mockT := setupWithMockT(t)
assert.ThatInt(5).IsOdd()
mockT.HasNoErrors()
}
func TestThatIntIsOddHasErrorMessages(t *testing.T) {
assert, mockT := setupWithMockT(t)
assert.ThatInt(6).IsOdd().IsOdd()
mockT.HasErrorMessages(
"Expected integer to be odd, but was <6>.",
"Expected integer to be odd, but was <6>.",
)
}
func TestThatIntIsDivisibleByHasNoErrors(t *testing.T) {
assert, mockT := setupWithMockT(t)
assert.ThatInt(4).IsDivisibleBy(1).IsDivisibleBy(2)
mockT.HasNoErrors()
}
func TestThatIntIsDivisibleByHasErrorMessages(t *testing.T) {
assert, mockT := setupWithMockT(t)
assert.ThatInt(6).IsDivisibleBy(5).IsDivisibleBy(7)
mockT.HasErrorMessages(
"Expected integer to be divisible by <5>, but was <6>.",
"Expected integer to be divisible by <7>, but was <6>.",
)
}
func TestThatIntIsNotDivisibleByHasNoErrors(t *testing.T) {
assert, mockT := setupWithMockT(t)
assert.ThatInt(4).IsNotDivisibleBy(3).IsNotDivisibleBy(5)
mockT.HasNoErrors()
}
func TestThatIntIsNotDivisibleByHasErrorMessages(t *testing.T) {
assert, mockT := setupWithMockT(t)
assert.ThatInt(6).IsNotDivisibleBy(2).IsNotDivisibleBy(3)
mockT.HasErrorMessages(
"Expected integer not to be divisible by <2>, but was <6>.",
"Expected integer not to be divisible by <3>, but was <6>.",
)
}
func TestThatIntIsPrimeHasNoErrors(t *testing.T) {
assert, mockT := setupWithMockT(t)
assert.ThatInt(2).IsPrime().IsPrime()
mockT.HasNoErrors()
}
func TestThatIntIsPrimeHasErrorMessages(t *testing.T) {
assert, mockT := setupWithMockT(t)
assert.ThatInt(1).IsPrime()
assert.ThatInt(4).IsPrime()
mockT.HasErrorMessages(
"Expected integer to be prime, but was <1>.",
"Expected integer to be prime, but was <4>.",
)
}
func TestThatIntIsNotPrimeHasNoErrors(t *testing.T) {
assert, mockT := setupWithMockT(t)
assert.ThatInt(25).IsNotPrime().IsNotPrime()
mockT.HasNoErrors()
}
func TestThatIntIsNotPrimeHasErrorMessages(t *testing.T) {
assert, mockT := setupWithMockT(t)
assert.ThatInt(5).IsNotPrime()
assert.ThatInt(31).IsNotPrime()
mockT.HasErrorMessages(
"Expected integer not to be prime, but was <5>.",
"Expected integer not to be prime, but was <31>.",
)
}
func TestThatIntIsAnswerToTheUltimateQuestionOfLifeHasNoErrors(t *testing.T) {
assert, mockT := setupWithMockT(t)
assert.ThatInt(42).IsAnswerToTheUltimateQuestionOfLife().IsAnswerToTheUltimateQuestionOfLife()
mockT.HasNoErrors()
}
func TestThatIntIsAnswerToTheUltimateQuestionOfLifeHasErrorMessages(t *testing.T) {
assert, mockT := setupWithMockT(t)
assert.ThatInt(0).IsAnswerToTheUltimateQuestionOfLife()
assert.ThatInt(44).IsAnswerToTheUltimateQuestionOfLife()
mockT.HasErrorMessages(
"Expected answer to the ultimate question of life, but was <0>.",
"Expected answer to the ultimate question of life, but was <44>.",
)
}