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