Merge pull request #1663 from ybrustin/master

Fix issue #1662 (comparing infs should fail)
pull/1664/head^2
Bracken 2024-10-26 19:43:05 +01:00 committed by GitHub
commit a1b9c9efe3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 0 deletions

View File

@ -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...)

View File

@ -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 {