Skip to content

Commit a1b9c9e

Browse files
authoredOct 26, 2024
Merge pull request #1663 from ybrustin/master
Fix issue #1662 (comparing infs should fail)
2 parents 89352f7 + 8302de9 commit a1b9c9e

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed
 

‎assert/assertions.go

+3
Original file line numberDiff line numberDiff line change
@@ -1512,6 +1512,9 @@ func InEpsilon(t TestingT, expected, actual interface{}, epsilon float64, msgAnd
15121512
if err != nil {
15131513
return Fail(t, err.Error(), msgAndArgs...)
15141514
}
1515+
if math.IsNaN(actualEpsilon) {
1516+
return Fail(t, "relative error is NaN", msgAndArgs...)
1517+
}
15151518
if actualEpsilon > epsilon {
15161519
return Fail(t, fmt.Sprintf("Relative error is too high: %#v (expected)\n"+
15171520
" < %#v (actual)", epsilon, actualEpsilon), msgAndArgs...)

‎assert/assertions_test.go

+8
Original file line numberDiff line numberDiff line change
@@ -2036,6 +2036,14 @@ func TestInEpsilon(t *testing.T) {
20362036
{math.NaN(), 0, 1},
20372037
{0, math.NaN(), 1},
20382038
{0, 0, math.NaN()},
2039+
{math.Inf(1), 1, 1},
2040+
{math.Inf(-1), 1, 1},
2041+
{1, math.Inf(1), 1},
2042+
{1, math.Inf(-1), 1},
2043+
{math.Inf(1), math.Inf(1), 1},
2044+
{math.Inf(1), math.Inf(-1), 1},
2045+
{math.Inf(-1), math.Inf(1), 1},
2046+
{math.Inf(-1), math.Inf(-1), 1},
20392047
}
20402048

20412049
for _, tc := range cases {

0 commit comments

Comments
 (0)