Skip to content

Commit 289df8f

Browse files
fix test definitions
1 parent 1242039 commit 289df8f

File tree

1 file changed

+20
-22
lines changed

1 file changed

+20
-22
lines changed

test/interface/ode_tstops_tests.jl

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using OrdinaryDiffEq, Test, Random, StaticArrays, DiffEqCallbacks
22
import ODEProblemLibrary: prob_ode_linear
33
Random.seed!(100)
4-
54
@testset "Tstops Tests on the Interval [0, 1]" begin
65
prob = prob_ode_linear
76

@@ -124,16 +123,16 @@ end
124123
# Test with extreme tolerances that originally caused issues
125124
prob_static = ODEProblem(precise_dynamics, u0_static, tspan)
126125
sol_static = solve(prob_static, Vern9(); reltol=1e-12, abstol=1e-15,
127-
tstops=tstops, save_everystep=false)
128-
@test sol_static.retcode == :Success
126+
tstops=tstops)
127+
@test SciMLBase.successful_retcode(sol_static)
129128
for tstop in tstops
130129
@test tstop sol_static.t
131130
end
132131

133132
prob_array = ODEProblem(precise_dynamics_array!, u0_array, tspan)
134133
sol_array = solve(prob_array, Vern9(); reltol=1e-12, abstol=1e-15,
135-
tstops=tstops, save_everystep=false)
136-
@test sol_array.retcode == :Success
134+
tstops=tstops)
135+
@test SciMLBase.successful_retcode(sol_static)
137136
for tstop in tstops
138137
@test tstop sol_array.t
139138
end
@@ -144,7 +143,7 @@ end
144143

145144
@testset "Duplicate tstops handling" begin
146145
function simple_ode(u, p, t)
147-
[0.1 * u[1]]
146+
SA[0.1 * u[1]]
148147
end
149148

150149
u0 = SVector{1}(1.0)
@@ -156,7 +155,7 @@ end
156155
prob = ODEProblem(simple_ode, u0, tspan)
157156
sol = solve(prob, Vern9(); tstops=duplicate_tstops)
158157

159-
@test sol.retcode == :Success
158+
@test SciMLBase.successful_retcode(sol)
160159

161160
# Count how many times each tstop appears in solution
162161
count_05 = count(t -> abs(t - 0.5) < 1e-12, sol.t)
@@ -169,7 +168,7 @@ end
169168
# Test with StaticArrays too
170169
prob_static = ODEProblem(simple_ode, u0, tspan)
171170
sol_static = solve(prob_static, Vern9(); tstops=duplicate_tstops)
172-
@test sol_static.retcode == :Success
171+
@test SciMLBase.successful_retcode(sol_static)
173172
end
174173

175174
@testset "PresetTimeCallback with identical times" begin
@@ -180,14 +179,14 @@ end
180179

181180
function affect_preset!(integrator)
182181
push!(callback_times, integrator.t)
183-
integrator.u[1] += 0.1 # Small modification
182+
integrator.u += 0.1* integrator.u # Small modification
184183
end
185184

186185
function simple_growth(u, p, t)
187-
[0.1 * u[1]]
186+
SA[0.1 * u[1]]
188187
end
189188

190-
u0 = SVector{1}(1.0)
189+
u0 = SA[1.0]
191190
tspan = (0.0, 3.0)
192191

193192
# Define times where both tstops and callbacks should trigger
@@ -200,7 +199,7 @@ end
200199
sol = solve(prob, Vern9(); tstops=critical_times, callback=preset_cb,
201200
reltol=1e-10, abstol=1e-12)
202201

203-
@test sol.retcode == :Success
202+
@test SciMLBase.successful_retcode(sol)
204203

205204
# Verify all tstops were hit
206205
for time in critical_times
@@ -232,7 +231,7 @@ end
232231
sol_array = solve(prob_array, Vern9(); tstops=critical_times, callback=preset_cb_array,
233232
reltol=1e-10, abstol=1e-12)
234233

235-
@test sol_array.retcode == :Success
234+
@test SciMLBase.successful_retcode(sol_array)
236235
@test length(callback_times_array) == length(critical_times)
237236

238237
# Both should have triggered all events
@@ -242,7 +241,7 @@ end
242241
@testset "Tiny tstop step handling" begin
243242
# Test cases where tstop is very close to current time (dt < eps(t))
244243
function test_ode(u, p, t)
245-
[0.01 * u[1]]
244+
SA[0.01 * u[1]]
246245
end
247246

248247
u0 = SVector{1}(1.0)
@@ -253,9 +252,8 @@ end
253252

254253
for tiny_tstop in tiny_tstops
255254
prob = ODEProblem(test_ode, u0, tspan)
256-
sol = solve(prob, Vern9(); tstops=[tiny_tstop], save_everystep=false)
257-
258-
@test sol.retcode == :Success
255+
sol = solve(prob, Vern9(); tstops=[tiny_tstop])
256+
@test SciMLBase.successful_retcode(sol)
259257
@test any(abs.(sol.t .- tiny_tstop) .< 1e-14) # Should handle tiny tstop correctly
260258
end
261259
end
@@ -277,7 +275,7 @@ end
277275
prob = ODEProblem(oscillator, u0, tspan)
278276
sol = solve(prob, Vern9(); tstops=close_tstops, reltol=1e-12, abstol=1e-15)
279277

280-
@test sol.retcode == :Success
278+
@test SciMLBase.successful_retcode(sol)
281279

282280
# Should handle all close tstops without error
283281
# (Some might be deduplicated, but no errors should occur)
@@ -290,7 +288,7 @@ end
290288
@testset "Backward integration with tstop flags" begin
291289
# Test that the fix works for backward time integration
292290
function decay_ode(u, p, t)
293-
[-0.1 * u[1]]
291+
SA[-0.1 * u[1]]
294292
end
295293

296294
u0 = SVector{1}(1.0)
@@ -300,7 +298,7 @@ end
300298
prob = ODEProblem(decay_ode, u0, tspan)
301299
sol = solve(prob, Vern9(); tstops=tstops, reltol=1e-12, abstol=1e-15)
302300

303-
@test sol.retcode == :Success
301+
@test SciMLBase.successful_retcode(sol)
304302
for tstop in tstops
305303
@test tstop sol.t
306304
end
@@ -323,7 +321,7 @@ end
323321
[0.2 * u[1]] # Exponential growth
324322
end
325323

326-
u0 = SVector{1}(0.1) # Start below 0.5
324+
u0 = [0.1] # Start below 0.5
327325
tspan = (0.0, 10.0)
328326
tstops = [2.0, 4.0, 6.0, 8.0] # Regular tstops
329327

@@ -333,7 +331,7 @@ end
333331
sol = solve(prob, Vern9(); tstops=tstops, callback=continuous_cb,
334332
reltol=1e-10, abstol=1e-12)
335333

336-
@test sol.retcode == :Success
334+
@test SciMLBase.successful_retcode(sol)
337335

338336
# Should hit all tstops
339337
for tstop in tstops

0 commit comments

Comments
 (0)