Skip to content

Commit 6555fd4

Browse files
committed
Fix issue #1662 (comparing infs should fail)
1 parent a012e45 commit 6555fd4

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

assert/assertions.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1527,6 +1527,9 @@ func InEpsilon(t TestingT, expected, actual interface{}, epsilon float64, msgAnd
15271527
if err != nil {
15281528
return Fail(t, err.Error(), msgAndArgs...)
15291529
}
1530+
if math.IsNaN(actualEpsilon) {
1531+
return Fail(t, "relative error is NaN", msgAndArgs...)
1532+
}
15301533
if actualEpsilon > epsilon {
15311534
return Fail(t, fmt.Sprintf("Relative error is too high: %#v (expected)\n"+
15321535
" < %#v (actual)", epsilon, actualEpsilon), msgAndArgs...)

assert/assertions_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1986,6 +1986,14 @@ func TestInEpsilon(t *testing.T) {
19861986
{math.NaN(), 0, 1},
19871987
{0, math.NaN(), 1},
19881988
{0, 0, math.NaN()},
1989+
{math.Inf(1), 1, 1},
1990+
{math.Inf(-1), 1, 1},
1991+
{1, math.Inf(1), 1},
1992+
{1, math.Inf(-1), 1},
1993+
{math.Inf(1), math.Inf(1), 1},
1994+
{math.Inf(1), math.Inf(-1), 1},
1995+
{math.Inf(-1), math.Inf(1), 1},
1996+
{math.Inf(-1), math.Inf(-1), 1},
19891997
}
19901998

19911999
for _, tc := range cases {

0 commit comments

Comments
 (0)