Skip to content

Commit e24cf6a

Browse files
authored
refactor: :Success -> Success (i.e ReturnCode.Success) (#149)
1 parent a4619b9 commit e24cf6a

File tree

13 files changed

+126
-108
lines changed

13 files changed

+126
-108
lines changed

test/Blocks/continuous.jl

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
using ModelingToolkit, ModelingToolkitStandardLibrary, OrdinaryDiffEq
22
using ModelingToolkitStandardLibrary.Blocks
3+
using OrdinaryDiffEq: ReturnCode.Success
34

45
@parameters t
56

67
#=
78
Testing strategy:
89
The general strategy is to test systems using simple intputs where the solution
910
is known on closed form. For algebraic systems (without differential variables),
10-
an integrator with a constant input is often used together with the system under test.
11+
an integrator with a constant input is often used together with the system under test.
1112
=#
1213

1314
@testset "Constant" begin
@@ -17,9 +18,9 @@ an integrator with a constant input is often used together with the system under
1718
sys = structural_simplify(iosys)
1819
prob = ODEProblem(sys, Pair[int.x => 1.0], (0.0, 1.0))
1920
sol = solve(prob, Rodas4())
20-
@test sol.retcode == :Success
21+
@test sol.retcode == Success
2122
@test all(sol[c.output.u] .≈ 1)
22-
@test sol[int.output.u][end] .≈ 2 # expected solution
23+
@test sol[int.output.u][end] .≈ 2 # expected solution
2324
end
2425

2526
@testset "Derivative" begin
@@ -35,7 +36,7 @@ end
3536
sys = structural_simplify(iosys)
3637
prob = ODEProblem(sys, Pair[int.x => 0.0], (0.0, 10.0))
3738
sol = solve(prob, Rodas4())
38-
@test sol.retcode == :Success
39+
@test sol.retcode == Success
3940
@test all(isapprox.(sol[source.output.u], sol[int.output.u], atol = 1e-1))
4041
end
4142

@@ -49,7 +50,7 @@ end
4950
sys = structural_simplify(iosys)
5051
prob = ODEProblem(sys, Pair[], (0.0, 100.0))
5152
sol = solve(prob, Rodas4())
52-
@test sol.retcode == :Success
53+
@test sol.retcode == Success
5354
@test sol[pt1.output.u]pt1_func.(sol.t, k, T) atol=1e-3
5455

5556
# Test highpass feature
@@ -58,7 +59,7 @@ end
5859
sys = structural_simplify(iosys)
5960
prob = ODEProblem(sys, Pair[], (0.0, 100.0))
6061
sol = solve(prob, Rodas4())
61-
@test sol.retcode == :Success
62+
@test sol.retcode == Success
6263
@test sol[pt1.output.u]k .- pt1_func.(sol.t, k, T) atol=1e-3
6364
end
6465

@@ -82,7 +83,7 @@ end
8283
sys = structural_simplify(iosys)
8384
prob = ODEProblem(sys, Pair[], (0.0, 100.0))
8485
sol = solve(prob, Rodas4())
85-
@test sol.retcode == :Success
86+
@test sol.retcode == Success
8687
@test sol[pt2.output.u]pt2_func.(sol.t, k, w, d) atol=1e-3
8788
end
8889

@@ -101,7 +102,7 @@ end
101102
sys = structural_simplify(model)
102103
prob = ODEProblem(sys, Pair[], (0.0, 100.0))
103104
sol = solve(prob, Rodas4())
104-
@test sol.retcode == :Success
105+
@test sol.retcode == Success
105106
# initial condition
106107
@test sol[ss.x[1]][1]0 atol=1e-3
107108
@test sol[ss.x[2]][1]0 atol=1e-3
@@ -121,7 +122,7 @@ end
121122
sys = structural_simplify(model)
122123
prob = ODEProblem(sys, Pair[], (0.0, 100.0))
123124
sol = solve(prob, Rodas4())
124-
@test sol.retcode == :Success
125+
@test sol.retcode == Success
125126

126127
@test sol[ss.x[1]][end ÷ 2]0 atol=1e-3 # Test that x did not move
127128
@test sol[ss.x[1]][end]0 atol=1e-3 # Test that x did not move
@@ -158,7 +159,7 @@ end
158159
sys = structural_simplify(model)
159160
prob = ODEProblem(sys, Pair[], (0.0, 100.0))
160161
sol = solve(prob, Rodas4())
161-
@test sol.retcode == :Success
162+
@test sol.retcode == Success
162163
@test all(isapprox.(sol[ref.output.u], re_val, atol = 1e-3)) # check reference
163164
@test sol[plant.output.u][end]re_val atol=1e-3 # zero control error after 100s
164165
end
@@ -180,7 +181,7 @@ end
180181
sys = structural_simplify(model)
181182
prob = ODEProblem(sys, Pair[], (0.0, 100.0))
182183
sol = solve(prob, Rodas4())
183-
@test sol.retcode == :Success
184+
@test sol.retcode == Success
184185
@test all(isapprox.(sol[ref.output.u], re_val, atol = 1e-3)) # check reference
185186
@test sol[plant.output.u][end]re_val atol=1e-3 # zero control error after 100s
186187

@@ -197,7 +198,7 @@ end
197198
sys = structural_simplify(model)
198199
prob = ODEProblem(sys, Pair[], (0.0, 100.0))
199200
sol = solve(prob, Rodas4())
200-
@test sol.retcode == :Success
201+
@test sol.retcode == Success
201202
@test all(isapprox.(sol[ref.output.u], re_val, atol = 1e-3)) # check reference
202203
@test sol[plant.output.u][end]re_val atol=1e-3 # zero control error after 100s
203204
end
@@ -215,7 +216,7 @@ end
215216
sys = structural_simplify(model)
216217
prob = ODEProblem(sys, Pair[], (0.0, 100.0))
217218
sol = solve(prob, Rodas4())
218-
@test sol.retcode == :Success
219+
@test sol.retcode == Success
219220
@test all(isapprox.(sol[ref.output.u], re_val, atol = 1e-3)) # check reference
220221
@test sol[plant.output.u][end] > 1 # without I there will be a steady-state error
221222
end
@@ -262,8 +263,8 @@ end
262263
sol = solve(prob, Rodas4())
263264
end
264265

265-
@test sol.retcode == :Success
266-
@test sol_lim.retcode == :Success
266+
@test sol.retcode == Success
267+
@test sol_lim.retcode == ReturnCode.Success
267268
@test all(isapprox.(sol[ref.output.u], re_val, atol = 1e-3)) # check reference
268269
@test all(isapprox.(sol_lim[ref.output.u], re_val, atol = 1e-3)) # check reference
269270
@test sol[plant.output.u][end]re_val atol=1e-3 # zero control error after 100s
@@ -292,7 +293,7 @@ end
292293
sol = solve(prob, Rodas4())
293294

294295
# Plots.plot(sol, vars=[plant.output.u, plant.input.u])
295-
@test sol.retcode == :Success
296+
@test sol.retcode == Success
296297
@test all(isapprox.(sol[ref.output.u], re_val, atol = 1e-3)) # check reference
297298
@test sol[plant.output.u][end]re_val atol=1e-3 # zero control error after 100s
298299
@test all(-1.5 .<= sol[pid_controller.ctr_output.u] .<= 1.5) # test limit
@@ -312,7 +313,7 @@ end
312313
sol = solve(prob, Rodas4())
313314

314315
# Plots.plot(sol, vars=[plant.output.u, plant.input.u])
315-
@test sol.retcode == :Success
316+
@test sol.retcode == Success
316317
@test all(isapprox.(sol[ref.output.u], re_val, atol = 1e-3)) # check reference
317318
@test sol[plant.output.u][end]re_val atol=1e-3 # zero control error after 100s
318319
@test all(-1.5 .<= sol[pid_controller.ctr_output.u] .<= 1.5) # test limit
@@ -332,7 +333,7 @@ end
332333
sol = solve(prob, Rodas4())
333334

334335
# Plots.plot(sol, vars=[plant.output.u, plant.input.u])
335-
@test sol.retcode == :Success
336+
@test sol.retcode == Success
336337
@test all(isapprox.(sol[ref.output.u], re_val, atol = 1e-3)) # check reference
337338
@test sol[plant.output.u][end] > 0.5 # without I there will be a steady-state error
338339
@test all(-1.5 .<= sol[pid_controller.ctr_output.u] .<= 1.5) # test limit
@@ -353,7 +354,7 @@ end
353354
sol = solve(prob, Rodas4())
354355

355356
# Plots.plot(sol, vars=[plant.output.u, plant.input.u])
356-
@test sol.retcode == :Success
357+
@test sol.retcode == Success
357358
@test all(isapprox.(sol[ref.output.u], re_val, atol = 1e-3)) # check reference
358359
sol[pid_controller.addP.output.u] == -sol[pid_controller.measurement.u]
359360
@test sol[plant.output.u][end]re_val atol=1e-3 # zero control error after 100s
@@ -374,7 +375,7 @@ end
374375
sol = solve(prob, Rodas4())
375376

376377
# Plots.plot(sol, vars=[plant.output.u, plant.input.u])
377-
@test sol.retcode == :Success
378+
@test sol.retcode == Success
378379
@test all(isapprox.(sol[ref.output.u], re_val, atol = 1e-3)) # check reference
379380
@test sol[plant.output.u][end]re_val atol=1e-3 # zero control error after 100s
380381
sol[pid_controller.addD.output.u] == -sol[pid_controller.measurement.u]
@@ -396,7 +397,7 @@ end
396397
sol = solve(prob, Rodas4())
397398

398399
# Plots.plot(sol, vars=[plant.output.u, plant.input.u])
399-
@test sol.retcode == :Success
400+
@test sol.retcode == Success
400401
@test all(isapprox.(sol[ref.output.u], re_val, atol = 1e-3)) # check reference
401402
@test sol[plant.output.u][end]re_val atol=1e-3 # zero control error after 100s
402403
@test all(-1.5 .<= sol[pid_controller.ctr_output.u] .<= 1.5) # test limit

test/Blocks/math.jl

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ using ModelingToolkitStandardLibrary.Blocks
22
using ModelingToolkit, OrdinaryDiffEq, Test
33
using ModelingToolkitStandardLibrary.Blocks: _clamp, _dead_zone
44
using ModelingToolkit: inputs, unbound_inputs, bound_inputs
5+
using OrdinaryDiffEq: ReturnCode.Success
56

67
@parameters t
78

@@ -19,7 +20,7 @@ using ModelingToolkit: inputs, unbound_inputs, bound_inputs
1920
sol = solve(prob, Rodas4())
2021

2122
@test isequal(unbound_inputs(sys), [])
22-
@test sol.retcode == :Success
23+
@test sol.retcode == Success
2324
@test all(sol[c.output.u] .≈ 1)
2425
@test sol[int.output.u][end] 2 # expected solution after 1s
2526
end
@@ -43,7 +44,7 @@ end
4344

4445
sol = solve(prob, Rodas4())
4546
@test isequal(unbound_inputs(sys), [])
46-
@test sol.retcode == :Success
47+
@test sol.retcode == Success
4748
@test sol[int.output.u][end] 2 # expected solution after 1s
4849
end
4950

@@ -63,7 +64,7 @@ end
6364
prob = ODEProblem(sys, Pair[int.x => 0.0], (0.0, 1.0))
6465
sol = solve(prob, Rodas4())
6566
@test isequal(unbound_inputs(sys), [])
66-
@test sol.retcode == :Success
67+
@test sol.retcode == Success
6768
@test sol[add.output.u] 1 .+ sin.(2 * pi * sol.t)
6869

6970
@testset "weights" begin
@@ -81,7 +82,7 @@ end
8182
prob = ODEProblem(sys, Pair[int.x => 0.0], (0.0, 1.0))
8283
sol = solve(prob, Rodas4())
8384
@test isequal(unbound_inputs(sys), [])
84-
@test sol.retcode == :Success
85+
@test sol.retcode == Success
8586
@test sol[add.output.u] k1 .* 1 .+ k2 .* sin.(2 * pi * sol.t)
8687
end
8788
end
@@ -104,7 +105,7 @@ end
104105
prob = ODEProblem(sys, Pair[int.x => 0.0], (0.0, 1.0))
105106
sol = solve(prob, Rodas4())
106107
@test isequal(unbound_inputs(sys), [])
107-
@test sol.retcode == :Success
108+
@test sol.retcode == Success
108109
@test sol[add.output.u] 1 .+ sin.(2 * pi * sol.t) .+ sin.(2 * pi * 2 * sol.t)
109110

110111
@testset "weights" begin
@@ -124,7 +125,7 @@ end
124125
prob = ODEProblem(sys, Pair[int.x => 0.0], (0.0, 1.0))
125126
sol = solve(prob, Rodas4())
126127
@test isequal(unbound_inputs(sys), [])
127-
@test sol.retcode == :Success
128+
@test sol.retcode == Success
128129
@test sol[add.output.u]
129130
k1 .* 1 .+ k2 .* sin.(2 * pi * sol.t) .+ k3 .* sin.(2 * pi * 2 * sol.t)
130131
end
@@ -146,7 +147,7 @@ end
146147
prob = ODEProblem(sys, Pair[int.x => 0.0], (0.0, 1.0))
147148
sol = solve(prob, Rodas4())
148149
@test isequal(unbound_inputs(sys), [])
149-
@test sol.retcode == :Success
150+
@test sol.retcode == Success
150151
@test sol[prod.output.u] 2 * sin.(2 * pi * sol.t)
151152
end
152153

@@ -166,7 +167,7 @@ end
166167
prob = ODEProblem(sys, Pair[int.x => 0.0], (0.0, 1.0))
167168
sol = solve(prob, Rodas4())
168169
@test isequal(unbound_inputs(sys), [])
169-
@test sol.retcode == :Success
170+
@test sol.retcode == Success
170171
@test sol[div.output.u] sin.(2 * pi * sol.t) ./ 2
171172
end
172173

@@ -184,7 +185,7 @@ end
184185
prob = ODEProblem(sys, Pair[int.x => 0.0], (0.0, 1.0))
185186
sol = solve(prob, Rodas4())
186187
@test isequal(unbound_inputs(sys), [])
187-
@test sol.retcode == :Success
188+
@test sol.retcode == Success
188189
@test sol[absb.output.u] abs.(sin.(2 * pi * sol.t))
189190
end
190191

@@ -228,7 +229,7 @@ end
228229
prob = ODEProblem(sys, Pair[int.x => 0.0], (0.0, 1.0))
229230
sol = solve(prob, Rodas4())
230231
@test isequal(unbound_inputs(sys), [])
231-
@test sol.retcode == :Success
232+
@test sol.retcode == Success
232233
@test sol[b.output.u] func.(sol[source.output.u])
233234
end
234235

@@ -246,7 +247,7 @@ end
246247
prob = ODEProblem(sys, Pair[int.x => 0.0, b.input.u => 2.0], (0.0, 1.0))
247248
sol = solve(prob, Rodas4())
248249
@test isequal(unbound_inputs(sys), [])
249-
@test sol.retcode == :Success
250+
@test sol.retcode == Success
250251
@test sol[b.output.u] func.(sol[source.output.u])
251252
end
252253
end
@@ -271,6 +272,6 @@ end
271272
@test isequal(unbound_inputs(sys), [])
272273
@test all(map(u -> u in Set([b.input1.u, b.input2.u, int.input.u]), bound_inputs(sys)))
273274
@test all(map(u -> u in Set([b.input1.u, b.input2.u, int.input.u]), inputs(sys)))
274-
@test sol.retcode == :Success
275+
@test sol.retcode == Success
275276
@test sol[int.input.u] atan.(sol[c1.output.u], sol[c2.output.u])
276277
end

test/Blocks/nonlinear.jl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using ModelingToolkit, OrdinaryDiffEq
22
using ModelingToolkitStandardLibrary.Blocks
33
using ModelingToolkitStandardLibrary.Blocks: _clamp, _dead_zone
4+
using OrdinaryDiffEq: ReturnCode.Success
45

56
@parameters t
67

@@ -19,7 +20,7 @@ using ModelingToolkitStandardLibrary.Blocks: _clamp, _dead_zone
1920
prob = ODEProblem(sys, [int.x => 1.0], (0.0, 1.0))
2021

2122
sol = solve(prob, Rodas4())
22-
@test sol.retcode == :Success
23+
@test sol.retcode == Success
2324
@test sol[int.output.u][end] 2
2425
@test sol[sat.output.u][end] 0.8
2526
end
@@ -40,7 +41,7 @@ using ModelingToolkitStandardLibrary.Blocks: _clamp, _dead_zone
4041
prob = ODEProblem(sys, Pair[], (0.0, 10.0))
4142

4243
sol = solve(prob, Rodas4())
43-
@test sol.retcode == :Success
44+
@test sol.retcode == Success
4445
@test all(abs.(sol[lim.output.u]) .<= 0.5)
4546
@test all(isapprox.(sol[lim.output.u], _clamp.(sol[source.output.u], y_min, y_max),
4647
atol = 1e-2))
@@ -66,7 +67,7 @@ end
6667
prob = ODEProblem(sys, [int.x => 1.0], (0.0, 1.0))
6768
sol = solve(prob, Rodas4())
6869

69-
@test sol.retcode == :Success
70+
@test sol.retcode == Success
7071
@test all(sol[int.output.u][end] .≈ 2)
7172
end
7273

@@ -85,7 +86,7 @@ end
8586
prob = ODEProblem(sys, [int.x => 1.0], (0.0, 10.0))
8687
sol = solve(prob, Rodas4())
8788

88-
@test sol.retcode == :Success
89+
@test sol.retcode == Success
8990
@test all(sol[dz.output.u] .<= 2)
9091
@test all(sol[dz.output.u] .>= -1)
9192
@test all(isapprox.(sol[dz.output.u],
@@ -111,7 +112,7 @@ end
111112

112113
tS = 0.01
113114
sol = solve(prob, Rodas4(), saveat = tS, abstol = 1e-10, reltol = 1e-10)
114-
@test sol.retcode == :Success
115+
@test sol.retcode == Success
115116
@test all(abs.(sol[rl.output.u]) .<= 0.51)
116117
@test all(-1 - 1e-5 .<= diff(sol[rl.output.u]) ./ tS .<= 1 + 1e-5) # just an approximation
117118
end

0 commit comments

Comments
 (0)