MCPcopy
hub / github.com/expr-lang/expr / InDeltaMapValues

Function InDeltaMapValues

internal/testify/assert/assertions.go:1418–1459  ·  view source on GitHub ↗

InDeltaMapValues is the same as InDelta, but it compares all values between two maps. Both maps must have exactly the same keys.

(t TestingT, expected, actual interface{}, delta float64, msgAndArgs ...interface{})

Source from the content-addressed store, hash-verified

1416
1417// InDeltaMapValues is the same as InDelta, but it compares all values between two maps. Both maps must have exactly the same keys.
1418func InDeltaMapValues(t TestingT, expected, actual interface{}, delta float64, msgAndArgs ...interface{}) bool {
1419 if h, ok := t.(tHelper); ok {
1420 h.Helper()
1421 }
1422 if expected == nil || actual == nil ||
1423 reflect.TypeOf(actual).Kind() != reflect.Map ||
1424 reflect.TypeOf(expected).Kind() != reflect.Map {
1425 return Fail(t, "Arguments must be maps", msgAndArgs...)
1426 }
1427
1428 expectedMap := reflect.ValueOf(expected)
1429 actualMap := reflect.ValueOf(actual)
1430
1431 if expectedMap.Len() != actualMap.Len() {
1432 return Fail(t, "Arguments must have the same number of keys", msgAndArgs...)
1433 }
1434
1435 for _, k := range expectedMap.MapKeys() {
1436 ev := expectedMap.MapIndex(k)
1437 av := actualMap.MapIndex(k)
1438
1439 if !ev.IsValid() {
1440 return Fail(t, fmt.Sprintf("missing key %q in expected map", k), msgAndArgs...)
1441 }
1442
1443 if !av.IsValid() {
1444 return Fail(t, fmt.Sprintf("missing key %q in actual map", k), msgAndArgs...)
1445 }
1446
1447 if !InDelta(
1448 t,
1449 ev.Interface(),
1450 av.Interface(),
1451 delta,
1452 msgAndArgs...,
1453 ) {
1454 return false
1455 }
1456 }
1457
1458 return true
1459}
1460
1461func calcRelativeError(expected, actual interface{}) (float64, error) {
1462 af, aok := toFloat(expected)

Callers 4

InDeltaMapValuesFunction · 0.92
InDeltaMapValuesfFunction · 0.70
TestInDeltaMapValuesFunction · 0.70
InDeltaMapValuesMethod · 0.70

Calls 5

SprintfMethod · 0.80
FailFunction · 0.70
InDeltaFunction · 0.70
HelperMethod · 0.45
LenMethod · 0.45

Tested by 1

TestInDeltaMapValuesFunction · 0.56

Used in the wild real call sites across dependent graphs

searching dependent graphs…