Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@test isapprox doesn't fail as expected #31

Closed
nirinA opened this issue May 14, 2017 · 5 comments
Closed

@test isapprox doesn't fail as expected #31

nirinA opened this issue May 14, 2017 · 5 comments

Comments

@nirinA
Copy link
Contributor

nirinA commented May 14, 2017

some constants have their values changed in the last SOFA release, and will be updated with the future liberfa release:

https://github.com/nirinA/ERFA.jl/blob/IAU2012/src/erfa_common.jl

running the current runtests.jl, it doesn't fail as it should do. for instance:

julia> @test_approx_eq_eps(4.289638913597693e-5, 4.28963889781338e-5,  1.0e-16)
WARNING: @test_approx_eq_eps is deprecated, use `@test 4.289638913597693e-5 ≈ 4.28963889781338e-5 atol=1.0e-16` instead
Stacktrace:
 [1] depwarn(::String, ::Symbol) at ./deprecated.jl:64
 [2] @test_approx_eq_eps(::ANY, ::ANY, ::ANY) at ./deprecated.jl:1031
 [3] eval(::Module, ::Any) at ./boot.jl:235
 [4] eval_user_input(::Any, ::Base.REPL.REPLBackend) at ./REPL.jl:66
 [5] macro expansion at ./REPL.jl:97 [inlined]
 [6] (::Base.REPL.##1#2{Base.REPL.REPLBackend})() at ./event.jl:73
while loading no file, in expression starting on line 0
ERROR: assertion failed: |4.289638913597693e-5 - 4.28963889781338e-5| <= 1.0e-16
  4.289638913597693e-5 = 4.289638913597693e-5
  4.28963889781338e-5 = 4.28963889781338e-5
  difference = 1.578431328241696e-13 > 1.0e-16

whereas:

julia> @test isapprox(4.289638913597693e-5, 4.28963889781338e-5, atol=1e-16)
Test Passed
@giordano
Copy link
Member

giordano commented May 14, 2017

isapprox tests the following:

abs(x-y) <= atol + rtol*max(abs(x), abs(y)))

Setting rtol to 0 should do the trick:

julia> @test isapprox(4.289638913597693e-5, 4.28963889781338e-5, atol=1e-16, rtol=0)
Test Failed
  Expression: isapprox(4.289638913597693e-5, 4.28963889781338e-5, atol=1.0e-16, rtol=0)
ERROR: There was an error during testing

Note that @test_approx_eq_eps has been deprecated in Julia 0.6, so it should be replaced anyway

@nirinA
Copy link
Contributor Author

nirinA commented May 14, 2017

yes, that needs this rtol=0 keyword argument. i would like it to be more verbose as @test_approx_eq_eps though.

@giordano
Copy link
Member

giordano commented May 14, 2017

An alternative is to set only rtol = 1e-11, without touching atol.

@nirinA
Copy link
Contributor Author

nirinA commented May 15, 2017

hmm, i'll stick with comparing the difference and atol. i'm confused with other value of rtol! need to see this more in detail.
thanks for the tips anyway.

@nirinA nirinA closed this as completed May 19, 2017
@giordano
Copy link
Member

The new syntax for isapprox proposed in JuliaLang/julia#22742 should do what you want: with atol > 0 there will be no need to explicitly set rtol=0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants