Skip to content

Commit

Permalink
add tests and format
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacsas committed Aug 13, 2024
1 parent 7234c51 commit d7fb363
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

<!-- [![Coverage Status](https://coveralls.io/repos/github/SciML/JumpProcesses.jl/badge.svg?branch=master)](https://coveralls.io/github/SciML/JumpProcesses.jl?branch=master)
[![codecov](https://codecov.io/gh/SciML/JumpProcesses.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/SciML/JumpProcesses.jl) -->

[![Build Status](https://github.com/SciML/JumpProcesses.jl/workflows/CI/badge.svg)](https://github.com/SciML/JumpProcesses.jl/actions?query=workflow%3ACI)
[![ColPrac: Contributor's Guide on Collaborative Practices for Community Packages](https://img.shields.io/badge/ColPrac-Contributor%27s%20Guide-blueviolet)](https://github.com/SciML/ColPrac)
[![SciML Code Style](https://img.shields.io/static/v1?label=code%20style&message=SciML&color=9558b2&labelColor=389826)](https://github.com/SciML/SciMLStyle)
Expand Down
5 changes: 2 additions & 3 deletions src/SSA_stepper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ function DiffEqBase.__init(jump_prob::JumpProblem,
tstops = nothing,
alias_tstops = false,
numsteps_hint = 100)

if !(jump_prob.prob isa DiscreteProblem)
error("SSAStepper only supports DiscreteProblems.")
end
Expand Down Expand Up @@ -264,10 +263,10 @@ function DiffEqBase.add_tstop!(integrator::SSAIntegrator, tstop)
tstops = integrator.tstops
else
integrator.copied_tstops = true
tstops = copy(integrator.tstops)
integrator.tstops = copy(integrator.tstops)
end

Base.insert!(tstops, insert_index, tstop)
Base.insert!(integrator.tstops, insert_index, tstop)
end
nothing
end
Expand Down
33 changes: 27 additions & 6 deletions test/ssa_callback_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -134,26 +134,47 @@ cb = PresetTimeCallback(cbtimes, affectpresets!)
jsol = solve(jprob, SSAStepper(), saveat = 0.1, callback = cb)
@test (jsol(20.00000000001) - jsol(19.9999999999))[1] == 10

# tests for periodic callbacks working, i.e. #417
# test periodic callbacks working, i.e. #417
let
rate(u,p,t) = 0.0
rate(u, p, t) = 0.0
affect!(integ) = (nothing)
crj = ConstantRateJump(rate, affect!)
dprob = DiscreteProblem([0], (0.0, 10.0))
cbfun(integ) = (integ.u[1] += 1; nothing)
cb = PeriodicCallback(cbfun, 1.0)
jprob = JumpProblem(dprob, crj; rng)
sol = solve(jprob; callback = cb)
@test sol[1,end] == 9
@test sol[1, end] == 9

cb = PeriodicCallback(cbfun, 1.0; initial_affect = true)
jprob = JumpProblem(dprob, crj; rng)
sol = solve(jprob; callback = cb)
@test sol[1,end] == 10
@test sol[1, end] == 10

cb = PeriodicCallback(cbfun, 1.0; initial_affect = true, final_affect = true)
jprob = JumpProblem(dprob, crj; rng)
sol = solve(jprob; callback = cb)
@test sol[1,end] == 11
@test sol[1, end] == 11
end

end
# test for tstops aliasing, i.e.#442
let
rate(u, p, t) = 0.0
affect!(integ) = (nothing)
crj = ConstantRateJump(rate, affect!)
dprob = DiscreteProblem([0], (0.0, 10.0))
cbfun(integ) = (integ.u[1] += 1; nothing)
cb = PeriodicCallback(cbfun, 1.0)
jprob = JumpProblem(dprob, crj; rng)
tstops = Float64[]
sol = solve(jprob; callback = cb, tstops, alias_tstops = true)
@test sol[1, end] == 9
@test tstops == 1.0:9.0
empty!(tstops)
sol = solve(jprob; callback = cb, tstops, alias_tstops = false)
@test sol[1, end] == 9
@test isempty(tstops)
sol = solve(jprob; callback = cb, tstops)
@test sol[1, end] == 9
@test isempty(tstops)
end

0 comments on commit d7fb363

Please sign in to comment.