MCPcopy Create free account
hub / github.com/jmespath/go-jmespath / InDeltaMapValues

Function InDeltaMapValues

internal/testify/assert/assertions.go:1148–1189  ·  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

1146
1147// InDeltaMapValues is the same as InDelta, but it compares all values between two maps. Both maps must have exactly the same keys.
1148func InDeltaMapValues(t TestingT, expected, actual interface{}, delta float64, msgAndArgs ...interface{}) bool {
1149 if h, ok := t.(tHelper); ok {
1150 h.Helper()
1151 }
1152 if expected == nil || actual == nil ||
1153 reflect.TypeOf(actual).Kind() != reflect.Map ||
1154 reflect.TypeOf(expected).Kind() != reflect.Map {
1155 return Fail(t, "Arguments must be maps", msgAndArgs...)
1156 }
1157
1158 expectedMap := reflect.ValueOf(expected)
1159 actualMap := reflect.ValueOf(actual)
1160
1161 if expectedMap.Len() != actualMap.Len() {
1162 return Fail(t, "Arguments must have the same number of keys", msgAndArgs...)
1163 }
1164
1165 for _, k := range expectedMap.MapKeys() {
1166 ev := expectedMap.MapIndex(k)
1167 av := actualMap.MapIndex(k)
1168
1169 if !ev.IsValid() {
1170 return Fail(t, fmt.Sprintf("missing key %q in expected map", k), msgAndArgs...)
1171 }
1172
1173 if !av.IsValid() {
1174 return Fail(t, fmt.Sprintf("missing key %q in actual map", k), msgAndArgs...)
1175 }
1176
1177 if !InDelta(
1178 t,
1179 ev.Interface(),
1180 av.Interface(),
1181 delta,
1182 msgAndArgs...,
1183 ) {
1184 return false
1185 }
1186 }
1187
1188 return true
1189}
1190
1191func calcRelativeError(expected, actual interface{}) (float64, error) {
1192 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

Used in the wild real call sites across dependent graphs

searching dependent graphs…