Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions assert/assertions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 10 additions & 0 deletions assert/assertions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading