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

Function InDeltaSlice

assert/assertions.go:1428–1449  ·  view source on GitHub ↗

InDeltaSlice is the same as InDelta, except it compares two slices.

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

Source from the content-addressed store, hash-verified

1426
1427// InDeltaSlice is the same as InDelta, except it compares two slices.
1428func InDeltaSlice(t TestingT, expected, actual interface{}, delta float64, msgAndArgs ...interface{}) bool {
1429 if h, ok := t.(tHelper); ok {
1430 h.Helper()
1431 }
1432 if expected == nil || actual == nil ||
1433 reflect.TypeOf(actual).Kind() != reflect.Slice ||
1434 reflect.TypeOf(expected).Kind() != reflect.Slice {
1435 return Fail(t, "Parameters must be slice", msgAndArgs...)
1436 }
1437
1438 actualSlice := reflect.ValueOf(actual)
1439 expectedSlice := reflect.ValueOf(expected)
1440
1441 for i := 0; i < actualSlice.Len(); i++ {
1442 result := InDelta(t, actualSlice.Index(i).Interface(), expectedSlice.Index(i).Interface(), delta, msgAndArgs...)
1443 if !result {
1444 return result
1445 }
1446 }
1447
1448 return true
1449}
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 {

Callers 4

InDeltaSliceFunction · 0.92
InDeltaSlicefFunction · 0.70
TestInDeltaSliceFunction · 0.70
InDeltaSliceMethod · 0.70

Calls 4

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

Tested by 1

TestInDeltaSliceFunction · 0.56