Skip to content

Commit 450e9c8

Browse files
authored
Merge pull request #158 from JuliaControl/vd_code_tests
update test for new VS code test framework
2 parents 2845aaa + 9a0aadf commit 450e9c8

6 files changed

+110
-110
lines changed

Project.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,15 @@ PrecompileTools = "1"
2828
ProgressLogging = "0.1"
2929
Random = "1.6"
3030
RecipesBase = "1"
31+
TestItemRunner = "1.1"
3132
julia = "1.10"
3233

3334
[extras]
3435
DAQP = "c47d62df-3981-49c8-9651-128b1cd08617"
3536
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
3637
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
3738
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
39+
TestItemRunner = "f8b46487-2199-4994-9208-9a1283c18c0a"
3840

3941
[targets]
40-
test = ["Test", "Documenter", "Plots", "DAQP"]
42+
test = ["Test", "TestItemRunner", "Documenter", "Plots", "DAQP"]

test/runtests.jl

+20-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,26 @@ using LinearAlgebra
77
using Random: randn
88
using JuMP, OSQP, Ipopt, DAQP, ForwardDiff
99
using Plots
10-
using Test
10+
using Test, TestItemRunner
11+
12+
@run_package_tests
13+
14+
#@testitem "ModelPredictiveControl.jl" begin
15+
16+
@testsnippet SetupMPCtests begin
17+
using ControlSystemsBase, LinearAlgebra
18+
using Random: randn
19+
using JuMP, OSQP, Ipopt, DAQP, ForwardDiff
20+
using Plots
21+
Ts = 400.0
22+
sys = [ tf(1.90,[1800.0,1]) tf(1.90,[1800.0,1]) tf(1.90,[1800.0,1]);
23+
tf(-0.74,[800.0,1]) tf(0.74,[800.0,1]) tf(-0.74,[800.0,1]) ]
24+
sys_ss = minreal(ss(sys))
25+
Gss = c2d(sys_ss[:,1:2], Ts, :zoh)
26+
Gss2 = c2d(sys_ss[:,1:2], 0.5Ts, :zoh)
27+
end
28+
1129

12-
@testset "ModelPredictiveControl.jl" begin
1330
include("test_sim_model.jl")
1431
include("test_state_estim.jl")
1532
include("test_predictive_control.jl")
@@ -29,6 +46,6 @@ DocMeta.setdocmeta!(
2946
doctest(ModelPredictiveControl, testset="DocTest")
3047
ENV["JULIA_DEBUG"] = old_debug_level
3148

32-
end;
49+
#end;
3350

3451
nothing

test/test_plot_sim.jl

+6-10
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
Ts = 400.0
2-
sys = [ tf(1.90,[1800.0,1]) tf(1.90,[1800.0,1]) tf(1.90,[1800.0,1]);
3-
tf(-0.74,[800.0,1]) tf(0.74,[800.0,1]) tf(-0.74,[800.0,1]) ]
4-
5-
@testset "SimModel quick simulation" begin
1+
@testitem "SimModel quick simulation" setup=[SetupMPCtests] begin
62
model = LinModel(sys, Ts, i_d=[3])
73
res = sim!(model, 15)
84
display(res)
@@ -21,7 +17,7 @@ sys = [ tf(1.90,[1800.0,1]) tf(1.90,[1800.0,1]) tf(1.90,[1800.0,1]);
2117
@test_throws ArgumentError SimResult(model, [res.U_data model.uop], res.Y_data, res.D_data)
2218
end
2319

24-
@testset "SimModel Plots" begin
20+
@testitem "SimModel Plots" setup=[SetupMPCtests] begin
2521
model = LinModel(sys, Ts, i_d=[3])
2622
res = sim!(model, 15, [1, 3], [-10])
2723
p = plot(res, plotx=true)
@@ -45,7 +41,7 @@ end
4541
@test p[3][1][:y] res.X_data[4, :]
4642
end
4743

48-
@testset "StateEstimator quick simulation" begin
44+
@testitem "StateEstimator quick simulation" setup=[SetupMPCtests] begin
4945
estim = SteadyKalmanFilter(LinModel(sys, Ts, i_d=[3]))
5046
res = sim!(estim, 15)
5147
@test isa(res.obj, SteadyKalmanFilter)
@@ -67,7 +63,7 @@ end
6763
@test res_man.X̂_data res.X̂_data
6864
end
6965

70-
@testset "StateEstimator Plots" begin
66+
@testitem "StateEstimator Plots" setup=[SetupMPCtests] begin
7167
estim = MovingHorizonEstimator(LinModel(sys, Ts, i_d=[3]), He=5)
7268
estim = setconstraint!(estim, x̂min=[-100,-101,-102,-103,-Inf,-Inf])
7369
estim = setconstraint!(estim, x̂max=[+100,+101,+102,+103,+Inf,+Inf])
@@ -124,7 +120,7 @@ end
124120
@test all(p7[end-2][3][:y] .≈ +103)
125121
end
126122

127-
@testset "PredictiveController quick simulation" begin
123+
@testitem "PredictiveController quick simulation" setup=[SetupMPCtests] begin
128124
mpc1 = LinMPC(LinModel(sys, Ts, i_d=[3]))
129125
res = sim!(mpc1, 15)
130126
@test isa(res.obj, LinMPC)
@@ -158,7 +154,7 @@ end
158154
@test res_man.Ry_data res.Ry_data
159155
end
160156

161-
@testset "PredictiveController Plots" begin
157+
@testitem "PredictiveController Plots" setup=[SetupMPCtests] begin
162158
estim = MovingHorizonEstimator(LinModel(sys, Ts, i_d=[3]), He=5)
163159
estim = setconstraint!(estim, x̂min=[-100,-101,-102,-103,-104,-105])
164160
estim = setconstraint!(estim, x̂max=[+100,+101,+102,+103,+104,+105])

0 commit comments

Comments
 (0)