Skip to content

Commit e04a678

Browse files
committed
tests
1 parent 5e93210 commit e04a678

File tree

3 files changed

+48
-28
lines changed

3 files changed

+48
-28
lines changed

test/DualTest.jl

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ ForwardDiff.:≺(::Int, ::Type{TestTag()}) = false
200200

201201
# Predicates #
202202
#------------#
203+
@testset "Predicates" begin
203204

204205
@test ForwardDiff.isconstant(zero(FDNUM))
205206
@test ForwardDiff.isconstant(one(FDNUM))
@@ -212,10 +213,13 @@ ForwardDiff.:≺(::Int, ::Type{TestTag()}) = false
212213
@test isequal(FDNUM, Dual{TestTag()}(PRIMAL, PARTIALS2)) == (N == 0)
213214
@test isequal(PRIMAL, PRIMAL2) == isequal(FDNUM, FDNUM2)
214215

215-
@test isequal(NESTED_FDNUM, Dual{TestTag()}(Dual{TestTag()}(PRIMAL, M_PARTIALS2), NESTED_PARTIALS2)) == (N == M == 0)
216-
# @test isequal(PRIMAL, PRIMAL2) == isequal(NESTED_FDNUM, NESTED_FDNUM2)
216+
# Recall that FDNUM = Dual{TestTag()}(PRIMAL, PARTIALS) has N partials,
217+
# and FDNUM2 has everything with a 2, and all random numbers nonzero.
218+
# M is the length of M_PARTIALS, which affects:
219+
# NESTED_FDNUM = Dual{TestTag()}(Dual{TestTag()}(PRIMAL, M_PARTIALS), NESTED_PARTIALS)
217220

218-
@info "Predicates" N M V PRIMAL PRIMAL2 NESTED_FDNUM NESTED_FDNUM2
221+
@test isequal(NESTED_FDNUM, Dual{TestTag()}(Dual{TestTag()}(PRIMAL, M_PARTIALS2), NESTED_PARTIALS2)) == (N == M == 0)
222+
@test isequal(NESTED_FDNUM, NESTED_FDNUM2) == isequal(PRIMAL, PRIMAL2) && (N == M == 0)
219223

220224
@test (FDNUM == Dual{TestTag()}(PRIMAL, PARTIALS2)) == (N == 0)
221225
@test (PRIMAL == PRIMAL2) == (FDNUM == FDNUM2)
@@ -300,6 +304,7 @@ ForwardDiff.:≺(::Int, ::Type{TestTag()}) = false
300304
@test isodd(Dual{TestTag()}(Dual{TestTag()}(1)))
301305
@test !(isodd(Dual{TestTag()}(Dual{TestTag()}(2))))
302306

307+
end
303308
########################
304309
# Promotion/Conversion #
305310
########################
@@ -373,8 +378,11 @@ ForwardDiff.:≺(::Int, ::Type{TestTag()}) = false
373378

374379
# Division #
375380
#----------#
381+
@testset "Division" begin
376382

377383
if M > 0 && N > 0
384+
# Recall that FDNUM = Dual{TestTag()}(PRIMAL, PARTIALS) has N partials,
385+
# all random numbers nonzero, and FDNUM2 another draw. M only affects NESTED_FDNUM.
378386
@test Dual{1}(FDNUM) / Dual{1}(PRIMAL) === Dual{1}(FDNUM / PRIMAL)
379387
@test Dual{1}(PRIMAL) / Dual{1}(FDNUM) === Dual{1}(PRIMAL / FDNUM)
380388
@test_broken Dual{1}(FDNUM) / FDNUM2 === Dual{1}(FDNUM / FDNUM2)
@@ -391,8 +399,10 @@ ForwardDiff.:≺(::Int, ::Type{TestTag()}) = false
391399
@test dual_isapprox(NESTED_FDNUM / PRIMAL, Dual{TestTag()}(value(NESTED_FDNUM) / PRIMAL, partials(NESTED_FDNUM) / PRIMAL))
392400
@test dual_isapprox(PRIMAL / NESTED_FDNUM, Dual{TestTag()}(PRIMAL / value(NESTED_FDNUM), (-(PRIMAL) / value(NESTED_FDNUM)^2) * partials(NESTED_FDNUM)))
393401

402+
end
394403
# Exponentiation #
395404
#----------------#
405+
@testset "Exponentiation" begin
396406

397407
@test dual_isapprox(FDNUM^FDNUM2, exp(FDNUM2 * log(FDNUM)))
398408
@test dual_isapprox(FDNUM^PRIMAL, exp(PRIMAL * log(FDNUM)))
@@ -404,6 +414,7 @@ ForwardDiff.:≺(::Int, ::Type{TestTag()}) = false
404414

405415
@test partials(NaNMath.pow(Dual{TestTag()}(-2.0, 1.0), Dual{TestTag()}(2.0, 0.0)), 1) == -4.0
406416

417+
end
407418
###################################
408419
# General Mathematical Operations #
409420
###################################
@@ -459,6 +470,7 @@ ForwardDiff.:≺(::Int, ::Type{TestTag()}) = false
459470

