Skip to content

Commit cf558d7

Browse files
Deprecate @test_approx_eq (part of #4615)
`@test_approx_eq_eps`, you're next!
1 parent 1f59fbf commit cf558d7

File tree

4 files changed

+21
-67
lines changed

4 files changed

+21
-67
lines changed

base/test.jl

+6-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module Test
1616
export @test, @test_throws, @test_broken, @test_skip
1717
export @testset
1818
# Legacy approximate testing functions, yet to be included
19-
export @test_approx_eq, @test_approx_eq_eps, @inferred
19+
export @test_approx_eq_eps, @inferred
2020
export detect_ambiguities
2121
export GenericString
2222

@@ -952,12 +952,15 @@ end
952952
"""
953953
@test_approx_eq(a, b)
954954
955-
Test two floating point numbers `a` and `b` for equality taking into account
956-
small numerical errors.
955+
Deprecated. Test two floating point numbers `a` and `b` for equality taking into
956+
account small numerical errors.
957957
"""
958958
macro test_approx_eq(a, b)
959+
Base.depwarn(string("@test_approx_eq is deprecated, use `@test ", a, "", b, "` instead"),
960+
Symbol("@test_approx_eq"))
959961
:(test_approx_eq($(esc(a)), $(esc(b)), $(string(a)), $(string(b))))
960962
end
963+
export @test_approx_eq
961964

962965
_args_and_call(args...; kwargs...) = (args[1:end-1], kwargs, args[end](args[1:end-1]...; kwargs...))
963966
"""

doc/src/stdlib/test.md

-49
Original file line numberDiff line numberDiff line change
@@ -163,55 +163,6 @@ ERROR: Some tests did not pass: 3 passed, 1 failed, 0 errored, 0 broken.
163163
in finish at test.jl:362
164164
```
165165

166-
## Other Test Macros
167-
168-
As calculations on floating-point values can be imprecise, you can perform approximate equality
169-
checks using either `@test a ≈ b` (where ``, typed via tab completion of `\approx`, is the
170-
[`isapprox()`](@ref) function) or use [`isapprox()`](@ref) directly.
171-
172-
An alternative is the `@test_approx_eq` macro (which differs from [`isapprox`](@ref) in that it treats
173-
`NaN` values as equal and has a smaller default tolerance) or `@test_approx_eq_eps` (which takes
174-
an extra argument indicating the relative tolerance):
175-
176-
```julia
177-
julia> @test 1 0.999999999
178-
179-
julia> @test 1 0.999999
180-
ERROR: test failed: 1 isapprox 0.999999
181-
in expression: 1 0.999999
182-
in error at error.jl:21
183-
in default_handler at test.jl:30
184-
in do_test at test.jl:53
185-
186-
julia> @test_approx_eq 1. 0.999999999
187-
ERROR: assertion failed: |1.0 - 0.999999999| < 2.220446049250313e-12
188-
1.0 = 1.0
189-
0.999999999 = 0.999999999
190-
in test_approx_eq at test.jl:75
191-
in test_approx_eq at test.jl:80
192-
193-
julia> @test_approx_eq 1. 0.9999999999999
194-
195-
julia> @test_approx_eq_eps 1. 0.999 1e-2
196-
197-
julia> @test_approx_eq_eps 1. 0.999 1e-3
198-
ERROR: assertion failed: |1.0 - 0.999| <= 0.001
199-
1.0 = 1.0
200-
0.999 = 0.999
201-
difference = 0.0010000000000000009 > 0.001
202-
in error at error.jl:22
203-
in test_approx_eq at test.jl:68
204-
```
205-
206-
Note that these macros will fail immediately, and are not compatible with `@testset()`, so using
207-
`@test isapprox` is encouraged when writing new tests.
208-
209-
```@docs
210-
Base.Test.@test_approx_eq
211-
Base.Test.@test_approx_eq_eps
212-
Base.Test.@inferred
213-
```
214-
215166
## Broken Tests
216167

217168
If a test fails consistently it can be changed to use the `@test_broken()` macro. This will denote

test/linalg/bunchkaufman.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ bimg = randn(n,2)/2
7272
@testset "Bunch-Kaufman factors of a pos-def matrix" begin
7373
@testset for rook in (false, true)
7474
bc2 = bkfact(apd, :U, issymmetric(apd), rook)
75-
@test_approx_eq logdet(bc2) log(det(bc2))
76-
@test_approx_eq logabsdet(bc2)[1] log(abs(det(bc2)))
75+
@test logdet(bc2) log(det(bc2))
76+
@test logabsdet(bc2)[1] log(abs(det(bc2)))
7777
@test logabsdet(bc2)[2] == sign(det(bc2))
7878
@test inv(bc2)*apd eye(n)
7979
@test_approx_eq_eps apd * (bc2\b) b 150000ε

test/offsetarray.jl

+13-13
Original file line numberDiff line numberDiff line change
@@ -267,11 +267,11 @@ am = map(identity, a)
267267

268268
# other functions
269269
v = OffsetArray(v0, (-3,))
270-
@test_approx_eq v v
270+
@test v v
271271
@test parent(v') == v0'
272272
@test indices(v') === (1:1,-2:1)
273273
A = OffsetArray(rand(4,4), (-3,5))
274-
@test_approx_eq A A
274+
@test A A
275275
@test maximum(A) == maximum(parent(A))
276276
@test minimum(A) == minimum(parent(A))
277277
@test extrema(A) == extrema(parent(A))
@@ -321,9 +321,9 @@ I,J,N = findnz(z)
321321
@test std(A_3_3, 2) == OffsetArray([3,3,3]'', (A_3_3.offsets[1],0))
322322
@test sum(OffsetArray(ones(Int,3000), -1000)) == 3000
323323

324-
@test_approx_eq vecnorm(v) vecnorm(parent(v))
325-
@test_approx_eq vecnorm(A) vecnorm(parent(A))
326-
@test_approx_eq vecdot(v, v) vecdot(v0, v0)
324+
@test vecnorm(v) vecnorm(parent(v))
325+
@test vecnorm(A) vecnorm(parent(A))
326+
@test vecdot(v, v) vecdot(v0, v0)
327327

328328
v = OffsetArray([1,1e100,1,-1e100], (-3,))*1000
329329
v2 = OffsetArray([1,-1e100,1,1e100], (5,))*1000
@@ -384,14 +384,14 @@ for s = -5:5
384384
for i = 1:5
385385
thisa = OffsetArray(a[i], (s,))
386386
thisc = c[mod1(i+s+5,5)]
387-
@test_approx_eq fft(thisa) thisc
388-
@test_approx_eq fft(thisa, 1) thisc
389-
@test_approx_eq ifft(fft(thisa)) circcopy!(a1, thisa)
390-
@test_approx_eq ifft(fft(thisa, 1), 1) circcopy!(a1, thisa)
391-
@test_approx_eq rfft(thisa) thisc[1:3]
392-
@test_approx_eq rfft(thisa, 1) thisc[1:3]
393-
@test_approx_eq irfft(rfft(thisa, 1), 5, 1) a1
394-
@test_approx_eq irfft(rfft(thisa, 1), 5, 1) a1
387+
@test fft(thisa) thisc
388+
@test fft(thisa, 1) thisc
389+
@test ifft(fft(thisa)) circcopy!(a1, thisa)
390+
@test ifft(fft(thisa, 1), 1) circcopy!(a1, thisa)
391+
@test rfft(thisa) thisc[1:3]
392+
@test rfft(thisa, 1) thisc[1:3]
393+
@test irfft(rfft(thisa, 1), 5, 1) a1
394+
@test irfft(rfft(thisa, 1), 5, 1) a1
395395
end
396396
end
397397

0 commit comments

Comments
 (0)