From d7fb363e2ab0b6eaf2417bc677a396116d55187a Mon Sep 17 00:00:00 2001 From: Sam Isaacson Date: Tue, 13 Aug 2024 13:47:49 -0400 Subject: [PATCH] add tests and format --- README.md | 1 - src/SSA_stepper.jl | 5 ++--- test/ssa_callback_test.jl | 33 +++++++++++++++++++++++++++------ 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index c1b1f1a6..badc20c7 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,6 @@ - [![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) diff --git a/src/SSA_stepper.jl b/src/SSA_stepper.jl index 9cd9e968..70039ee6 100644 --- a/src/SSA_stepper.jl +++ b/src/SSA_stepper.jl @@ -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 @@ -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 diff --git a/test/ssa_callback_test.jl b/test/ssa_callback_test.jl index 0e5a0992..acbbd073 100644 --- a/test/ssa_callback_test.jl +++ b/test/ssa_callback_test.jl @@ -134,9 +134,9 @@ 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)) @@ -144,16 +144,37 @@ let 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 \ No newline at end of file +# 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