InEpsilon asserts that expected and actual have a relative error less than epsilon
(t TestingT, expected, actual interface{}, epsilon float64, msgAndArgs ...interface{})
| 1482 | |
| 1483 | // InEpsilon asserts that expected and actual have a relative error less than epsilon |
| 1484 | func InEpsilon(t TestingT, expected, actual interface{}, epsilon float64, msgAndArgs ...interface{}) bool { |
| 1485 | if h, ok := t.(tHelper); ok { |
| 1486 | h.Helper() |
| 1487 | } |
| 1488 | if math.IsNaN(epsilon) { |
| 1489 | return Fail(t, "epsilon must not be NaN", msgAndArgs...) |
| 1490 | } |
| 1491 | actualEpsilon, err := calcRelativeError(expected, actual) |
| 1492 | if err != nil { |
| 1493 | return Fail(t, err.Error(), msgAndArgs...) |
| 1494 | } |
| 1495 | if actualEpsilon > epsilon { |
| 1496 | return Fail(t, fmt.Sprintf("Relative error is too high: %#v (expected)\n"+ |
| 1497 | " < %#v (actual)", epsilon, actualEpsilon), msgAndArgs...) |
| 1498 | } |
| 1499 | |
| 1500 | return true |
| 1501 | } |
| 1502 | |
| 1503 | // InEpsilonSlice is the same as InEpsilon, except it compares each value from two slices. |
| 1504 | func InEpsilonSlice(t TestingT, expected, actual interface{}, epsilon float64, msgAndArgs ...interface{}) bool { |
searching dependent graphs…