MCPcopy Create free account
hub / github.com/stretchr/testify / TestInEpsilon

Function TestInEpsilon

assert/assertions_test.go:2020–2073  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2018}
2019
2020func TestInEpsilon(t *testing.T) {
2021 mockT := new(testing.T)
2022
2023 cases := []struct {
2024 a, b interface{}
2025 epsilon float64
2026 }{
2027 {uint8(2), uint16(2), .001},
2028 {2.1, 2.2, 0.1},
2029 {2.2, 2.1, 0.1},
2030 {-2.1, -2.2, 0.1},
2031 {-2.2, -2.1, 0.1},
2032 {uint64(100), uint8(101), 0.01},
2033 {0.1, -0.1, 2},
2034 {0.1, 0, 2},
2035 {math.NaN(), math.NaN(), 1},
2036 {time.Second, time.Second + time.Millisecond, 0.002},
2037 }
2038
2039 for _, tc := range cases {
2040 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)
2041 }
2042
2043 cases = []struct {
2044 a, b interface{}
2045 epsilon float64
2046 }{
2047 {uint8(2), int16(-2), .001},
2048 {uint64(100), uint8(102), 0.01},
2049 {2.1, 2.2, 0.001},
2050 {2.2, 2.1, 0.001},
2051 {2.1, -2.2, 1},
2052 {2.1, "bla-bla", 0},
2053 {0.1, -0.1, 1.99},
2054 {0, 0.1, 2}, // expected must be different to zero
2055 {time.Second, time.Second + 10*time.Millisecond, 0.002},
2056 {math.NaN(), 0, 1},
2057 {0, math.NaN(), 1},
2058 {0, 0, math.NaN()},
2059 {math.Inf(1), 1, 1},
2060 {math.Inf(-1), 1, 1},
2061 {1, math.Inf(1), 1},
2062 {1, math.Inf(-1), 1},
2063 {math.Inf(1), math.Inf(1), 1},
2064 {math.Inf(1), math.Inf(-1), 1},
2065 {math.Inf(-1), math.Inf(1), 1},
2066 {math.Inf(-1), math.Inf(-1), 1},
2067 }
2068
2069 for _, tc := range cases {
2070 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))
2071 }
2072
2073}
2074
2075func TestInEpsilonSlice(t *testing.T) {
2076 mockT := new(testing.T)

Callers

nothing calls this directly

Calls 3

TrueFunction · 0.70
InEpsilonFunction · 0.70
FalseFunction · 0.70

Tested by

no test coverage detected