Skip to content

Commit 6598181

Browse files
committed
add tests
1 parent 2c87e5c commit 6598181

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

lib/ImplicitDiscreteSolve/src/cache.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function alg_cache(alg::SimpleIDSolve, u, rate_prototype, ::Type{uEltypeNoUnits}
1616
dt, reltol, p, calck,
1717
::Val{true}) where {uEltypeNoUnits, uBottomEltypeNoUnits, tTypeNoUnits}
1818

19-
state = ImplicitDiscreteState(isnothing(u) ? nothing : similar(u), p, t)
19+
state = ImplicitDiscreteState(isnothing(u) ? nothing : zero(u), p, t)
2020
SimpleIDSolveCache(u, uprev, state, nothing)
2121
end
2222

@@ -31,7 +31,7 @@ function alg_cache(alg::SimpleIDSolve, u, rate_prototype, ::Type{uEltypeNoUnits}
3131
dt, reltol, p, calck,
3232
::Val{false}) where {uEltypeNoUnits, uBottomEltypeNoUnits, tTypeNoUnits}
3333

34-
state = ImplicitDiscreteState(isnothing(u) ? nothing : similar(u), p, t)
34+
state = ImplicitDiscreteState(isnothing(u) ? nothing : zero(u), p, t)
3535
SimpleIDSolveCache(u, uprev, state, nothing)
3636
end
3737

lib/ImplicitDiscreteSolve/src/solve.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ end
3333

3434
function _initialize_dae!(integrator, prob::ImplicitDiscreteProblem,
3535
alg::DefaultInit, x::Union{Val{true}, Val{false}})
36-
atol = one(eltype(prob.u0)) * 1e-12
36+
isnothing(prob.u0) && return
37+
atol = 1e-12
3738
if SciMLBase.has_initializeprob(prob.f)
3839
_initialize_dae!(integrator, prob,
3940
OverrideInit(atol), x)

lib/ImplicitDiscreteSolve/test/runtests.jl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,17 @@ end
6565

6666
for ts in 1:tsteps
6767
step!(integ)
68-
@show integ.u
6968
@test integ.u[1]^2 + integ.u[2]^2 16
7069
end
7170
end
71+
72+
@testset "Handle nothing in u0" begin
73+
function empty(u_next, u, p, t)
74+
nothing
75+
end
76+
77+
tsteps = 5
78+
u0 = nothing
79+
idprob = ImplicitDiscreteProblem(empty, u0, (0, tsteps), [])
80+
@test_nowarn integ = init(idprob, SimpleIDSolve())
81+
end

0 commit comments

Comments
 (0)