Skip to content

Commit

Permalink
Deprecate @test_approx_eq (part of #4615) (#19880)
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanKarpinski authored Jan 6, 2017
1 parent a861aaf commit 5d90ab6
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 57 deletions.
9 changes: 6 additions & 3 deletions base/test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module Test
export @test, @test_throws, @test_broken, @test_skip
export @testset
# Legacy approximate testing functions, yet to be included
export @test_approx_eq, @test_approx_eq_eps, @inferred
export @test_approx_eq_eps, @inferred
export detect_ambiguities
export GenericString

Expand Down Expand Up @@ -952,12 +952,15 @@ end
"""
@test_approx_eq(a, b)
Test two floating point numbers `a` and `b` for equality taking into account
small numerical errors.
Deprecated. Test two floating point numbers `a` and `b` for equality taking into
account small numerical errors.
"""
macro test_approx_eq(a, b)
Base.depwarn(string("@test_approx_eq is deprecated, use `@test ", a, "", b, "` instead"),
Symbol("@test_approx_eq"))
:(test_approx_eq($(esc(a)), $(esc(b)), $(string(a)), $(string(b))))
end
export @test_approx_eq

_args_and_call(args...; kwargs...) = (args[1:end-1], kwargs, args[end](args[1:end-1]...; kwargs...))
"""
Expand Down
39 changes: 0 additions & 39 deletions doc/src/stdlib/test.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,46 +169,7 @@ As calculations on floating-point values can be imprecise, you can perform appro
checks using either `@test a ≈ b` (where ``, typed via tab completion of `\approx`, is the
[`isapprox()`](@ref) function) or use [`isapprox()`](@ref) directly.

An alternative is the `@test_approx_eq` macro (which differs from [`isapprox`](@ref) in that it treats
`NaN` values as equal and has a smaller default tolerance) or `@test_approx_eq_eps` (which takes
an extra argument indicating the relative tolerance):

```julia
julia> @test 1 0.999999999

julia> @test 1 0.999999
ERROR: test failed: 1 isapprox 0.999999
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

julia> @test_approx_eq 1. 0.999999999
ERROR: assertion failed: |1.0 - 0.999999999| < 2.220446049250313e-12
1.0 = 1.0
0.999999999 = 0.999999999
in test_approx_eq at test.jl:75
in test_approx_eq at test.jl:80

julia> @test_approx_eq 1. 0.9999999999999

julia> @test_approx_eq_eps 1. 0.999 1e-2

julia> @test_approx_eq_eps 1. 0.999 1e-3
ERROR: assertion failed: |1.0 - 0.999| <= 0.001
1.0 = 1.0
0.999 = 0.999
difference = 0.0010000000000000009 > 0.001
in error at error.jl:22
in test_approx_eq at test.jl:68
```

Note that these macros will fail immediately, and are not compatible with `@testset()`, so using
`@test isapprox` is encouraged when writing new tests.

```@docs
Base.Test.@test_approx_eq
Base.Test.@test_approx_eq_eps
Base.Test.@inferred
```

Expand Down
4 changes: 2 additions & 2 deletions test/linalg/bunchkaufman.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ bimg = randn(n,2)/2
@testset "Bunch-Kaufman factors of a pos-def matrix" begin
@testset for rook in (false, true)
bc2 = bkfact(apd, :U, issymmetric(apd), rook)
@test_approx_eq logdet(bc2) log(det(bc2))
@test_approx_eq logabsdet(bc2)[1] log(abs(det(bc2)))
@test logdet(bc2) log(det(bc2))
@test logabsdet(bc2)[1] log(abs(det(bc2)))
@test logabsdet(bc2)[2] == sign(det(bc2))
@test inv(bc2)*apd eye(n)
@test_approx_eq_eps apd * (bc2\b) b 150000ε
Expand Down
26 changes: 13 additions & 13 deletions test/offsetarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -267,11 +267,11 @@ am = map(identity, a)

# other functions
v = OffsetArray(v0, (-3,))
@test_approx_eq v v
@test v v
@test parent(v') == v0'
@test indices(v') === (1:1,-2:1)
A = OffsetArray(rand(4,4), (-3,5))
@test_approx_eq A A
@test A A
@test maximum(A) == maximum(parent(A))
@test minimum(A) == minimum(parent(A))
@test extrema(A) == extrema(parent(A))
Expand Down Expand Up @@ -321,9 +321,9 @@ I,J,N = findnz(z)
@test std(A_3_3, 2) == OffsetArray([3,3,3]'', (A_3_3.offsets[1],0))
@test sum(OffsetArray(ones(Int,3000), -1000)) == 3000

@test_approx_eq vecnorm(v) vecnorm(parent(v))
@test_approx_eq vecnorm(A) vecnorm(parent(A))
@test_approx_eq vecdot(v, v) vecdot(v0, v0)
@test vecnorm(v) vecnorm(parent(v))
@test vecnorm(A) vecnorm(parent(A))
@test vecdot(v, v) vecdot(v0, v0)

v = OffsetArray([1,1e100,1,-1e100], (-3,))*1000
v2 = OffsetArray([1,-1e100,1,1e100], (5,))*1000
Expand Down Expand Up @@ -384,14 +384,14 @@ for s = -5:5
for i = 1:5
thisa = OffsetArray(a[i], (s,))
thisc = c[mod1(i+s+5,5)]
@test_approx_eq fft(thisa) thisc
@test_approx_eq fft(thisa, 1) thisc
@test_approx_eq ifft(fft(thisa)) circcopy!(a1, thisa)
@test_approx_eq ifft(fft(thisa, 1), 1) circcopy!(a1, thisa)
@test_approx_eq rfft(thisa) thisc[1:3]
@test_approx_eq rfft(thisa, 1) thisc[1:3]
@test_approx_eq irfft(rfft(thisa, 1), 5, 1) a1
@test_approx_eq irfft(rfft(thisa, 1), 5, 1) a1
@test fft(thisa) thisc
@test fft(thisa, 1) thisc
@test ifft(fft(thisa)) circcopy!(a1, thisa)
@test ifft(fft(thisa, 1), 1) circcopy!(a1, thisa)
@test rfft(thisa) thisc[1:3]
@test rfft(thisa, 1) thisc[1:3]
@test irfft(rfft(thisa, 1), 5, 1) a1
@test irfft(rfft(thisa, 1), 5, 1) a1
end
end

Expand Down

3 comments on commit 5d90ab6

@vchuravy
Copy link
Member

Choose a reason for hiding this comment

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

@nanosoldier runbenchmarks("nullablearray", vs = "@c38a5a3044ffd62c585225a201422f95fd18f6dc")

@jrevels
Copy link
Member

@jrevels jrevels commented on 5d90ab6 Jan 6, 2017

Choose a reason for hiding this comment

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

I was in the process of restarting Nanosoldier with an updated JLD when this was submitted, sorry.

Retriggering:

@nanosoldier runbenchmarks("nullablearray", vs = "@c38a5a3044ffd62c585225a201422f95fd18f6dc")

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

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

Your benchmark job has completed - no performance regressions were detected. A full report can be found here. cc @jrevels

Please sign in to comment.