diff --git a/assert/assertions.go b/assert/assertions.go index 166f63726..79224f345 100644 --- a/assert/assertions.go +++ b/assert/assertions.go @@ -1497,6 +1497,10 @@ func InDeltaSlice(t TestingT, expected, actual interface{}, delta float64, msgAn actualSlice := reflect.ValueOf(actual) expectedSlice := reflect.ValueOf(expected) + if expectedSlice.Len() != actualSlice.Len() { + return Fail(t, "Parameters must have the same number of elements", msgAndArgs...) + } + for i := 0; i < actualSlice.Len(); i++ { result := InDelta(t, actualSlice.Index(i).Interface(), expectedSlice.Index(i).Interface(), delta, msgAndArgs...) if !result { diff --git a/assert/assertions_test.go b/assert/assertions_test.go index 11642e096..a408123f7 100644 --- a/assert/assertions_test.go +++ b/assert/assertions_test.go @@ -2360,6 +2360,16 @@ func TestInDeltaSlice(t *testing.T) { 0.1), "{1, NaN, 2} is not element-wise close to {0, NaN, 3} in delta=0.1") False(t, InDeltaSlice(mockT, "", nil, 1), "Expected non numeral slices to fail") + + False(t, InDeltaSlice(mockT, + []float64{1, 2}, + []float64{1}, + 0.001), "Slices of different lengths should fail even if the common prefix matches") + + False(t, InDeltaSlice(mockT, + []float64{1}, + []float64{1, 2}, + 0.001), "Slices of different lengths should fail regardless of which is longer") } func TestInDeltaMapValues(t *testing.T) {