MCPcopy
hub / github.com/stretchr/testify / InDeltaSlice

Function InDeltaSlice

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

1478
1479// InDeltaSlice is the same as InDelta, except it compares two slices.
1480func InDeltaSlice(t TestingT, expected, actual interface{}, delta float64, msgAndArgs ...interface{}) bool {
1481 if h, ok := t.(tHelper); ok {
1482 h.Helper()
1483 }
1484 if expected == nil || actual == nil ||
1485 reflect.TypeOf(actual).Kind() != reflect.Slice ||
1486 reflect.TypeOf(expected).Kind() != reflect.Slice {
1487 return Fail(t, "Parameters must be slice", msgAndArgs...)
1488 }
1489
1490 actualSlice := reflect.ValueOf(actual)
1491 expectedSlice := reflect.ValueOf(expected)
1492
1493 for i := 0; i < actualSlice.Len(); i++ {
1494 result := InDelta(t, actualSlice.Index(i).Interface(), expectedSlice.Index(i).Interface(), delta, msgAndArgs...)
1495 if !result {
1496 return result
1497 }
1498 }
1499
1500 return true
1501}
1502
1503// InDeltaMapValues is the same as InDelta, but it compares all values between two maps. Both maps must have exactly the same keys.
1504func 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