diff --git a/assert/assertions.go b/assert/assertions.go index 44b854d..d4b4bef 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 e158688..848a5d8 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 {