InDelta asserts that the two numerals are within delta of each other. assert.InDelta(t, math.Pi, 22/7.0, 0.01)
(t TestingT, expected, actual interface{}, delta float64, msgAndArgs ...interface{})
| 1359 | // |
| 1360 | // assert.InDelta(t, math.Pi, 22/7.0, 0.01) |
| 1361 | func InDelta(t TestingT, expected, actual interface{}, delta float64, msgAndArgs ...interface{}) bool { |
| 1362 | if h, ok := t.(tHelper); ok { |
| 1363 | h.Helper() |
| 1364 | } |
| 1365 | |
| 1366 | af, aok := toFloat(expected) |
| 1367 | bf, bok := toFloat(actual) |
| 1368 | |
| 1369 | if !aok || !bok { |
| 1370 | return Fail(t, "Parameters must be numerical", msgAndArgs...) |
| 1371 | } |
| 1372 | |
| 1373 | if math.IsNaN(af) && math.IsNaN(bf) { |
| 1374 | return true |
| 1375 | } |
| 1376 | |
| 1377 | if math.IsNaN(af) { |
| 1378 | return Fail(t, "Expected must not be NaN", msgAndArgs...) |
| 1379 | } |
| 1380 | |
| 1381 | if math.IsNaN(bf) { |
| 1382 | return Fail(t, fmt.Sprintf("Expected %v with delta %v, but was NaN", expected, delta), msgAndArgs...) |
| 1383 | } |
| 1384 | |
| 1385 | dt := af - bf |
| 1386 | if dt < -delta || dt > delta { |
| 1387 | return Fail(t, fmt.Sprintf("Max difference between %v and %v allowed is %v, but difference was %v", expected, actual, delta, dt), msgAndArgs...) |
| 1388 | } |
| 1389 | |
| 1390 | return true |
| 1391 | } |
| 1392 | |
| 1393 | // InDeltaSlice is the same as InDelta, except it compares two slices. |
| 1394 | func InDeltaSlice(t TestingT, expected, actual interface{}, delta float64, msgAndArgs ...interface{}) bool { |
searching dependent graphs…