Skip to content

Commit a0847cd

Browse files
committed
tests: convert println() into @testset
reduces the amount of noise in the output
1 parent 21043fb commit a0847cd

File tree

6 files changed

+47
-40
lines changed

6 files changed

+47
-40
lines changed

test/DerivativeTest.jl

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ Random.seed!(1)
1717

1818
const x = 1
1919

20-
for f in DiffTests.NUMBER_TO_NUMBER_FUNCS
21-
println(" ...testing $f")
20+
@testset "Derivative test vs Calculus.jl" begin
21+
22+
@testset "$f" for f in DiffTests.NUMBER_TO_NUMBER_FUNCS
2223
v = f(x)
2324
d = ForwardDiff.derivative(f, x)
2425
@test isapprox(d, Calculus.derivative(f, x), atol=FINITEDIFF_ERROR)
@@ -29,8 +30,7 @@ for f in DiffTests.NUMBER_TO_NUMBER_FUNCS
2930
@test isapprox(DiffResults.derivative(out), d)
3031
end
3132

32-
for f in DiffTests.NUMBER_TO_ARRAY_FUNCS
33-
println(" ...testing $f")
33+
@testset "$f" for f in DiffTests.NUMBER_TO_ARRAY_FUNCS
3434
v = f(x)
3535
d = ForwardDiff.derivative(f, x)
3636

@@ -47,8 +47,7 @@ for f in DiffTests.NUMBER_TO_ARRAY_FUNCS
4747
@test isapprox(DiffResults.derivative(out), d)
4848
end
4949

50-
for f! in DiffTests.INPLACE_NUMBER_TO_ARRAY_FUNCS
51-
println(" ...testing $f!")
50+
@testset "$f!" for f! in DiffTests.INPLACE_NUMBER_TO_ARRAY_FUNCS
5251
m, n = 3, 2
5352
y = fill(0.0, m, n)
5453
f = x -> (tmp = similar(y, promote_type(eltype(y), typeof(x)), m, n); f!(tmp, x); tmp)
@@ -89,6 +88,8 @@ for f! in DiffTests.INPLACE_NUMBER_TO_ARRAY_FUNCS
8988
@test isapprox(DiffResults.derivative(out), d)
9089
end
9190

91+
end
92+
9293
@testset "exponential function at base zero" begin
9394
@test (x -> ForwardDiff.derivative(y -> x^y, -0.5))(0.0) === -Inf
9495
@test (x -> ForwardDiff.derivative(y -> x^y, 0.0))(0.0) === -Inf

test/DualTest.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ ForwardDiff.:≺(::Type{TestTag}, ::Type{OuterTestTag}) = true
3131
ForwardDiff.:(::Type{OuterTestTag}, ::Type{TestTag}) = false
3232

3333
@testset "Dual{Z,$V,$N} and Dual{Z,Dual{Z,$V,$M},$N}" for N in (0,3), M in (0,4), V in (Int, Float32)
34-
println(" ...testing Dual{TestTag(),$V,$N} and Dual{TestTag(),Dual{TestTag(),$V,$M},$N}")
3534

3635
PARTIALS = Partials{N,V}(ntuple(n -> intrand(V), N))
3736
PRIMAL = intrand(V)
@@ -466,13 +465,12 @@ ForwardDiff.:≺(::Type{OuterTestTag}, ::Type{TestTag}) = false
466465
@test abs(NESTED_FDNUM) === NESTED_FDNUM
467466

468467
if V != Int
469-
@testset "$f" for (M, f, arity) in DiffRules.diffrules(filter_modules = nothing)
468+
@testset "auto-testing $(M).$(f) with $arity arguments" for (M, f, arity) in DiffRules.diffrules(filter_modules = nothing)
470469
if f in (:/, :rem2pi)
471470
continue # Skip these rules
472471
elseif !(isdefined(@__MODULE__, M) && isdefined(getfield(@__MODULE__, M), f))
473472
continue # Skip rules for methods not defined in the current scope
474473
end
475-
println(" ...auto-testing $(M).$(f) with $arity arguments")
476474
if arity == 1
477475
deriv = DiffRules.diffrule(M, f, :x)
478476
modifier = if in(f, (:asec, :acsc, :asecd, :acscd, :acosh, :acoth))

