| 2414 | } |
| 2415 | |
| 2416 | func TestInEpsilon(t *testing.T) { |
| 2417 | t.Parallel() |
| 2418 | |
| 2419 | mockT := new(testing.T) |
| 2420 | |
| 2421 | cases := []struct { |
| 2422 | a, b interface{} |
| 2423 | epsilon float64 |
| 2424 | }{ |
| 2425 | {uint8(2), uint16(2), .001}, |
| 2426 | {2.1, 2.2, 0.1}, |
| 2427 | {2.2, 2.1, 0.1}, |
| 2428 | {-2.1, -2.2, 0.1}, |
| 2429 | {-2.2, -2.1, 0.1}, |
| 2430 | {uint64(100), uint8(101), 0.01}, |
| 2431 | {0.1, -0.1, 2}, |
| 2432 | {0.1, 0, 2}, |
| 2433 | {math.NaN(), math.NaN(), 1}, |
| 2434 | {time.Second, time.Second + time.Millisecond, 0.002}, |
| 2435 | } |
| 2436 | |
| 2437 | for _, tc := range cases { |
| 2438 | True(t, InEpsilon(t, tc.a, tc.b, tc.epsilon, "Expected %V and %V to have a relative difference of %v", tc.a, tc.b, tc.epsilon), "test: %q", tc) |
| 2439 | } |
| 2440 | |
| 2441 | cases = []struct { |
| 2442 | a, b interface{} |
| 2443 | epsilon float64 |
| 2444 | }{ |
| 2445 | {uint8(2), int16(-2), .001}, |
| 2446 | {uint64(100), uint8(102), 0.01}, |
| 2447 | {2.1, 2.2, 0.001}, |
| 2448 | {2.2, 2.1, 0.001}, |
| 2449 | {2.1, -2.2, 1}, |
| 2450 | {2.1, "bla-bla", 0}, |
| 2451 | {0.1, -0.1, 1.99}, |
| 2452 | {0, 0.1, 2}, // expected must be different to zero |
| 2453 | {time.Second, time.Second + 10*time.Millisecond, 0.002}, |
| 2454 | {math.NaN(), 0, 1}, |
| 2455 | {0, math.NaN(), 1}, |
| 2456 | {0, 0, math.NaN()}, |
| 2457 | {math.Inf(1), 1, 1}, |
| 2458 | {math.Inf(-1), 1, 1}, |
| 2459 | {1, math.Inf(1), 1}, |
| 2460 | {1, math.Inf(-1), 1}, |
| 2461 | {math.Inf(1), math.Inf(1), 1}, |
| 2462 | {math.Inf(1), math.Inf(-1), 1}, |
| 2463 | {math.Inf(-1), math.Inf(1), 1}, |
| 2464 | {math.Inf(-1), math.Inf(-1), 1}, |
| 2465 | } |
| 2466 | |
| 2467 | for _, tc := range cases { |
| 2468 | False(t, InEpsilon(mockT, tc.a, tc.b, tc.epsilon, "Expected %V and %V to have a relative difference of %v", tc.a, tc.b, tc.epsilon)) |
| 2469 | } |
| 2470 | } |
| 2471 | |
| 2472 | func TestInEpsilonSlice(t *testing.T) { |
| 2473 | t.Parallel() |