Skip to content

Commit

Permalink
Merge pull request #1483 from stretchr/fix-1231-InEpsilonSlice-expect…
Browse files Browse the repository at this point in the history
…ed-actual-order

assert.InEpsilonSlice: fix expected/actual order and other improvements
  • Loading branch information
MovieStoreGuy committed Jan 21, 2024
2 parents 92533fa + f8dcfd6 commit 14d4b9b
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions assert/assertions.go
Expand Up @@ -1457,19 +1457,26 @@ func InEpsilonSlice(t TestingT, expected, actual interface{}, epsilon float64, m
if h, ok := t.(tHelper); ok {
h.Helper()
}
if expected == nil || actual == nil ||
reflect.TypeOf(actual).Kind() != reflect.Slice ||
reflect.TypeOf(expected).Kind() != reflect.Slice {

if expected == nil || actual == nil {
return Fail(t, "Parameters must be slice", msgAndArgs...)
}

actualSlice := reflect.ValueOf(actual)
expectedSlice := reflect.ValueOf(expected)
actualSlice := reflect.ValueOf(actual)

for i := 0; i < actualSlice.Len(); i++ {
result := InEpsilon(t, actualSlice.Index(i).Interface(), expectedSlice.Index(i).Interface(), epsilon)
if !result {
return result
if expectedSlice.Type().Kind() != reflect.Slice {
return Fail(t, "Expected value must be slice", msgAndArgs...)
}

expectedLen := expectedSlice.Len()
if !IsType(t, expected, actual) || !Len(t, actual, expectedLen) {
return false
}

for i := 0; i < expectedLen; i++ {
if !InEpsilon(t, expectedSlice.Index(i).Interface(), actualSlice.Index(i).Interface(), epsilon, "at index %d", i) {
return false
}
}

Expand Down

0 comments on commit 14d4b9b

Please sign in to comment.