87
87
if !Equal(mockT, nil, nil) {
88
88
t.Error("Equal should return true")
90
if !Equal(mockT, int32(123), int64(123)) {
91
t.Error("Equal should return true")
93
if !Equal(mockT, int64(123), uint64(123)) {
94
t.Error("Equal should return true")
269
275
func TestEqual_Funcs(t *testing.T) {
271
277
type f func() int
272
var f1 f = func() int { return 1 }
273
var f2 f = func() int { return 2 }
277
Equal(t, f1_copy, f1, "Funcs are the same and should be considered equal")
278
f1 := func() int { return 1 }
279
f2 := func() int { return 2 }
283
Equal(t, f1Copy, f1, "Funcs are the same and should be considered equal")
278
284
NotEqual(t, f1, f2, "f1 and f2 are different")
284
290
mockT := new(testing.T)
286
292
// start with a nil error
289
295
True(t, NoError(mockT, err), "NoError should return True for nil arg")
291
297
// now set an error
292
err = errors.New("Some error")
298
err = errors.New("some error")
294
300
False(t, NoError(mockT, err), "NoError with error should return False")
300
306
mockT := new(testing.T)
302
308
// start with a nil error
305
311
False(t, Error(mockT, err), "Error should return False for nil arg")
307
313
// now set an error
308
err = errors.New("Some error")
314
err = errors.New("some error")
310
316
True(t, Error(mockT, err), "Error with error should return True")
315
321
mockT := new(testing.T)
317
323
// start with a nil error
319
325
False(t, EqualError(mockT, err, ""),
320
326
"EqualError should return false for nil arg")
322
328
// now set an error
323
err = errors.New("Some error")
329
err = errors.New("some error")
324
330
False(t, EqualError(mockT, err, "Not some error"),
325
331
"EqualError should return false for different error string")
326
True(t, EqualError(mockT, err, "Some error"),
332
True(t, EqualError(mockT, err, "some error"),
327
333
"EqualError should return true")
330
336
func Test_isEmpty(t *testing.T) {
332
ch_with_value := make(chan struct{}, 1)
333
ch_with_value <- struct{}{}
338
chWithValue := make(chan struct{}, 1)
339
chWithValue <- struct{}{}
335
341
True(t, isEmpty(""))
336
342
True(t, isEmpty(nil))
337
343
True(t, isEmpty([]string{}))
338
344
True(t, isEmpty(0))
345
True(t, isEmpty(int32(0)))
346
True(t, isEmpty(int64(0)))
339
347
True(t, isEmpty(false))
340
348
True(t, isEmpty(map[string]string{}))
341
349
True(t, isEmpty(new(time.Time)))
346
354
False(t, isEmpty(1))
347
355
False(t, isEmpty(true))
348
356
False(t, isEmpty(map[string]string{"Hello": "World"}))
349
False(t, isEmpty(ch_with_value))
357
False(t, isEmpty(chWithValue))
353
361
func TestEmpty(t *testing.T) {
355
363
mockT := new(testing.T)
356
ch_with_value := make(chan struct{}, 1)
357
ch_with_value <- struct{}{}
364
chWithValue := make(chan struct{}, 1)
365
chWithValue <- struct{}{}
359
367
True(t, Empty(mockT, ""), "Empty string is empty")
360
368
True(t, Empty(mockT, nil), "Nil is empty")
368
376
False(t, Empty(mockT, []string{"something"}), "Non empty string array is not empty")
369
377
False(t, Empty(mockT, 1), "Non-zero int value is not empty")
370
378
False(t, Empty(mockT, true), "True value is not empty")
371
False(t, Empty(mockT, ch_with_value), "Channel with values is not empty")
379
False(t, Empty(mockT, chWithValue), "Channel with values is not empty")
374
382
func TestNotEmpty(t *testing.T) {
376
384
mockT := new(testing.T)
377
ch_with_value := make(chan struct{}, 1)
378
ch_with_value <- struct{}{}
385
chWithValue := make(chan struct{}, 1)
386
chWithValue <- struct{}{}
380
388
False(t, NotEmpty(mockT, ""), "Empty string is empty")
381
389
False(t, NotEmpty(mockT, nil), "Nil is empty")
389
397
True(t, NotEmpty(mockT, []string{"something"}), "Non empty string array is not empty")
390
398
True(t, NotEmpty(mockT, 1), "Non-zero int value is not empty")
391
399
True(t, NotEmpty(mockT, true), "True value is not empty")
392
True(t, NotEmpty(mockT, ch_with_value), "Channel with values is not empty")
400
True(t, NotEmpty(mockT, chWithValue), "Channel with values is not empty")
403
func Test_getLen(t *testing.T) {
404
falseCases := []interface{}{
412
for _, v := range falseCases {
414
False(t, ok, "Expected getLen fail to get length of %#v", v)
415
Equal(t, 0, l, "getLen should return 0 for %#v", v)
418
ch := make(chan int, 5)
422
trueCases := []struct {
427
{[...]int{1, 2, 3}, 3},
429
{map[int]int{1: 2, 2: 4, 3: 6}, 3},
437
{map[int]int(nil), 0},
438
{(chan int)(nil), 0},
441
for _, c := range trueCases {
443
True(t, ok, "Expected getLen success to get length of %#v", c.v)
448
func TestLen(t *testing.T) {
449
mockT := new(testing.T)
451
False(t, Len(mockT, nil, 0), "nil does not have length")
452
False(t, Len(mockT, 0, 0), "int does not have length")
453
False(t, Len(mockT, true, 0), "true does not have length")
454
False(t, Len(mockT, false, 0), "false does not have length")
455
False(t, Len(mockT, 'A', 0), "Rune does not have length")
456
False(t, Len(mockT, struct{}{}, 0), "Struct does not have length")
458
ch := make(chan int, 5)
468
{[...]int{1, 2, 3}, 3},
470
{map[int]int{1: 2, 2: 4, 3: 6}, 3},
478
{map[int]int(nil), 0},
479
{(chan int)(nil), 0},
482
for _, c := range cases {
483
True(t, Len(mockT, c.v, c.l), "%#v have %d items", c.v, c.l)
395
487
func TestWithinDuration(t *testing.T) {
410
502
False(t, WithinDuration(mockT, a, b, -11*time.Second), "A 10s difference is not within a 9s time difference")
411
503
False(t, WithinDuration(mockT, b, a, -11*time.Second), "A 10s difference is not within a 9s time difference")
506
func TestInDelta(t *testing.T) {
507
mockT := new(testing.T)
509
True(t, InDelta(mockT, 1.001, 1, 0.01), "|1.001 - 1| <= 0.01")
510
True(t, InDelta(mockT, 1, 1.001, 0.01), "|1 - 1.001| <= 0.01")
511
True(t, InDelta(mockT, 1, 2, 1), "|1 - 2| <= 1")
512
False(t, InDelta(mockT, 1, 2, 0.5), "Expected |1 - 2| <= 0.5 to fail")
513
False(t, InDelta(mockT, 2, 1, 0.5), "Expected |2 - 1| <= 0.5 to fail")
514
False(t, InDelta(mockT, "", nil, 1), "Expected non numerals to fail")
520
{uint8(2), uint8(1), 1},
521
{uint16(2), uint16(1), 1},
522
{uint32(2), uint32(1), 1},
523
{uint64(2), uint64(1), 1},
526
{int8(2), int8(1), 1},
527
{int16(2), int16(1), 1},
528
{int32(2), int32(1), 1},
529
{int64(2), int64(1), 1},
531
{float32(2), float32(1), 1},
532
{float64(2), float64(1), 1},
535
for _, tc := range cases {
536
True(t, InDelta(mockT, tc.a, tc.b, tc.delta), "Expected |%V - %V| <= %v", tc.a, tc.b, tc.delta)