460471
# Special Cases #
461472
#---------------#
473+
@testset "Special Cases" begin
462474

463475
@test_broken dual_isapprox(hypot(FDNUM, FDNUM2, FDNUM), sqrt(2*(FDNUM^2) + FDNUM2^2))
464476
@test_broken dual_isapprox(hypot(FDNUM, FDNUM2, FDNUM3), sqrt(FDNUM^2 + FDNUM2^2 + FDNUM3^2))
@@ -483,8 +495,14 @@ ForwardDiff.:≺(::Int, ::Type{TestTag()}) = false
483495
@test dual_isapprox(f(FDNUM, PRIMAL2, PRIMAL3), Dual{TestTag()}(f(PRIMAL, PRIMAL2, PRIMAL3), PRIMAL2*PARTIALS))
484496
@test dual_isapprox(f(PRIMAL, PRIMAL2, FDNUM3), Dual{TestTag()}(f(PRIMAL, PRIMAL2, PRIMAL3), PARTIALS3))
485497
end
498+
499+
end # testset
486500
end
487501

502+
#############
503+
# bug fixes #
504+
#############
505+
488506
@testset "Exponentiation of zero" begin
489507
x0 = 0.0
490508
x1 = Dual{:t1}(x0, 1.0)

test/GradientTest.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ x = [0.1, 0.2, 0.3]
2020
v = f(x)
2121
g = [-9.4, 15.6, 52.0]
2222

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

@@ -56,7 +56,7 @@ cfgx = ForwardDiff.GradientConfig(sin, x)
5656
# test vs. Calculus.jl #
5757
########################
5858

59-
for f in DiffTests.VECTOR_TO_NUMBER_FUNCS
59+
@testset "$f" for f in DiffTests.VECTOR_TO_NUMBER_FUNCS
6060
v = f(X)
6161
g = ForwardDiff.gradient(f, X)
6262
@test isapprox(g, Calculus.gradient(f, X), atol=FINITEDIFF_ERROR)

test/runtests.jl

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,53 @@
11
using ForwardDiff, Test
22

33
@testset "ForwardDiff" begin
4+
t0 = time()
45
@testset "Partials" begin
5-
println("Testing Partials...")
6+
println("##### Testing Partials...")
67
t = @elapsed include("PartialsTest.jl")
7-
println("done (took $t seconds).")
8+
println("##### done (took $t seconds).")
89
end
910
@testset "Dual" begin
10-
println("Testing Dual...")
11+
println("##### Testing Dual...")
1112
t = @elapsed include("DualTest.jl")
12-
println("done (took $t seconds).")
13+
println("##### done (took $t seconds).")
1314
end
14-
@testset "Derivative" begin
15-
println("Testing derivative functionality...")
15+
@testset "Derivatives" begin
16+
println("##### Testing derivative functionality...")
1617
t = @elapsed include("DerivativeTest.jl")
17-
println("done (took $t seconds).")
18+
println("##### done (took $t seconds).")
1819
end
19-
@testset "Gradient" begin
20-
println("Testing gradient functionality...")
20+
@testset "Gradients" begin
21+
println("##### Testing gradient functionality...")
2122
t = @elapsed include("GradientTest.jl")
22-
println("done (took $t seconds).")
23+
println("##### done (took $t seconds).")
2324
end
24-
@testset "Jacobian" begin
25-
println("Testing jacobian functionality...")
25+
@testset "Jacobians" begin
26+
println("##### Testing jacobian functionality...")
2627
t = @elapsed include("JacobianTest.jl")
27-
println("done (took $t seconds).")
28+
println("##### done (took $t seconds).")
2829
end
29-
@testset "Hessian" begin
30-
println("Testing hessian functionality...")
30+
@testset "Hessians" begin
31+
println("##### Testing hessian functionality...")
3132
t = @elapsed include("HessianTest.jl")
32-
println("done (took $t seconds).")
33+
println("##### done (took $t seconds).")
3334
end
34-
@testset "Perturbation confusion" begin
35-
println("Testing perturbation confusion functionality...")
35+
@testset "Perturbation Confusion" begin
36+
println("##### Testing perturbation confusion functionality...")
3637
t = @elapsed include("ConfusionTest.jl")
37-
println("done (took $t seconds).")
38+
println("##### done (took $t seconds).")
3839
end
3940
@testset "Miscellaneous" begin
40-
println("Testing miscellaneous functionality...")
41+
println("##### Testing miscellaneous functionality...")
4142
t = @elapsed include("MiscTest.jl")
42-
println("done (took $t seconds).")
43+
println("##### done (took $t seconds).")
4344
end
4445
if VERSION >= v"1.5-"
4546
@testset "Allocations" begin
46-
println("Testing allocations...")
47+
println("##### Testing allocations...")
4748
t = @elapsed include("AllocationsTest.jl")
48-
println("done (took $t seconds).")
49+
println("##### done (took $t seconds).")
4950
end
5051
end
52+
println("##### Running all ForwardDiff tests took $(t0 - time()) seconds.")
5153
end

0 commit comments

Comments
 (0)