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

Function InEpsilon

assert/assertions.go:1518–1538  ·  view source on GitHub ↗

InEpsilon asserts that expected and actual have a relative error less than epsilon

(t TestingT, expected, actual interface{}, epsilon float64, msgAndArgs ...interface{})

Source from the content-addressed store, hash-verified

1516
1517// InEpsilon asserts that expected and actual have a relative error less than epsilon
1518func InEpsilon(t TestingT, expected, actual interface{}, epsilon float64, msgAndArgs ...interface{}) bool {
1519 if h, ok := t.(tHelper); ok {
1520 h.Helper()
1521 }
1522 if math.IsNaN(epsilon) {
1523 return Fail(t, "epsilon must not be NaN", msgAndArgs...)
1524 }
1525 actualEpsilon, err := calcRelativeError(expected, actual)
1526 if err != nil {
1527 return Fail(t, err.Error(), msgAndArgs...)
1528 }
1529 if math.IsNaN(actualEpsilon) {
1530 return Fail(t, "relative error is NaN", msgAndArgs...)
1531 }
1532 if actualEpsilon > epsilon {
1533 return Fail(t, fmt.Sprintf("Relative error is too high: %#v (expected)\n"+
1534 " < %#v (actual)", epsilon, actualEpsilon), msgAndArgs...)
1535 }
1536
1537 return true
1538}
1539
1540// InEpsilonSlice is the same as InEpsilon, except it compares each value from two slices.
1541func InEpsilonSlice(t TestingT, expected, actual interface{}, epsilon float64, msgAndArgs ...interface{}) bool {

Callers 5

InEpsilonFunction · 0.92
InEpsilonfFunction · 0.70
TestInEpsilonFunction · 0.70
InEpsilonSliceFunction · 0.70
InEpsilonMethod · 0.70

Calls 4

calcRelativeErrorFunction · 0.85
FailFunction · 0.70
HelperMethod · 0.65
ErrorMethod · 0.45

Tested by 1

TestInEpsilonFunction · 0.56