-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathhit_test.go
522 lines (456 loc) · 9.42 KB
/
hit_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
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
package hit
import (
"errors"
"image"
"log"
"strings"
"testing"
)
func TestIf0(t *testing.T) {
a := If(500)
if a != 500 {
t.Errorf(`a := If(500)`)
}
}
func TestIf0a(t *testing.T) {
var b int
a := If(func() { b = 10 })
if a != nil && b != 10 {
t.Errorf(`a := If(func() { b = 10 })`)
}
}
func TestIf0b(t *testing.T) {
var b int
a := If(func() interface{} { b = 10; return 30 })
if a != 30 && b != 10 {
t.Errorf(`a := If(func() { b = 10 })`)
}
}
func TestIf1(t *testing.T) {
expect := 5
a := If(true, 5, 50)
if a != expect {
t.Errorf(`a := If(true, 5, 50)`)
}
}
func TestIf1b(t *testing.T) {
var b = []string{"aa", "bb"}
a := If(len(b) > 10, b[1], "cancel")
if a != "cancel" {
t.Errorf(`a := If(len(b) > 1, b[1], "cancel")`)
}
}
func TestIf2(t *testing.T) {
expect := 50
a := If(false, 5, 50)
if a != expect {
t.Errorf(`a := If(false, 5, 50)`)
}
}
func TestIf3(t *testing.T) {
expect := 50
a := If(nil, 5, 50)
if a != expect {
t.Errorf(`a := If(nil, 5, 50)`)
}
}
func TestIf4(t *testing.T) {
expect := 50
a := If("", 5, 50)
if a != expect {
t.Errorf(`a := If("", 5, 50)`)
}
}
func TestIf5(t *testing.T) {
expect := 50
a := If("0", 5, 50)
if a != expect {
t.Errorf(`a := If("0", 5, 50)`)
}
}
func TestIf5a(t *testing.T) {
expect := 50
a := If("0.0", 5, 50)
if a != expect {
t.Errorf(`a := If("0.0", 5, 50)`)
}
}
func TestIf5b(t *testing.T) {
expect := 50
a := If("-0", 5, 50)
if a != expect {
t.Errorf(`a := If("-0", 5, 50)`)
}
}
func TestIf6(t *testing.T) {
expect := 50
a := If("false", 5, 50)
if a != expect {
t.Errorf(`a := If("false", 5, 50)`)
}
}
func TestIf6a(t *testing.T) {
expect := 50
a := If("FALSE", 5, 50)
if a != expect {
t.Errorf(`a := If("FALSE", 5, 50)`)
}
}
func TestIf6b(t *testing.T) {
expect := 50
a := If("f", 5, 50)
if a != expect {
t.Errorf(`a := If("f", 5, 50)`)
}
}
func TestIf6c(t *testing.T) {
expect := 50
a := If("F", 5, 50)
if a != expect {
t.Errorf(`a := If("F", 5, 50)`)
}
}
func TestIf7(t *testing.T) {
expect := 50
a := If(0, 5, 50)
if a != expect {
t.Errorf(`a := If(0, 5, 50)`)
}
}
func TestIf7a(t *testing.T) {
expect := 50
a := If(0.0, 5, 50)
if a != expect {
t.Errorf(`a := If(0.0, 5, 50)`)
}
}
func TestIf7b(t *testing.T) {
expect := 50
a := If(uint(0), 5, 50)
if a != expect {
t.Errorf(`a := If(uint(0), 5, 50)`)
}
}
func TestIf8(t *testing.T) {
expect := 5
a := If(299, 5, 50)
if a != expect {
t.Errorf(`a := If(299, 5, 50)`)
}
}
func TestIf9(t *testing.T) {
expect := 5
a := If("test", 5, 50)
if a != expect {
t.Errorf(`a := If("test", 5, 50)`)
}
}
func TestIf10(t *testing.T) {
expect := 5
a := If(log.Printf, 5, 50)
if a != expect {
t.Errorf(`a := If(log.Printf, 5, 50)`)
}
}
func TestIf11(t *testing.T) {
expect := 5
a := If(func() bool { return true }(), 5, 50)
if a != expect {
t.Errorf(`a := If(func() bool { return true }(), 5, 50)`)
}
}
func TestIf12(t *testing.T) {
a := If(true, func() interface{} { return "run-func" }, 50)
log.Println(a)
if a != "run-func" {
t.Errorf(`a := If(true, func() interface{} { return "run-func" }, 50)`)
}
}
func TestIf13(t *testing.T) {
a := If(func() interface{} { return "false" }, 5, 50)
log.Println(a)
if a != 50 {
t.Errorf(`a := If(func() interface{} { return "false" }, 5, 50)`)
}
}
func TestIf14(t *testing.T) {
a := If(func() interface{} { return 123 }, 5, 50)
log.Println(a)
if a != 5 {
t.Errorf(`a := If(func() interface{} { return 123 }, 5, 50)`)
}
}
func TestIf15(t *testing.T) {
a := If(20 > 5, func() interface{} { return "ok" }, func() interface{} { return "cancel" })
if a != "ok" {
t.Errorf(`a := If(20 > 5, func() interface{} { return "ok" }, func() interface{} { return "cancel" })`)
}
}
func TestIf16(t *testing.T) {
a := If(20 > 5, func() (string, int) { return "ok", 1 }, func() interface{} { return "cancel" })
if v, ok := a.([]interface{}); !ok || v[0] != "ok" || v[1] != 1 {
t.Errorf(`a := If(20 > 5, func() (string, int) { return "ok", 1 }, func() interface{} { return "cancel" })`)
}
}
func TestAnd1(t *testing.T) {
expect := 5
a := If(true, 5)
if a != expect {
t.Errorf(`a := If(true, 5)`)
}
}
func TestAnd2(t *testing.T) {
a := If(false, 5)
if a != nil {
t.Errorf(`a := If(false, 5)`)
}
}
func TestAnd3(t *testing.T) {
a := If(200, 5)
if a != 5 {
t.Errorf(`a := If(200, 5)`)
}
}
func TestAnd4(t *testing.T) {
a := If("false", 5)
if a != nil {
t.Errorf(`a := If("false", 5)`)
}
}
func TestAnd5(t *testing.T) {
var b string
a := If(func() { b = "ok" }, 5)
if a != nil {
t.Errorf(`a := If("false", 5)`)
}
if b != "ok" {
t.Errorf(`a := If("false", 5)`)
}
}
func TestAnd6(t *testing.T) {
var b string
a := If(1, func() interface{} { b = "ok"; return 10 })
if a != 10 {
t.Errorf(`a := If("false", 5)`)
}
if b != "ok" {
t.Errorf(`a := If("false", 5)`)
}
}
func TestAnd7(t *testing.T) {
a := If(0, 5)
if a != nil {
t.Errorf(`a := If(0, 5)`)
}
}
func TestAnd7a(t *testing.T) {
a := If(0.0, 5)
if a != nil {
t.Errorf(`a := If(0.0, 5)`)
}
}
func TestAnd7b(t *testing.T) {
a := If(uint(0), 5)
if a != nil {
t.Errorf(`a := If(uint(0), 5)`)
}
}
func TestOr0(t *testing.T) {
a := Or(500)
if a != 500 {
t.Errorf(`a := If(500)`)
}
}
func TestOr0a(t *testing.T) {
var b int
a := Or(func() { b = 10 })
if a != nil && b != 10 {
t.Errorf(`a := If(func() { b = 10 })`)
}
}
func TestOr0b(t *testing.T) {
var b int
a := Or(func() interface{} { b = 10; return 30 })
if a != 30 && b != 10 {
t.Errorf(`a := If(func() { b = 10 })`)
}
}
func TestOr1(t *testing.T) {
a := Or(true, 5)
if a != true {
t.Errorf(`a := Or(true, 5)`)
}
}
func TestOr2(t *testing.T) {
a := Or(400, 5)
if a != 400 {
t.Errorf(`a := Or(400, 5)`)
}
}
func TestOr3(t *testing.T) {
a := Or(0, 5)
if a != 5 {
t.Errorf(`a := Or(0, 5)`)
}
}
func TestOr3a(t *testing.T) {
a := Or(0.0, 5)
if a != 5 {
t.Errorf(`a := Or(0.0, 5)`)
}
}
func TestOr3b(t *testing.T) {
a := Or(uint(0), 5)
if a != 5 {
t.Errorf(`a := Or(uint(0), 5)`)
}
}
func TestOr4(t *testing.T) {
a := Or("0", 5)
if a != 5 {
t.Errorf(`a := Or("0", 5)`)
}
}
func TestOr4a(t *testing.T) {
a := Or("0.0", 5)
if a != 5 {
t.Errorf(`a := Or("0.0", 5)`)
}
}
func TestOr4b(t *testing.T) {
a := Or("-0", 5)
if a != 5 {
t.Errorf(`a := Or("-0", 5)`)
}
}
func TestOr5(t *testing.T) {
a := Or("false", 5)
if a != 5 {
t.Errorf(`a := Or("false", 5)`)
}
}
func TestOr5a(t *testing.T) {
a := Or("FALSE", 5)
if a != 5 {
t.Errorf(`a := Or("FALSE", 5)`)
}
}
func TestOr5b(t *testing.T) {
a := Or("f", 5)
if a != 5 {
t.Errorf(`a := Or("f", 5)`)
}
}
func TestOr5c(t *testing.T) {
a := Or("F", 5)
if a != 5 {
t.Errorf(`a := Or("F", 5)`)
}
}
func TestOr6(t *testing.T) {
a := Or("test", 5)
if a != "test" {
t.Errorf(`a := Or("test", 5)`)
}
}
func TestOr7(t *testing.T) {
a := Or(nil, 5)
if a != 5 {
t.Errorf(`a := Or(nil, 5)`)
}
}
func TestOr8(t *testing.T) {
var b int
a := Or(func() { b = 100 }, 5)
if a != 5 && b != 100 {
t.Errorf(`a := Or(func() { b = 100 }, 5)`)
}
}
func TestOr9(t *testing.T) {
var b int
a := Or(func() interface{} { b = 100; return 500 }, 5)
if a != 500 && b != 100 {
t.Errorf(`a := Or(func() { b = 100 }, 5)`)
}
}
func TestOr10(t *testing.T) {
var b int
a := Or("", func() interface{} { b = 100; return 500 })
if a != 500 && b != 100 {
t.Errorf(`a := Or("", func() interface{} { b = 100; return 500 })`)
}
}
func TestOr11(t *testing.T) {
var b int
a := Or("", func() interface{} { b = 100; return 500 })
if a != 500 && b != 100 {
t.Errorf(`a := Or("", func() interface{} { b = 100; return 500 })`)
}
}
func TestOr12(t *testing.T) {
var b int
a := Or(false, func() interface{} { b = 100; return 500 })
if a != 500 && b != 100 {
t.Errorf(`a := Or("", func() interface{} { b = 100; return 500 })`)
}
}
func TestIfError1(t *testing.T) {
a := If(errors.New("test-error"))
if _, ok := a.(error); ok == false {
t.Errorf(`a := If(errors.New("test-error"))`)
}
}
func TestIfError2(t *testing.T) {
var b int
a := If(errors.New("test-error"), func() { b = 10 })
if _, ok := a.(error); ok == false && b == 10 {
t.Errorf(`a := If(errors.New("test-error"), func() { b = 10 })`)
}
}
func TestFnTime1(t *testing.T) {
a := TestFnTime(func() {})
if strings.Contains(a, "TestFnTime1") == false {
t.Errorf(`a := TestFnTime(func() {})`)
}
}
func TestCallFn1(t *testing.T) {
var b int
a := callFn(func() { b = 100 })
if a != nil && b != 100 {
t.Errorf(`a := callFn(func() { b = 100 })`)
}
}
func TestCallFn2(t *testing.T) {
var b int
a := callFn(func() interface{} { b = 100; return 10 })
if a != 10 && b != 100 {
t.Errorf(`a := callFn(func() interface{} { b = 100; return 10 })`)
}
}
func TestCallFn3(t *testing.T) {
var b int
a := callFn(func() int { b = 100; return 10 })
if a != 10 && b != 100 {
t.Errorf(`a := callFn(func() int { b = 100; return 10 })`)
}
}
func TestCallFn4(t *testing.T) {
var b int
a := callFn(func() image.Point { b = 100; return image.Point{0, 0} })
if v, ok := a.(image.Point); !ok || (!v.Eq(image.Point{0,0}) && b != 100) {
t.Errorf(`a := callFn(func() image.Point { b = 100; return image.Point{0, 0} })`)
}
}
func TestOrError1(t *testing.T) {
a := Or(errors.New("test-error"))
if _, ok := a.(error); ok == false {
t.Errorf(`a := If(errors.New("test-error"))`)
}
}
func TestOrError2(t *testing.T) {
var b int
a := Or(errors.New("test-error"), func() { b = 10 })
if _, ok := a.(error); ok == false && b == 10 {
t.Errorf(`a := If(errors.New("test-error"), func() { b = 10 })`)
}
}