InEpsilonSlice is the same as InEpsilon, except it compares each value from two slices.
(t TestingT, expected, actual interface{}, epsilon float64, msgAndArgs ...interface{})
| 1539 | |
| 1540 | // InEpsilonSlice is the same as InEpsilon, except it compares each value from two slices. |
| 1541 | func InEpsilonSlice(t TestingT, expected, actual interface{}, epsilon float64, msgAndArgs ...interface{}) bool { |
| 1542 | if h, ok := t.(tHelper); ok { |
| 1543 | h.Helper() |
| 1544 | } |
| 1545 | |
| 1546 | if expected == nil || actual == nil { |
| 1547 | return Fail(t, "Parameters must be slice", msgAndArgs...) |
| 1548 | } |
| 1549 | |
| 1550 | expectedSlice := reflect.ValueOf(expected) |
| 1551 | actualSlice := reflect.ValueOf(actual) |
| 1552 | |
| 1553 | if expectedSlice.Type().Kind() != reflect.Slice { |
| 1554 | return Fail(t, "Expected value must be slice", msgAndArgs...) |
| 1555 | } |
| 1556 | |
| 1557 | expectedLen := expectedSlice.Len() |
| 1558 | if !IsType(t, expected, actual) || !Len(t, actual, expectedLen) { |
| 1559 | return false |
| 1560 | } |
| 1561 | |
| 1562 | for i := 0; i < expectedLen; i++ { |
| 1563 | if !InEpsilon(t, expectedSlice.Index(i).Interface(), actualSlice.Index(i).Interface(), epsilon, "at index %d", i) { |
| 1564 | return false |
| 1565 | } |
| 1566 | } |
| 1567 | |
| 1568 | return true |
| 1569 | } |
| 1570 | |
| 1571 | /* |
| 1572 | Errors |