test/GradientTest.jl

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@ include(joinpath(dirname(@__FILE__), "utils.jl"))
1515
# hardcoded test #
1616
##################
1717

18+
@testset "hardcoded tests" begin
19+
1820
f = DiffTests.rosenbrock_1
1921
x = [0.1, 0.2, 0.3]
2022
v = f(x)
2123
g = [-9.4, 15.6, 52.0]
2224

2325
@testset "Rosenbrock, chunk size = $c and tag = $(repr(tag))" for c in (1, 2, 3), tag in (nothing, Tag(f, eltype(x)))
24-
println(" ...running hardcoded test with chunk size = $c and tag = $(repr(tag))")
2526
cfg = ForwardDiff.GradientConfig(f, x, ForwardDiff.Chunk{c}(), tag)
2627

2728
@test eltype(cfg) == Dual{typeof(tag), eltype(x), c}
@@ -51,17 +52,19 @@ cfgx = ForwardDiff.GradientConfig(sin, x)
5152
@test_throws ForwardDiff.InvalidTagException ForwardDiff.gradient(f, x, cfgx)
5253
@test ForwardDiff.gradient(f, x, cfgx, Val{false}()) == ForwardDiff.gradient(f,x)
5354

55+
end
5456

5557
########################
5658
# test vs. Calculus.jl #
5759
########################
60+
@testset "Comparison vs Calculus.jl" begin
5861

5962
@testset "$f" for f in DiffTests.VECTOR_TO_NUMBER_FUNCS
6063
v = f(X)
6164
g = ForwardDiff.gradient(f, X)
6265
@test isapprox(g, Calculus.gradient(f, X), atol=FINITEDIFF_ERROR)
63-
for c in CHUNK_SIZES, tag in (nothing, Tag(f, eltype(x)))
64-
println(" ...testing $f with chunk size = $c and tag = $(repr(tag))")
66+
67+
@testset "chunk size = $c and tag = $(repr(tag))" for c in CHUNK_SIZES, tag in (nothing, Tag(f, eltype(X)))
6568
cfg = ForwardDiff.GradientConfig(f, X, ForwardDiff.Chunk{c}(), tag)
6669

6770
out = ForwardDiff.gradient(f, X, cfg)
@@ -78,15 +81,15 @@ cfgx = ForwardDiff.GradientConfig(sin, x)
7881
end
7982
end
8083

84+
end
85+
8186
##########################################
8287
# test specialized StaticArray codepaths #
8388
##########################################
8489

85-
println(" ...testing specialized StaticArray codepaths")
86-
87-
@testset "$T" for T in (StaticArrays.SArray, StaticArrays.MArray)
88-
x = rand(3, 3)
90+
x = rand(3, 3)
8991

92+
@testset "Specialized $T codepaths" for T in (StaticArrays.SArray, StaticArrays.MArray)
9093
sx = T{Tuple{3,3}}(x)
9194

9295
cfg = ForwardDiff.GradientConfig(nothing, x)

test/HessianTest.jl

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ h = [-66.0 -40.0 0.0;
2323
-40.0 130.0 -80.0;
2424
0.0 -80.0 200.0]
2525

26-
for c in HESSIAN_CHUNK_SIZES, tag in (nothing, Tag((f,ForwardDiff.gradient), eltype(x)))
27-
println(" ...running hardcoded test with chunk size = $c and tag = $(repr(tag))")
26+
@testset "hardcoded" begin
27+
28+
@testset "chunk size = $c and tag = $(repr(tag))" for c in HESSIAN_CHUNK_SIZES, tag in (nothing, Tag((f,ForwardDiff.gradient), eltype(x)))
2829
cfg = ForwardDiff.HessianConfig(f, x, ForwardDiff.Chunk{c}(), tag)
2930
resultcfg = ForwardDiff.HessianConfig(f, DiffResults.HessianResult(x), x, ForwardDiff.Chunk{c}(), tag)
3031

