Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion assert/assertions.go
Original file line number Diff line number Diff line change
Expand Up @@ -1619,7 +1619,11 @@ func InEpsilonSlice(t TestingT, expected, actual interface{}, epsilon float64, m
}

for i := 0; i < expectedLen; i++ {
if !InEpsilon(t, expectedSlice.Index(i).Interface(), actualSlice.Index(i).Interface(), epsilon, "at index %d", i) {
message := fmt.Sprintf("at index %d", i)
if len(msgAndArgs) > 0 {
message += ": " + messageFromMsgAndArgs(msgAndArgs...)
}
if !InEpsilon(t, expectedSlice.Index(i).Interface(), actualSlice.Index(i).Interface(), epsilon, message) {
return false
}
}
Expand Down
33 changes: 33 additions & 0 deletions assert/assertions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2516,6 +2516,39 @@ func TestInEpsilonSlice(t *testing.T) {
False(t, InEpsilonSlice(mockT, "", nil, 1), "Expected non numeral slices to fail")
}

func TestInEpsilonSliceMessage(t *testing.T) {
t.Parallel()

mockT := new(bufferT)
False(t, InEpsilonSlice(mockT,
[]float64{2.1, 2.0},
[]float64{2.1, 2.1},
0.04,
"ctx %d", 7,
))
Regexp(t, regexp.MustCompile(
`^\tassertions.go:\d+: \n\t+Error Trace:\t\n\t+Error:\s+Relative error is too high: 0.04 \(expected\)\n\s+< 0.050000000000000044 \(actual\)\n\s+Messages:\s+at index 1: ctx 7\n$`,
), mockT.buf.String())

mockT = new(bufferT)
False(t, InEpsilonSlice(mockT,
[]float64{2.1, 2.0},
[]float64{2.1, 2.1},
0.04,
))
Regexp(t, regexp.MustCompile(
`^\tassertions.go:\d+: \n\t+Error Trace:\t\n\t+Error:\s+Relative error is too high: 0.04 \(expected\)\n\s+< 0.050000000000000044 \(actual\)\n\s+Messages:\s+at index 1\n$`,
), mockT.buf.String())

mockT = new(bufferT)
True(t, InEpsilonSlice(mockT,
[]float64{2.1, 2.0},
[]float64{2.1, 2.0},
0.04,
))
Empty(t, mockT.buf.String())
}

func TestRegexp(t *testing.T) {
t.Parallel()

Expand Down