InEpsilonSlice is the same as InEpsilon, except it compares each value from two slices.
(t TestingT, expected, actual interface{}, epsilon float64, msgAndArgs ...interface{})
| 1591 | |
| 1592 | // InEpsilonSlice is the same as InEpsilon, except it compares each value from two slices. |
| 1593 | func InEpsilonSlice(t TestingT, expected, actual interface{}, epsilon float64, msgAndArgs ...interface{}) bool { |
| 1594 | if h, ok := t.(tHelper); ok { |
| 1595 | h.Helper() |
| 1596 | } |
| 1597 | |
| 1598 | if expected == nil || actual == nil { |
| 1599 | return Fail(t, "Parameters must be slice", msgAndArgs...) |
| 1600 | } |
| 1601 | |
| 1602 | expectedSlice := reflect.ValueOf(expected) |
| 1603 | actualSlice := reflect.ValueOf(actual) |
| 1604 | |
| 1605 | if expectedSlice.Type().Kind() != reflect.Slice { |
| 1606 | return Fail(t, "Expected value must be slice", msgAndArgs...) |
| 1607 | } |
| 1608 | |
| 1609 | expectedLen := expectedSlice.Len() |
| 1610 | if !IsType(t, expected, actual) || !Len(t, actual, expectedLen) { |
| 1611 | return false |
| 1612 | } |
| 1613 | |
| 1614 | for i := 0; i < expectedLen; i++ { |
| 1615 | if !InEpsilon(t, expectedSlice.Index(i).Interface(), actualSlice.Index(i).Interface(), epsilon, "at index %d", i) { |
| 1616 | return false |
| 1617 | } |
| 1618 | } |
| 1619 | |
| 1620 | return true |
| 1621 | } |
| 1622 | |
| 1623 | /* |
| 1624 | Errors |