@@ -54,6 +55,8 @@ for c in HESSIAN_CHUNK_SIZES, tag in (nothing, Tag((f,ForwardDiff.gradient), elt
5455
@test isapprox(DiffResults.hessian(out), h)
5556
end
5657

58+
end
59+
5760
cfgx = ForwardDiff.HessianConfig(sin, x)
5861
@test_throws ForwardDiff.InvalidTagException ForwardDiff.hessian(f, x, cfgx)
5962
@test ForwardDiff.hessian(f, x, cfgx, Val{false}()) == ForwardDiff.hessian(f,x)
@@ -63,14 +66,16 @@ cfgx = ForwardDiff.HessianConfig(sin, x)
6366
# test vs. Calculus.jl #
6467
########################
6568

66-
for f in DiffTests.VECTOR_TO_NUMBER_FUNCS
69+
@testset "Comparison vs Calculus.jl" begin
70+
71+
@testset "$f" for f in DiffTests.VECTOR_TO_NUMBER_FUNCS
6772
v = f(X)
6873
g = ForwardDiff.gradient(f, X)
6974
h = ForwardDiff.hessian(f, X)
7075
# finite difference approximation error is really bad for Hessians...
7176
@test isapprox(h, Calculus.hessian(f, X), atol=0.02)
72-
for c in HESSIAN_CHUNK_SIZES, tag in (nothing, Tag((f,ForwardDiff.gradient), eltype(x)))
73-
println(" ...testing $f with chunk size = $c and tag = $(repr(tag))")
77+
78+
@testset "chunk size = $c and tag = $(repr(tag))" for c in HESSIAN_CHUNK_SIZES, tag in (nothing, Tag((f,ForwardDiff.gradient), eltype(x)))
7479
cfg = ForwardDiff.HessianConfig(f, X, ForwardDiff.Chunk{c}(), tag)
7580
resultcfg = ForwardDiff.HessianConfig(f, DiffResults.HessianResult(X), X, ForwardDiff.Chunk{c}(), tag)
7681

@@ -89,14 +94,14 @@ for f in DiffTests.VECTOR_TO_NUMBER_FUNCS
8994
end
9095
end
9196

97+
end
98+
9299
##########################################
93100
# test specialized StaticArray codepaths #
94101
##########################################
95102

96-
println(" ...testing specialized StaticArray codepaths")
97-
98103
x = rand(3, 3)
99-
for T in (StaticArrays.SArray, StaticArrays.MArray)
104+
@testset "Specialized $T codepaths" for T in (StaticArrays.SArray, StaticArrays.MArray)
100105
sx = T{Tuple{3,3}}(x)
101106

102107
cfg = ForwardDiff.HessianConfig(nothing, x)

test/JacobianTest.jl

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ include(joinpath(dirname(@__FILE__), "utils.jl"))
1515
# hardcoded test #
1616
##################
1717

18+
@testset "hardcoded" begin
19+
1820
f! = (y, x) -> begin
1921
y[1] = x[1] * x[2]
2022
y[1] *= sin(x[3]^2)
@@ -31,9 +33,8 @@ j = [0.8242369704835132 0.4121184852417566 -10.933563142616123
3133
0.169076696546684 0.084538348273342 -2.299173530851733
3234
0.0 0.0 1.0]
3335

34-
for c in (1, 2, 3), tags in ((nothing, nothing),
36+
@testset "chunk size = $c and tag = $(repr(tags))" for c in (1, 2, 3), tags in ((nothing, nothing),
3537
(Tag(f, eltype(x)), Tag(f!, eltype(x))))
36-
println(" ...running hardcoded test with chunk size = $c and tag = $(repr(tags))")
3738
cfg = JacobianConfig(f, x, ForwardDiff.Chunk{c}(), tags[1])
3839
ycfg = JacobianConfig(f!, fill(0.0, 4), x, ForwardDiff.Chunk{c}(), tags[2])
3940

@@ -95,19 +96,20 @@ cfgx = ForwardDiff.JacobianConfig(sin, x)
9596
@test_throws ForwardDiff.InvalidTagException ForwardDiff.jacobian(f, x, cfgx)
9697
@test ForwardDiff.jacobian(f, x, cfgx, Val{false}()) == ForwardDiff.jacobian(f,x)
9798

99+
end
100+
98101
########################
99102
# test vs. Calculus.jl #
100103
########################
101104

102-
for f in DiffTests.ARRAY_TO_ARRAY_FUNCS
105+
@testset "Comparison vs Calculus.jl" begin
106+
107+
@testset "$f" for f in DiffTests.ARRAY_TO_ARRAY_FUNCS
103108
v = f(X)
104109
j = ForwardDiff.jacobian(f, X)
105110
@test isapprox(j, Calculus.jacobian(x -> vec(f(x)), X, :forward), atol=1.3FINITEDIFF_ERROR)
106-
for c in CHUNK_SIZES, tag in (nothing, Tag)
107-
if tag == Tag
108-
tag = Tag(f, eltype(X))
109-
end
110-
println(" ...testing $f with chunk size = $c and tag = $(repr(tag))")
111+
112+
@testset "chunk size = $c and tag = $(repr(tag))" for c in CHUNK_SIZES, tag in (nothing, Tag(f, eltype(X)))
111113
cfg = JacobianConfig(f, X, ForwardDiff.Chunk{c}(), tag)
112114

113115
out = ForwardDiff.jacobian(f, X, cfg)
@@ -124,13 +126,13 @@ for f in DiffTests.ARRAY_TO_ARRAY_FUNCS
124126
end
125127
end
126128

127-
for f! in DiffTests.INPLACE_ARRAY_TO_ARRAY_FUNCS
129+
@testset "$f!" for f! in DiffTests.INPLACE_ARRAY_TO_ARRAY_FUNCS
128130
v = fill!(similar(Y), 0.0)
129131
f!(v, X)
130132
j = ForwardDiff.jacobian(f!, fill!(similar(Y), 0.0), X)
131133
@test isapprox(j, Calculus.jacobian(x -> (y = fill!(similar(Y), 0.0); f!(y, x); vec(y)), X, :forward), atol=FINITEDIFF_ERROR)
132-
for c in CHUNK_SIZES, tag in (nothing, Tag(f!, eltype(X)))
133-
println(" ...testing $(f!) with chunk size = $c and tag = $(repr(tag))")
134+
135+
@testset "chunk size = $c and tag = $(repr(tag))" for c in CHUNK_SIZES, tag in (nothing, Tag(f!, eltype(X)))
134136
ycfg = JacobianConfig(f!, fill!(similar(Y), 0.0), X, ForwardDiff.Chunk{c}(), tag)
135137

136138
y = fill!(similar(Y), 0.0)
@@ -160,14 +162,14 @@ for f! in DiffTests.INPLACE_ARRAY_TO_ARRAY_FUNCS
160162
end
161163
end
162164

165+
end
166+
163167
##########################################
164168
# test specialized StaticArray codepaths #
165169
##########################################
166170

167-
println(" ...testing specialized StaticArray codepaths")
168-
169171
x = rand(3, 3)
170-
for T in (StaticArrays.SArray, StaticArrays.MArray)
172+
@testset "Specialized $T codepaths" for T in (StaticArrays.SArray, StaticArrays.MArray)
171173
sx = T{Tuple{3,3}}(x)
172174

173175
cfg = ForwardDiff.JacobianConfig(nothing, x)

test/PartialsTest.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ using ForwardDiff: Partials
88
samerng() = MersenneTwister(1)
99

1010
@testset "Partials{$N,$T}" for N in (0, 3), T in (Int, Float32, Float64)
11-
println(" ...testing Partials{$N,$T}")
12-
1311
VALUES = (rand(T,N)...,)
1412
PARTIALS = Partials{N,T}(VALUES)
1513

0 commit comments

Comments
 (0)