Skip to content

Commit

Permalink
Merge pull request #1663 from ybrustin/master
Browse files Browse the repository at this point in the history
Fix issue #1662 (comparing infs should fail)
  • Loading branch information
brackendawson authored Oct 26, 2024
2 parents 89352f7 + 8302de9 commit a1b9c9e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions assert/assertions.go
Original file line number Diff line number Diff line change
Expand Up @@ -1512,6 +1512,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 @@ -2036,6 +2036,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

0 comments on commit a1b9c9e

Please sign in to comment.