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

Deprecate @test_approx_eq (part of #4615) #19880

Merged
merged 2 commits into from
Jan 6, 2017
Merged

Deprecate @test_approx_eq (part of #4615) #19880

merged 2 commits into from
Jan 6, 2017

Conversation

StefanKarpinski
Copy link
Member

@test_approx_eq_eps, you're next!

`@test_approx_eq_eps`, you're next!
@StefanKarpinski StefanKarpinski added this to the 0.6.0 milestone Jan 5, 2017
@KristofferC
Copy link
Member

Is there a non unicode way to do this?

@ararslan
Copy link
Member

ararslan commented Jan 5, 2017

@test isapprox(x, y)

@cstjean
Copy link
Contributor

cstjean commented Jan 5, 2017

They're not 100% equivalent yet, though. isapprox isn't informative (on 0.5)

julia> @test_approx_eq 2.1 1+1
ERROR: assertion failed: |2.1 - 1 + 1| <= 4.440892098500626e-12
  2.1 = 2.1
  1 + 1 = 2
  difference = 0.10000000000000009 > 4.440892098500626e-12
 in test_approx_eq(::Float64, ::Int64, ::Float64, ::String, ::String) at ./test.jl:863
 in test_approx_eq(::Float64, ::Int64, ::String, ::String) at ./test.jl:873

julia> @test isapprox(2.1, 1+1)
Test Failed
  Expression: isapprox(2.1,1 + 1)
ERROR: There was an error during testing
 in record(::Base.Test.FallbackTestSet, ::Base.Test.Fail) at ./test.jl:397
 in do_test(::Base.Test.Returned, ::Expr) at ./test.jl:281

julia> @test 2.1  1+1
Test Failed
  Expression: 2.1  1 + 1
   Evaluated: 2.1 isapprox 2
ERROR: There was an error during testing
 in record(::Base.Test.FallbackTestSet, ::Base.Test.Fail) at ./test.jl:397
 in do_test(::Base.Test.Returned, ::Expr) at ./test.jl:281

:(test_approx_eq($(esc(a)), $(esc(b)), $(string(a)), $(string(b))))
end
export @test_approx_eq
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we do this with an eval into the Base.Test module from deprecated.jl so it's in a place where we know we'll be deleting it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eh, I'd rather just leave it here until we tear out the rest of this stuff.

@ararslan
Copy link
Member

ararslan commented Jan 5, 2017

Fair point, @cstjean. We could check in @test whether the expression is a call to isapprox, but having to perform that check every time might make things slow and/or be overkill.

@kshyatt kshyatt added the testsystem The unit testing framework and Test stdlib label Jan 5, 2017
@StefanKarpinski
Copy link
Member Author

We display lots of test conditions specially, so that could certainly be arranged for isapprox tests.


As calculations on floating-point values can be imprecise, you can perform approximate equality
checks using either `@test a ≈ b` (where ``, typed via tab completion of `\approx`, is the
[`isapprox()`](@ref) function) or use [`isapprox()`](@ref) directly.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This first paragraph seems fine to leave in. Same with the examples that use isapprox, and the ```@docs line for @inferred

in expression: 1 ≈ 0.999999
in error at error.jl:21
in default_handler at test.jl:30
in do_test at test.jl:53
Copy link
Contributor

@tkelman tkelman Jan 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these 2 were worth keeping (though should be made into doctests if possible)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you open an issue for it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

about to get on a plane (aren't you, too?), I have a commit on a misc branch locally to put these back, can go into a PR next time I rearrange branches

@giordano
Copy link
Contributor

giordano commented Jan 7, 2017

@test_approx_eq actually had a nice feature: @test_approx_eq NaN NaN didn't give an error. I know there exists isnan, yet that feature was useful when comparing arrays made by a mixture of finite and NaN elements. When doing tests, it makes sense to treat NaNs as equal to each other.

@StefanKarpinski
Copy link
Member Author

I think I'd prefer to have that as a feature of isapprox than keep this weird extra testing API around.

@giordano
Copy link
Contributor

giordano commented Jan 8, 2017

I just wanted to point out a difference between @test_approx_eq and isapprox, not suggest to bring back the former ;-)

I was testing a custom type and in test/runtests.jl I defined a method for isapprox replacing == with isequal, so I found a solution for my use case and have no problem. I'm going to open an ticket to see if other people are interested in this feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
testsystem The unit testing framework and Test stdlib
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants