MCPcopy Create free account
hub / github.com/stretchr/testify / InDeltaMapValues

Function InDeltaMapValues

assert/assertions.go:1452–1493  ·  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

1450
1451// InDeltaMapValues is the same as InDelta, but it compares all values between two maps. Both maps must have exactly the same keys.
1452func InDeltaMapValues(t TestingT, expected, actual interface{}, delta float64, msgAndArgs ...interface{}) bool {
1453 if h, ok := t.(tHelper); ok {
1454 h.Helper()
1455 }
1456 if expected == nil || actual == nil ||
1457 reflect.TypeOf(actual).Kind() != reflect.Map ||
1458 reflect.TypeOf(expected).Kind() != reflect.Map {
1459 return Fail(t, "Arguments must be maps", msgAndArgs...)
1460 }
1461
1462 expectedMap := reflect.ValueOf(expected)
1463 actualMap := reflect.ValueOf(actual)
1464
1465 if expectedMap.Len() != actualMap.Len() {
1466 return Fail(t, "Arguments must have the same number of keys", msgAndArgs...)
1467 }
1468
1469 for _, k := range expectedMap.MapKeys() {
1470 ev := expectedMap.MapIndex(k)
1471 av := actualMap.MapIndex(k)
1472
1473 if !ev.IsValid() {
1474 return Fail(t, fmt.Sprintf("missing key %q in expected map", k), msgAndArgs...)
1475 }
1476
1477 if !av.IsValid() {
1478 return Fail(t, fmt.Sprintf("missing key %q in actual map", k), msgAndArgs...)
1479 }
1480
1481 if !InDelta(
1482 t,
1483 ev.Interface(),
1484 av.Interface(),
1485 delta,
1486 msgAndArgs...,
1487 ) {
1488 return false
1489 }
1490 }
1491
1492 return true
1493}
1494
1495func calcRelativeError(expected, actual interface{}) (float64, error) {
1496 af, aok := toFloat(expected)

Callers 4

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

Calls 4

FailFunction · 0.70
InDeltaFunction · 0.70
HelperMethod · 0.65
LenMethod · 0.45

Tested by 1

TestInDeltaMapValuesFunction · 0.56