-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Description
@test_approx_eq has been deprecated by #19880, now the suggested way to compare numbers is @test isapprox(a ,b) (or some other fancy Unicode syntax). However, @test_approx_eq had a feature that isapprox is missing: @test_approx_eq NaN NaN didn't error. When performing tests, it makes sense to treat NaNs as equal (i.e., what isequal does): even if isnan is available, having isapprox dealing nicely with NaNs may be useful for cases like isapprox([1, NaN, Inf], [1, NaN, Inf]), where there is a mixture of numbers and not-numbers.
My suggestion: optionally have isapprox treat NaN values as equal to each other (maybe only in tests).
A bit of background: in a package of mines I have a test where I was using @test_approx_eq, relying on the fact that it treated NaNs as equal. When I moved to @test + isapprox I had to define a new method for a custom type in the testing suite and now I'm fine. With this ticket my aim is not to advocate for this feature, because I currently don't need it, but to suggest a possible improvement to isapprox that may be useful above all for testing.