Skip to content

Commit

Permalink
Merge pull request #158 from JuliaControl/vd_code_tests
Browse files Browse the repository at this point in the history
update test for new VS code test framework
  • Loading branch information
franckgaga authored Feb 14, 2025
2 parents 2845aaa + 9a0aadf commit 450e9c8
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 110 deletions.
4 changes: 3 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ PrecompileTools = "1"
ProgressLogging = "0.1"
Random = "1.6"
RecipesBase = "1"
TestItemRunner = "1.1"
julia = "1.10"

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

[targets]
test = ["Test", "Documenter", "Plots", "DAQP"]
test = ["Test", "TestItemRunner", "Documenter", "Plots", "DAQP"]
23 changes: 20 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,26 @@ using LinearAlgebra
using Random: randn
using JuMP, OSQP, Ipopt, DAQP, ForwardDiff
using Plots
using Test
using Test, TestItemRunner

@run_package_tests

#@testitem "ModelPredictiveControl.jl" begin

@testsnippet SetupMPCtests begin
using ControlSystemsBase, LinearAlgebra
using Random: randn
using JuMP, OSQP, Ipopt, DAQP, ForwardDiff
using Plots
Ts = 400.0
sys = [ tf(1.90,[1800.0,1]) tf(1.90,[1800.0,1]) tf(1.90,[1800.0,1]);
tf(-0.74,[800.0,1]) tf(0.74,[800.0,1]) tf(-0.74,[800.0,1]) ]
sys_ss = minreal(ss(sys))
Gss = c2d(sys_ss[:,1:2], Ts, :zoh)
Gss2 = c2d(sys_ss[:,1:2], 0.5Ts, :zoh)
end


@testset "ModelPredictiveControl.jl" begin
include("test_sim_model.jl")
include("test_state_estim.jl")
include("test_predictive_control.jl")
Expand All @@ -29,6 +46,6 @@ DocMeta.setdocmeta!(
doctest(ModelPredictiveControl, testset="DocTest")
ENV["JULIA_DEBUG"] = old_debug_level

end;
#end;

nothing
16 changes: 6 additions & 10 deletions test/test_plot_sim.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
Ts = 400.0
sys = [ tf(1.90,[1800.0,1]) tf(1.90,[1800.0,1]) tf(1.90,[1800.0,1]);
tf(-0.74,[800.0,1]) tf(0.74,[800.0,1]) tf(-0.74,[800.0,1]) ]

@testset "SimModel quick simulation" begin
@testitem "SimModel quick simulation" setup=[SetupMPCtests] begin
model = LinModel(sys, Ts, i_d=[3])
res = sim!(model, 15)
display(res)
Expand All @@ -21,7 +17,7 @@ sys = [ tf(1.90,[1800.0,1]) tf(1.90,[1800.0,1]) tf(1.90,[1800.0,1]);
@test_throws ArgumentError SimResult(model, [res.U_data model.uop], res.Y_data, res.D_data)
end

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

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

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

@testset "PredictiveController quick simulation" begin
@testitem "PredictiveController quick simulation" setup=[SetupMPCtests] begin
mpc1 = LinMPC(LinModel(sys, Ts, i_d=[3]))
res = sim!(mpc1, 15)
@test isa(res.obj, LinMPC)
Expand Down Expand Up @@ -158,7 +154,7 @@ end
@test res_man.Ry_data res.Ry_data
end

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

0 comments on commit 450e9c8

Please sign in to comment.