MCPcopy
hub / github.com/stretchr/testify / InEpsilon

Function InEpsilon

assert/assertions.go:1570–1590  ·  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

1568
1569// InEpsilon asserts that expected and actual have a relative error less than epsilon
1570func InEpsilon(t TestingT, expected, actual interface{}, epsilon float64, msgAndArgs ...interface{}) bool {
1571 if h, ok := t.(tHelper); ok {
1572 h.Helper()
1573 }
1574 if math.IsNaN(epsilon) {
1575 return Fail(t, "epsilon must not be NaN", msgAndArgs...)
1576 }
1577 actualEpsilon, err := calcRelativeError(expected, actual)
1578 if err != nil {
1579 return Fail(t, err.Error(), msgAndArgs...)
1580 }
1581 if math.IsNaN(actualEpsilon) {
1582 return Fail(t, "relative error is NaN", msgAndArgs...)
1583 }
1584 if actualEpsilon > epsilon {
1585 return Fail(t, fmt.Sprintf("Relative error is too high: %#v (expected)\n"+
1586 " < %#v (actual)", epsilon, actualEpsilon), msgAndArgs...)
1587 }
1588
1589 return true
1590}
1591
1592// InEpsilonSlice is the same as InEpsilon, except it compares each value from two slices.
1593func 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