Skip to content

Commit

Permalink
Add InDeltaSlice.
Browse files Browse the repository at this point in the history
  • Loading branch information
Chih-Wei Chang committed Feb 18, 2015
1 parent efa3c4c commit f0b02af
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions assert/assertions.go
Expand Up @@ -667,6 +667,25 @@ func InDelta(t TestingT, expected, actual interface{}, delta float64, msgAndArgs
return true
}

func InDeltaSlice(t TestingT, expected, actual interface{}, delta float64, msgAndArgs ...interface{}) bool {
if reflect.TypeOf(actual).Kind() != reflect.Slice ||
reflect.TypeOf(expected).Kind() != reflect.Slice {
return Fail(t, fmt.Sprintf("Parameters must be slice"), msgAndArgs...)
}

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

for i := 0; i < actualSlice.Len(); i++ {
result := InDelta(t, actualSlice.Index(i).Interface(), expectedSlice.Index(i).Interface(), delta)
if !result {
return result
}
}

return true
}

// min(|expected|, |actual|) * epsilon
func calcEpsilonDelta(expected, actual interface{}, epsilon float64) float64 {
af, aok := toFloat(expected)
Expand Down

0 comments on commit f0b02af

Please sign in to comment.