| 489 | } |
| 490 | |
| 491 | func TestInDeltaWrapper(t *testing.T) { |
| 492 | t.Parallel() |
| 493 | |
| 494 | assert := New(new(testing.T)) |
| 495 | |
| 496 | True(t, assert.InDelta(1.001, 1, 0.01), "|1.001 - 1| <= 0.01") |
| 497 | True(t, assert.InDelta(1, 1.001, 0.01), "|1 - 1.001| <= 0.01") |
| 498 | True(t, assert.InDelta(1, 2, 1), "|1 - 2| <= 1") |
| 499 | False(t, assert.InDelta(1, 2, 0.5), "Expected |1 - 2| <= 0.5 to fail") |
| 500 | False(t, assert.InDelta(2, 1, 0.5), "Expected |2 - 1| <= 0.5 to fail") |
| 501 | False(t, assert.InDelta("", nil, 1), "Expected non numerals to fail") |
| 502 | |
| 503 | cases := []struct { |
| 504 | a, b interface{} |
| 505 | delta float64 |
| 506 | }{ |
| 507 | {uint8(2), uint8(1), 1}, |
| 508 | {uint16(2), uint16(1), 1}, |
| 509 | {uint32(2), uint32(1), 1}, |
| 510 | {uint64(2), uint64(1), 1}, |
| 511 | |
| 512 | {int(2), int(1), 1}, |
| 513 | {int8(2), int8(1), 1}, |
| 514 | {int16(2), int16(1), 1}, |
| 515 | {int32(2), int32(1), 1}, |
| 516 | {int64(2), int64(1), 1}, |
| 517 | |
| 518 | {float32(2), float32(1), 1}, |
| 519 | {float64(2), float64(1), 1}, |
| 520 | } |
| 521 | |
| 522 | for _, tc := range cases { |
| 523 | True(t, assert.InDelta(tc.a, tc.b, tc.delta), "Expected |%V - %V| <= %v", tc.a, tc.b, tc.delta) |
| 524 | } |
| 525 | } |
| 526 | |
| 527 | func TestInEpsilonWrapper(t *testing.T) { |
| 528 | t.Parallel() |