stretchr / testify

A toolkit with common assertions and mocks that plays nicely with the standard library
MIT License
23.55k stars 1.6k forks source link

InEpsilon has inconsistent results with expected or actual values of Inf #1662

Closed brackendawson closed 1 month ago

brackendawson commented 1 month ago
func TestInEpsilon1(t *testing.T) {
    div := 0.0
    require.InEpsilon(t, 1, 1/div, 0.001)
}

func TestInEpsilon2(t *testing.T) {
    div := 0.0
    require.InEpsilon(t, 1/div, 1, 0.001)
}
> go test -v -run InEps | grep -E '(PASS|FAIL)'
--- FAIL: TestInEpsilon1 (0.00s)
--- PASS: TestInEpsilon2 (0.00s)

Originally posted by @ybrustin-te in https://github.com/stretchr/testify/issues/918#issuecomment-2416889992

Given the difference between two Inf values cannot be determined, those assertions should both fail.