MCPcopy Index your code
hub / github.com/expr-lang/expr / InDelta

Function InDelta

internal/testify/assert/assertions.go:1361–1391  ·  view source on GitHub ↗

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{})

Source from the content-addressed store, hash-verified

1359//
1360// assert.InDelta(t, math.Pi, 22/7.0, 0.01)
1361func 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.
1394func InDeltaSlice(t TestingT, expected, actual interface{}, delta float64, msgAndArgs ...interface{}) bool {

Callers 6

InDeltaFunction · 0.92
InDeltafFunction · 0.70
TestInDeltaFunction · 0.70
InDeltaSliceFunction · 0.70
InDeltaMapValuesFunction · 0.70
InDeltaMethod · 0.70

Calls 4

SprintfMethod · 0.80
toFloatFunction · 0.70
FailFunction · 0.70
HelperMethod · 0.45

Tested by 1

TestInDeltaFunction · 0.56

Used in the wild real call sites across dependent graphs

searching dependent graphs…