InEpsilonSlice is the same as InEpsilon, except it compares each value from two slices.
(t TestingT, expected, actual interface{}, epsilon float64, msgAndArgs ...interface{})
| 1502 | |
| 1503 | // InEpsilonSlice is the same as InEpsilon, except it compares each value from two slices. |
| 1504 | func InEpsilonSlice(t TestingT, expected, actual interface{}, epsilon float64, msgAndArgs ...interface{}) bool { |
| 1505 | if h, ok := t.(tHelper); ok { |
| 1506 | h.Helper() |
| 1507 | } |
| 1508 | |
| 1509 | if expected == nil || actual == nil { |
| 1510 | return Fail(t, "Parameters must be slice", msgAndArgs...) |
| 1511 | } |
| 1512 | |
| 1513 | expectedSlice := reflect.ValueOf(expected) |
| 1514 | actualSlice := reflect.ValueOf(actual) |
| 1515 | |
| 1516 | if expectedSlice.Type().Kind() != reflect.Slice { |
| 1517 | return Fail(t, "Expected value must be slice", msgAndArgs...) |
| 1518 | } |
| 1519 | |
| 1520 | expectedLen := expectedSlice.Len() |
| 1521 | if !IsType(t, expected, actual) || !Len(t, actual, expectedLen) { |
| 1522 | return false |
| 1523 | } |
| 1524 | |
| 1525 | for i := 0; i < expectedLen; i++ { |
| 1526 | if !InEpsilon(t, expectedSlice.Index(i).Interface(), actualSlice.Index(i).Interface(), epsilon, "at index %d", i) { |
| 1527 | return false |
| 1528 | } |
| 1529 | } |
| 1530 | |
| 1531 | return true |
| 1532 | } |
| 1533 | |
| 1534 | /* |
| 1535 | Errors |
searching dependent graphs…