Skip to content

Commit f1415d7

Browse files
committed
test: improve coverage of error termination status
1 parent 6f644d5 commit f1415d7

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

test/2_test_state_estim.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,6 +1035,16 @@ end
10351035
info = getinfo(mhe5)
10361036
@test info[:x̂] x̂ atol=1e-9
10371037
@test info[:Ŷ][end-1:end] [50, 30] atol=1e-9
1038+
1039+
# coverage of the branch with error termination status (with an infeasible problem):
1040+
mhe_infeas = MovingHorizonEstimator(nonlinmodel, He=1, Cwt=Inf)
1041+
mhe_infeas = setconstraint!(mhe_infeas, v̂min=[1, 1], v̂max=[-1, -1])
1042+
@test_logs(
1043+
(:error, "MHE terminated without solution: estimation in open-loop "*
1044+
"(more info in debug log)"),
1045+
preparestate!(mhe_infeas, [0, 0], [0])
1046+
)
1047+
10381048
# for coverage of NLP functions, the univariate syntax of JuMP.@operator
10391049
mhe6 = MovingHorizonEstimator(nonlinmodel, He=1, Cwt=Inf)
10401050
setconstraint!(mhe6, v̂min=[-51,-52], v̂max=[53,54])

test/3_test_predictive_control.jl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,16 @@ end
121121
ΔU_diff = diff(getinfo(mpc7)[:U])
122122
@test ΔU_diff[[2, 4, 5, 7, 8, 9]] zeros(6) atol=1e-9
123123

124+
# coverage of the branch with error termination status (with an infeasible problem):
125+
mpc_infeas = LinMPC(linmodel2, Hp=1, Hc=1, Cwt=Inf)
126+
mpc_infeas = setconstraint!(mpc_infeas, umin=[+1], umax=[-1])
127+
preparestate!(mpc_infeas, [0], [0])
128+
@test_logs(
129+
(:error, "MPC terminated without solution: returning last solution shifted "*
130+
"(more info in debug log)"),
131+
moveinput!(mpc_infeas, [0], [0])
132+
)
133+
124134
@test_throws DimensionMismatch moveinput!(mpc1, [0,0,0])
125135
@test_throws DimensionMismatch moveinput!(mpc1, [0], [0,0])
126136
@test_throws DimensionMismatch moveinput!(mpc1; D̂ = fill(0, mpc1.Hp+1))
@@ -823,6 +833,17 @@ end
823833
ΔU_diff = diff(getinfo(nmpc11)[:U])
824834
@test ΔU_diff[[2, 4, 5, 7, 8, 9]] zeros(6) atol=1e-9
825835

836+
# coverage of the branch with error termination status (with an infeasible problem):
837+
nmpc_infeas = NonLinMPC(nonlinmodel, Hp=1, Hc=1, Cwt=Inf)
838+
nmpc_infeas = setconstraint!(nmpc_infeas, umin=[+1], umax=[-1])
839+
preparestate!(nmpc_infeas, [0], [0])
840+
@test_logs(
841+
(:error, "MPC terminated without solution: returning last solution shifted "*
842+
"(more info in debug log)"),
843+
moveinput!(nmpc_infeas, [0], [0])
844+
)
845+
846+
826847
@test_nowarn ModelPredictiveControl.info2debugstr(info)
827848
end
828849

0 commit comments

Comments
 (0)