From 6555fd4da6911f1a3a0e751fbe4fd61c22e809d5 Mon Sep 17 00:00:00 2001 From: Yaroslav Brustinov Date: Wed, 16 Oct 2024 17:25:23 +0300 Subject: [PATCH] Fix issue #1662 (comparing infs should fail) --- assert/assertions.go | 3 +++ assert/assertions_test.go | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/assert/assertions.go b/assert/assertions.go index 44b854da6..d4b4befcb 100644 --- a/assert/assertions.go +++ b/assert/assertions.go @@ -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...) diff --git a/assert/assertions_test.go b/assert/assertions_test.go index e158688f2..848a5d8a5 100644 --- a/assert/assertions_test.go +++ b/assert/assertions_test.go @@ -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 {