Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue #1662 (comparing infs should fail) #1663

Merged
merged 2 commits into from
Oct 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions assert/assertions.go
Original file line number Diff line number Diff line change
Expand Up @@ -1527,6 +1527,9 @@ func InEpsilon(t TestingT, expected, actual interface{}, epsilon float64, msgAnd
if err != nil {
return Fail(t, err.Error(), msgAndArgs...)
}
if math.IsNaN(actualEpsilon) {
return Fail(t, "relative error is NaN", msgAndArgs...)
}
if actualEpsilon > epsilon {
return Fail(t, fmt.Sprintf("Relative error is too high: %#v (expected)\n"+
" < %#v (actual)", epsilon, actualEpsilon), msgAndArgs...)
Expand Down
8 changes: 8 additions & 0 deletions assert/assertions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1986,6 +1986,14 @@ func TestInEpsilon(t *testing.T) {
{math.NaN(), 0, 1},
{0, math.NaN(), 1},
{0, 0, math.NaN()},
{math.Inf(1), 1, 1},
{math.Inf(-1), 1, 1},
{1, math.Inf(1), 1},
{1, math.Inf(-1), 1},
{math.Inf(1), math.Inf(1), 1},
{math.Inf(1), math.Inf(-1), 1},
{math.Inf(-1), math.Inf(1), 1},
{math.Inf(-1), math.Inf(-1), 1},
}

for _, tc := range cases {
Expand Down