Skip to content

Commit

Permalink
Merge pull request #535 from ranocha/isapprox_instead_of_norm
Browse files Browse the repository at this point in the history
use isapprox in tests instead of norm(.) < .; closes #387
  • Loading branch information
ChrisRackauckas authored Oct 15, 2018
2 parents d008ddb + ceb9979 commit b90e3d9
Show file tree
Hide file tree
Showing 10 changed files with 237 additions and 237 deletions.
14 changes: 7 additions & 7 deletions test/complex_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ implicit_noautodiff = [ImplicitEuler(autodiff=false),Trapezoid(autodiff=false),K
ψ0 = [1.0+0.0im; 0.0]
prob = ODEProblem(f,ψ0,(-T,T))
sol = solve(prob,alg)
@test abs(norm(sol(T)) - 1.0) < 1e-2
@test norm(sol(T)) 1 atol=1e-2
end
ψ0 = @SArray [1.0+0.0im; 0.0]
prob = ODEProblem(fun,ψ0,(-T,T))
sol = solve(prob,alg)
@test abs(norm(sol(T)) - 1.0) < 1e-2
@test norm(sol(T)) 1 atol=1e-2
end

@testset "Complex Tests on Implicit Autodiff Methods" for alg in implicit_autodiff
Expand All @@ -34,28 +34,28 @@ end
ψ0 = [1.0+0.0im; 0.0]
prob = ODEProblem(f,ψ0,(-T,T))
sol = solve(prob,alg)
@test abs(norm(sol(T)) - 1.0) < 1e-2
@test norm(sol(T)) 1 atol=1e-2
end
ψ0 = @SArray [1.0+0.0im; 0.0]
prob = ODEProblem(fun,ψ0,(-T,T))
sol = solve(prob,alg)
@test abs(norm(sol(T)) - 1.0) < 1e-2
@test norm(sol(T)) 1 atol=1e-2
end
end

@testset "Complex Tests on Implicit Finite Diff Methods" for alg in implicit_noautodiff
ψ0 = [1.0+0.0im; 0.0]
prob = ODEProblem(fun_inplace,ψ0,(-T,T))
sol = solve(prob,alg)
@test abs(norm(sol(T)) - 1.0) < 1e-2
@test norm(sol(T)) 1 atol=1e-2
end

@testset "Complex Tests on Implicit Finite Diff Out-of-place Methods" begin
for alg in implicit_noautodiff
ψ0 = [1.0+0.0im; 0.0]
prob = ODEProblem(fun,ψ0,(-T,T))
sol = solve(prob,alg)
@test abs(norm(sol(T)) - 1.0) < 1e-2
@test norm(sol(T)) 1 atol=1e-2
end
end

Expand All @@ -65,7 +65,7 @@ end
ψ0 = @SArray [1.0+0.0im; 0.0]
prob = ODEProblem(fun,ψ0,(-T,T))
sol = solve(prob,alg)
@test abs(norm(sol(T)) - 1.0) < 1e-2
@test norm(sol(T)) 1 atol=1e-2
end
end
end
4 changes: 2 additions & 2 deletions test/linear_method_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ sol = solve(prob,LinearImplicitEuler())

dts = 1./2.^(8:-1:4) #14->7 good plot
sim = test_convergence(dts,prob,LinearImplicitEuler())
@test abs(sim.𝒪est[:l2]-1) < 0.2
@test sim.𝒪est[:l2] 1 atol=0.2

# using Plots; pyplot(); plot(sim)

Expand Down Expand Up @@ -76,4 +76,4 @@ x0,v0,ti = rand(3)
prob = ODEProblem(H, [x0, v0, 1, ti], (ti, 5.))
dts = 1./2.^(10:-1:1)
sim = test_convergence(dts,prob,MidpointSplitting())
@test abs(sim.𝒪est[:l2]-2) < 0.2
@test sim.𝒪est[:l2] 2 atol=0.2
28 changes: 14 additions & 14 deletions test/linear_nonlinear_convergence_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ using OrdinaryDiffEq: alg_order
for Alg in [GenericIIF1,GenericIIF2,LawsonEuler,NorsettEuler,ETDRK2,ETDRK3,ETDRK4,HochOst4,Exprb32,Exprb43,ETD2,KenCarp3]
sim = test_convergence(dts,prob,Alg())
if Alg in [Exprb32, Exprb43]
@test_broken abs(sim.𝒪est[:l2] - alg_order(Alg())) < 0.2
@test_broken sim.𝒪est[:l2] alg_order(Alg()) atol=0.2
else
@test abs(sim.𝒪est[:l2] - alg_order(Alg())) < 0.2
@test sim.𝒪est[:l2] alg_order(Alg()) atol=0.2
end
end
# Dense test
Expand All @@ -38,14 +38,14 @@ end
for Alg in [GenericIIF1,GenericIIF2,LawsonEuler,NorsettEuler,ETDRK2,ETDRK3,ETDRK4,HochOst4,Exprb32,Exprb43,ETD2,KenCarp3]
sim = test_convergence(dts,prob,Alg())
if Alg in [Exprb32, Exprb43]
@test_broken abs(sim.𝒪est[:l2] - alg_order(Alg())) < 0.1
@test_broken sim.𝒪est[:l2] alg_order(Alg()) atol=0.1
else
@test abs(sim.𝒪est[:l2] - alg_order(Alg())) < 0.1
@test sim.𝒪est[:l2] alg_order(Alg()) atol=0.1
end
end
sim = test_convergence(dts,prob,ETDRK4(),dense_errors=true)
@test abs(sim.𝒪est[:l2]-4) < 0.1
@test abs(sim.𝒪est[:L2]-4) < 0.1
@test sim.𝒪est[:l2] 4 atol=0.1
@test sim.𝒪est[:L2] 4 atol=0.1
end

@testset "EPIRK Out-of-place" begin
Expand All @@ -65,9 +65,9 @@ end
for Alg in Algs
sim = analyticless_test_convergence(dts, prob, Alg(adaptive_krylov=false), test_setup)
if Alg == EPIRK5s3
@test_broken abs(sim.𝒪est[:l2] - alg_order(Alg())) < 0.1
@test_broken sim.𝒪est[:l2] alg_order(Alg()) atol=0.1
else
@test abs(sim.𝒪est[:l2] - alg_order(Alg())) < 0.1
@test sim.𝒪est[:l2] alg_order(Alg()) atol=0.1
end
end
end
Expand All @@ -90,9 +90,9 @@ end
for Alg in Algs
sim = analyticless_test_convergence(dts, prob, Alg(adaptive_krylov=false), test_setup)
if Alg == EPIRK5s3
@test_broken abs(sim.𝒪est[:l2] - alg_order(Alg())) < 0.1
@test_broken sim.𝒪est[:l2] alg_order(Alg()) atol=0.1
else
@test abs(sim.𝒪est[:l2] - alg_order(Alg())) < 0.1
@test sim.𝒪est[:l2] alg_order(Alg()) atol=0.1
end
end
end
Expand All @@ -113,11 +113,11 @@ end
# Convergence simulation
dts = 1 ./2 .^(7:-1:4)
sim = analyticless_test_convergence(dts, prob, HochOst4(krylov=true), test_setup)
@test abs(sim.𝒪est[:l2] - 4) < 0.1
@test sim.𝒪est[:l2] 4 atol=0.1
sim = analyticless_test_convergence(dts, prob_ip, HochOst4(krylov=true), test_setup)
@test abs(sim.𝒪est[:l2] - 4) < 0.1
@test sim.𝒪est[:l2] 4 atol=0.1
sim = analyticless_test_convergence(dts, prob, EPIRK5P1(adaptive_krylov=false), test_setup)
@test abs(sim.𝒪est[:l2] - 5) < 0.1
@test sim.𝒪est[:l2] 5 atol=0.1
sim = analyticless_test_convergence(dts, prob_ip, EPIRK5P1(adaptive_krylov=false), test_setup)
@test abs(sim.𝒪est[:l2] - 5) < 0.1
@test sim.𝒪est[:l2] 5 atol=0.1
end
8 changes: 4 additions & 4 deletions test/ode/nordsieck_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ dts = 1 .//(2 .^(10:-1:5))
@testset "Nordsieck Convergence Tests" begin
for i in eachindex(probArr)
sim = test_convergence(dts,probArr[i],AN5())
@test abs(sim.𝒪est[:final]-5) < testTol
@test abs(sim.𝒪est[:l2]-5) < testTol
@test abs(sim.𝒪est[:l∞]-5) < testTol
@test sim.𝒪est[:final] 5 atol=testTol
@test sim.𝒪est[:l2] 5 atol=testTol
@test sim.𝒪est[:l∞] 5 atol=testTol
end
end

Expand All @@ -23,7 +23,7 @@ probArr = [prob_ode_linear,
sol = solve(prob, AN5(), reltol=1e-6)
@test length(sol.t) < 11
exact = prob.f(Val{:analytic}, prob.u0, prob.p, prob.tspan[end])
@test Float64(norm(exact-sol[end])) < 1e-5
@test exact sol[end] atol=1e-5
end
end

Expand Down
130 changes: 65 additions & 65 deletions test/ode/ode_convergence_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,169 +16,169 @@ for i = 1:2
global dts
prob = probArr[i]
sim = test_convergence(dts,prob,Euler())
@test abs(sim.𝒪est[:final]-1) < testTol
@test sim.𝒪est[:final] 1 atol=testTol
sim2 = test_convergence(dts,prob,Heun())
@test abs(sim2.𝒪est[:l∞]-2) < testTol
@test sim2.𝒪est[:l∞] 2 atol=testTol
sim2 = test_convergence(dts,prob,Ralston())
@test abs(sim2.𝒪est[:l∞]-2) < testTol
@test sim2.𝒪est[:l∞] 2 atol=testTol
sim2 = test_convergence(dts,prob,Midpoint())
@test abs(sim2.𝒪est[:l∞]-2) < testTol
@test sim2.𝒪est[:l∞] 2 atol=testTol
sim3 = test_convergence(dts,prob,RK4())
@test abs(sim3.𝒪est[:l∞]-4) < testTol
@test sim3.𝒪est[:l∞] 4 atol=testTol
sim4 = test_convergence(dts,prob,BS3())
@test abs(sim4.𝒪est[:l2]-3) < testTol
@test sim4.𝒪est[:l2] 3 atol=testTol
alg = CarpenterKennedy2N54()
@test abs(test_convergence(dts,prob,alg).𝒪est[:l∞]-OrdinaryDiffEq.alg_order(alg)) < testTol
@test test_convergence(dts,prob,alg).𝒪est[:l∞] OrdinaryDiffEq.alg_order(alg) atol=testTol
sim5 = test_convergence(dts, prob, AB3())
@test abs(sim5.𝒪est[:l2]-3) < testTol
@test sim5.𝒪est[:l2] 3 atol=testTol
sim6 = test_convergence(dts,prob,ABM32())
@test abs(sim6.𝒪est[:l2]-3) < testTol
@test sim6.𝒪est[:l2] 3 atol=testTol
sim7 = test_convergence(dts, prob, AB4())
@test abs(sim7.𝒪est[:l2]-4) < testTol
@test sim7.𝒪est[:l2] 4 atol=testTol
sim8 = test_convergence(dts1,prob,ABM43()) #using dts1 due to floating point error in convergence test
@test abs(sim8.𝒪est[:l2]-4) < testTol
@test sim8.𝒪est[:l2] 4 atol=testTol
sim9 = test_convergence(dts,prob,AB5())
@test abs(sim9.𝒪est[:l2]-5) < testTol
@test sim9.𝒪est[:l2] 5 atol=testTol
sim10 = test_convergence(dts,prob,ABM54())
@test abs(sim10.𝒪est[:l2]-5) < testTol
@test sim10.𝒪est[:l2] 5 atol=testTol
sim101 = test_convergence(dts,prob,VCAB3())
@test abs(sim101.𝒪est[:l2]-3) < testTol
@test sim101.𝒪est[:l2] 3 atol=testTol
sim102 = test_convergence(dts,prob,VCAB4())
@test abs(sim102.𝒪est[:l2]-4) < testTol
@test sim102.𝒪est[:l2] 4 atol=testTol
sim103 = test_convergence(dts,prob,VCAB5())
@test abs(sim103.𝒪est[:l2]-5) < testTol
@test sim103.𝒪est[:l2] 5 atol=testTol
sim104 = test_convergence(dts,prob,VCABM3())
@test abs(sim104.𝒪est[:l2]-3) < testTol
@test sim104.𝒪est[:l2] 3 atol=testTol
sim105 = test_convergence(dts,prob,VCABM4())
@test abs(sim105.𝒪est[:l2]-4) < testTol
@test sim105.𝒪est[:l2] 4 atol=testTol
sim106 = test_convergence(dts,prob,VCABM5())
@test abs(sim106.𝒪est[:l2]-5) < testTol
@test sim106.𝒪est[:l2] 5 atol=testTol
sim160 = test_convergence(dts,prob,Anas5(w=2))
@test abs(sim160.𝒪est[:l2]-4) < 2*testTol
@test sim160.𝒪est[:l2] 4 atol=2*testTol

println("Stiff Solvers")

dts = 1 .//2 .^(9:-1:5)

sim11 = test_convergence(dts,prob,ImplicitEuler(extrapolant = :linear))
@test abs(sim11.𝒪est[:final]-1) < testTol
@test sim11.𝒪est[:final] 1 atol=testTol

sim112 = test_convergence(dts,prob,ImplicitEuler(nlsolve = NLFunctional()))
@test abs(sim112.𝒪est[:final]-1) < testTol
@test sim112.𝒪est[:final] 1 atol=testTol

sim12 = test_convergence(dts,prob,
GenericImplicitEuler(nlsolve=OrdinaryDiffEq.NLSOLVEJL_SETUP(autodiff=true)))
@test abs(sim12.𝒪est[:final]-1) < testTol
@test sim12.𝒪est[:final] 1 atol=testTol

sim122 = test_convergence(dts,prob,
GenericImplicitEuler(nlsolve=OrdinaryDiffEq.NLSOLVEJL_SETUP(autodiff=false)))

sim13 = test_convergence(dts,prob,ImplicitMidpoint())
@test abs(sim13.𝒪est[:final]-2) < testTol
@test sim13.𝒪est[:final] 2 atol=testTol

sim132 = test_convergence(dts,prob,ImplicitMidpoint(nlsolve = NLFunctional()))
@test abs(sim132.𝒪est[:final]-2) < testTol
@test sim132.𝒪est[:final] 2 atol=testTol

sim13 = test_convergence(dts,prob,Trapezoid())
@test abs(sim13.𝒪est[:final]-2) < testTol
@test sim13.𝒪est[:final] 2 atol=testTol

sim133 = test_convergence(dts,prob,Trapezoid(nlsolve = NLFunctional()))
@test abs(sim133.𝒪est[:final]-2) < testTol
@test sim133.𝒪est[:final] 2 atol=testTol

sim14 = test_convergence(dts,prob,
GenericTrapezoid(nlsolve=OrdinaryDiffEq.NLSOLVEJL_SETUP(autodiff=true)))
@test abs(sim14.𝒪est[:final]-2) < testTol
@test sim14.𝒪est[:final] 2 atol=testTol

sim142 = test_convergence(dts,prob,
GenericTrapezoid(nlsolve=OrdinaryDiffEq.NLSOLVEJL_SETUP(autodiff=false)))
@test abs(sim142.𝒪est[:final]-2) < testTol
@test sim142.𝒪est[:final] 2 atol=testTol

sim14 = test_convergence(dts,prob,TRBDF2())
@test abs(sim14.𝒪est[:final]-2) < testTol
@test sim14.𝒪est[:final] 2 atol=testTol

sim152 = test_convergence(dts,prob,TRBDF2(autodiff=false))
@test abs(sim152.𝒪est[:final]-2) < testTol+0.1
@test sim152.𝒪est[:final] 2 atol=testTol+0.1

sim15 = test_convergence(dts,prob,SDIRK2())
@test abs(sim15.𝒪est[:final]-2) < testTol
@test sim15.𝒪est[:final] 2 atol=testTol

sim152 = test_convergence(dts,prob,SSPSDIRK2())
@test abs(sim152.𝒪est[:final]-2) < testTol
@test sim152.𝒪est[:final] 2 atol=testTol

sim16 = test_convergence(dts,prob,Kvaerno3())
@test abs(sim16.𝒪est[:final]-3) < testTol
@test sim16.𝒪est[:final] 3 atol=testTol

sim162 = test_convergence(dts,prob,Kvaerno3(nlsolve = NLFunctional()))
@test abs(sim162.𝒪est[:final]-3) < testTol
@test sim162.𝒪est[:final] 3 atol=testTol

sim17 = test_convergence(dts,prob,KenCarp3())
@test abs(sim17.𝒪est[:final]-3) < testTol
@test sim17.𝒪est[:final] 3 atol=testTol

#####################################
# BDF
#####################################

sim = test_convergence(dts,prob,ABDF2(extrapolant = :linear))
@test abs(sim.𝒪est[:final]-2) < testTol
@test abs(sim.𝒪est[:l2]-2) < testTol
@test abs(sim.𝒪est[:l∞]-2) < testTol
@test sim.𝒪est[:final] 2 atol=testTol
@test sim.𝒪est[:l2] 2 atol=testTol
@test sim.𝒪est[:l∞] 2 atol=testTol

sim = test_convergence(dts,prob,ABDF2(nlsolve = NLFunctional()))
@test abs(sim.𝒪est[:final]-2) < testTol
@test abs(sim.𝒪est[:l2]-2) < testTol
@test abs(sim.𝒪est[:l∞]-2) < testTol
@test sim.𝒪est[:final] 2 atol=testTol
@test sim.𝒪est[:l2] 2 atol=testTol
@test sim.𝒪est[:l∞] 2 atol=testTol

# QBDF
sim = test_convergence(dts,prob,QBDF1())
@test abs(sim.𝒪est[:final]-1) < testTol
@test abs(sim.𝒪est[:l2]-1) < testTol
@test abs(sim.𝒪est[:l∞]-1) < testTol
@test sim.𝒪est[:final] 1 atol=testTol
@test sim.𝒪est[:l2] 1 atol=testTol
@test sim.𝒪est[:l∞] 1 atol=testTol

sim = test_convergence(dts,prob,QBDF2())
@test abs(sim.𝒪est[:final]-2) < testTol
@test abs(sim.𝒪est[:l2]-2) < testTol
@test abs(sim.𝒪est[:l∞]-2) < testTol
@test sim.𝒪est[:final] 2 atol=testTol
@test sim.𝒪est[:l2] 2 atol=testTol
@test sim.𝒪est[:l∞] 2 atol=testTol

# QNDF
sim = test_convergence(dts,prob,QNDF1())
@test abs(sim.𝒪est[:final]-1) < testTol
@test abs(sim.𝒪est[:l2]-1) < testTol
@test abs(sim.𝒪est[:l∞]-1) < testTol
@test sim.𝒪est[:final] 1 atol=testTol
@test sim.𝒪est[:l2] 1 atol=testTol
@test sim.𝒪est[:l∞] 1 atol=testTol

sim = test_convergence(dts,prob,QNDF2())
@test abs(sim.𝒪est[:final]-2) < testTol
@test abs(sim.𝒪est[:l2]-2) < testTol
@test abs(sim.𝒪est[:l∞]-2) < testTol
@test sim.𝒪est[:final] 2 atol=testTol
@test sim.𝒪est[:l2] 2 atol=testTol
@test sim.𝒪est[:l∞] 2 atol=testTol

sim = test_convergence(dts,prob,QNDF2(nlsolve = NLFunctional()))
@test abs(sim.𝒪est[:final]-2) < testTol
@test abs(sim.𝒪est[:l2]-2) < testTol
@test abs(sim.𝒪est[:l∞]-2) < testTol
@test sim.𝒪est[:final] 2 atol=testTol
@test sim.𝒪est[:l2] 2 atol=testTol
@test sim.𝒪est[:l∞] 2 atol=testTol

dts = 1 .//2 .^(7:-1:4)
println("Higher Order")

sim18 = test_convergence(dts,prob,Cash4())
@test abs(sim18.𝒪est[:final]-4) < testTol
@test sim18.𝒪est[:final] 4 atol=testTol

sim19 = test_convergence(dts,prob,Hairer4())
@test abs(sim19.𝒪est[:final]-4) < testTol
@test sim19.𝒪est[:final] 4 atol=testTol

sim110 = test_convergence(dts,prob,Hairer42())
@test abs(sim110.𝒪est[:final]-4) < testTol
@test sim110.𝒪est[:final] 4 atol=testTol

sim111 = test_convergence(dts,prob,Kvaerno4())
@test abs(sim111.𝒪est[:final]-4) < testTol
@test sim111.𝒪est[:final] 4 atol=testTol

sim112 = test_convergence(dts,prob,KenCarp4())
@test abs(sim112.𝒪est[:final]-4) < testTol
@test sim112.𝒪est[:final] 4 atol=testTol

sim113 = test_convergence(dts,prob,Kvaerno5())
@test abs(sim113.𝒪est[:final]-5) < testTol
@test sim113.𝒪est[:final] 5 atol=testTol

sim114 = test_convergence(dts,prob,KenCarp5())
@test abs(sim114.𝒪est[:final]-5) < testTol
@test sim114.𝒪est[:final] 5 atol=testTol

sim115 = test_convergence(dts,prob,KenCarp5(nlsolve = NLFunctional()))
@test_broken abs(sim115.𝒪est[:final]-5) < testTol
@test_broken sim115.𝒪est[:final] 5 atol=testTol
end
Loading

0 comments on commit b90e3d9

Please sign in to comment.