Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisRackauckas committed May 15, 2022
1 parent cb25e31 commit fb80c6c
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions test/common_interface/iterators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,20 @@ u2 = copy(integrator.u)
@test u1 != vec(prob.u0)
@test u1 == u2

f(u, p, t) = 2 * u
u_positive(u, t, integrator) = u > 0
f(u, p, t) = [2 * u[1]]
u_positive(u, t, integrator) = u[1] > 0
terminate_if_u_pos = DiscreteCallback(u_positive, terminate!)

prob = ODEProblem(f, [1.0], (0.0, 1.0)) # positive initial condition > positive u > :Terminated
integrator = init(prob, CVODE_BDF(), callback=terminate_if_u_pos)
sol1 = solve!(integrator)
@test sol1.retcode === :Terminated

reinit!(integrator, -1.0) # negative initial condition > negative u > :Success!
reinit!(integrator, [-1.0]) # negative initial condition > negative u > :Success!
sol2 = solve!(integrator)
@test sol2.retcode == :Success

prob = ODEProblem(f, -1.0, (0.0, 1.0)) # negative initial condition > negative u > :Success!
integrator = init(prob, Tsit5(), callback=terminate_if_u_pos)
prob = ODEProblem(f, [-1.0], (0.0, 1.0)) # negative initial condition > negative u > :Success!
integrator = init(prob, CVODE_BDF(), callback=terminate_if_u_pos)
sol3 = solve!(integrator)
@test sol3.retcode == :Success

0 comments on commit fb80c6c

Please sign in to comment.