InEpsilon asserts that expected and actual have a relative error less than epsilon
(t TestingT, expected, actual interface{}, epsilon float64, msgAndArgs ...interface{})
| 1568 | |
| 1569 | // InEpsilon asserts that expected and actual have a relative error less than epsilon |
| 1570 | func 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. |
| 1593 | func InEpsilonSlice(t TestingT, expected, actual interface{}, epsilon float64, msgAndArgs ...interface{}) bool { |