Skip to content

Commit 526624e

Browse files
author
dd
committed
more tests
1 parent 8155e56 commit 526624e

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

test/funcaffect.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,16 +177,22 @@ sol2 = solve(prob2, Rodas4())
177177

178178
# discrete events
179179

180+
a7_count = 0
180181
function affect7!(integ, u, p, ctx)
181182
integ.p[p.g] = 0
183+
ctx[1] += 1
184+
@test ctx[1] <= 2
185+
@test (ctx[1] == 1 && integ.t == 1.0) || (ctx[1] == 2 && integ.t == 2.0)
186+
global a7_count += 1
182187
end
183188

189+
a7_ctx = [0]
184190
function Ball(; name, g = 9.8, anti_gravity_time = 1.0)
185191
pars = @parameters g = g
186192
sts = @variables x(t), v(t)
187193
eqs = [D(x) ~ v, D(v) ~ g]
188194
ODESystem(eqs, t, sts, pars; name = name,
189-
discrete_events = [[anti_gravity_time] => (affect7!, [], [g], nothing)])
195+
discrete_events = [[anti_gravity_time] => (affect7!, [], [g], a7_ctx)])
190196
end
191197

192198
@named ball1 = Ball(anti_gravity_time = 1.0)
@@ -201,6 +207,7 @@ prob = ODEProblem(balls, [ball1.x => 10.0, ball1.v => 0, ball2.x => 10.0, ball2.
201207
(0, 3.0))
202208
sol = solve(prob, Tsit5())
203209

210+
@test a7_count == 2
204211
@test sol(0.99)[1] == sol(0.99)[3]
205212
@test sol(1.01)[4] > sol(1.01)[2]
206213
@test sol(1.99)[2] == sol(1.01)[2]

0 commit comments

Comments
 (0)