Permalink
Browse files

Add InDeltaSlice.

  • Loading branch information...
Chih-Wei Chang
Chih-Wei Chang committed Feb 18, 2015
1 parent efa3c4c commit f0b02af48e5ee31c78b949e9ed67c37e08d1a897
Showing with 19 additions and 0 deletions.
  1. +19 −0 assert/assertions.go
View
@@ -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)

0 comments on commit f0b02af

Please sign in to comment.