Skip to content

Commit 51d3210

Browse files
authored
Improve test coverage (#91)
1 parent 657ea54 commit 51d3210

File tree

4 files changed

+59
-0
lines changed

4 files changed

+59
-0
lines changed

test/algorithms/Chalmet.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,23 @@ function test_vector_of_variables_objective()
206206
return
207207
end
208208

209+
function test_too_many_objectives()
210+
P = Float64[1 0 0 0; 0 1 0 0; 0 0 0 1; 0 0 1 0]
211+
model = MOA.Optimizer(HiGHS.Optimizer)
212+
MOI.set(model, MOA.Algorithm(), MOA.Chalmet())
213+
x = MOI.add_variables(model, 4)
214+
MOI.add_constraint.(model, x, MOI.GreaterThan(0.0))
215+
MOI.add_constraint.(model, x, MOI.LessThan(1.0))
216+
MOI.set(model, MOI.ObjectiveSense(), MOI.MAX_SENSE)
217+
f = MOI.Utilities.operate(vcat, Float64, P * x...)
218+
MOI.set(model, MOI.ObjectiveFunction{typeof(f)}(), f)
219+
@test_throws(
220+
ErrorException("Chalmet requires exactly two objectives"),
221+
MOI.optimize!(model),
222+
)
223+
return
224+
end
225+
209226
end
210227

211228
TestChalmet.run_tests()

test/algorithms/EpsilonConstraint.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,23 @@ function test_vector_of_variables_objective()
467467
return
468468
end
469469

470+
function test_too_many_objectives()
471+
P = Float64[1 0 0 0; 0 1 0 0; 0 0 0 1; 0 0 1 0]
472+
model = MOA.Optimizer(HiGHS.Optimizer)
473+
MOI.set(model, MOA.Algorithm(), MOA.EpsilonConstraint())
474+
x = MOI.add_variables(model, 4)
475+
MOI.add_constraint.(model, x, MOI.GreaterThan(0.0))
476+
MOI.add_constraint.(model, x, MOI.LessThan(1.0))
477+
MOI.set(model, MOI.ObjectiveSense(), MOI.MAX_SENSE)
478+
f = MOI.Utilities.operate(vcat, Float64, P * x...)
479+
MOI.set(model, MOI.ObjectiveFunction{typeof(f)}(), f)
480+
@test_throws(
481+
ErrorException("EpsilonConstraint requires exactly two objectives"),
482+
MOI.optimize!(model),
483+
)
484+
return
485+
end
486+
470487
end
471488

472489
TestEpsilonConstraint.run_tests()

test/algorithms/Hierarchical.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,11 @@ function test_knapsack()
3636
P = Float64[1 0 0 0; 0 1 1 0; 0 0 1 1; 0 1 0 0]
3737
model = MOA.Optimizer(HiGHS.Optimizer)
3838
MOI.set(model, MOA.Algorithm(), MOA.Hierarchical())
39+
@test MOI.supports(model, MOA.ObjectivePriority(1))
3940
MOI.set.(model, MOA.ObjectivePriority.(1:4), [2, 1, 1, 0])
41+
@test MOI.supports(model, MOA.ObjectiveWeight(1))
4042
MOI.set.(model, MOA.ObjectiveWeight.(1:4), [1, 0.5, 0.5, 1])
43+
@test MOI.supports(model, MOA.ObjectiveRelativeTolerance(1))
4144
MOI.set(model, MOA.ObjectiveRelativeTolerance(1), 0.1)
4245
MOI.set(model, MOI.Silent(), true)
4346
x = MOI.add_variables(model, 4)

test/algorithms/Lexicographic.jl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ function test_knapsack()
2727
model = MOA.Optimizer(HiGHS.Optimizer)
2828
MOI.set(model, MOA.Algorithm(), MOA.Lexicographic())
2929
@test MOI.supports(model, MOA.LexicographicAllPermutations())
30+
@test MOI.supports(model, MOA.ObjectiveRelativeTolerance(1))
3031
MOI.set(model, MOA.LexicographicAllPermutations(), false)
3132
MOI.set(model, MOA.ObjectiveRelativeTolerance(1), 0.1)
3233
MOI.set(model, MOI.Silent(), true)
@@ -175,6 +176,27 @@ function test_warn_all_permutations()
175176
return
176177
end
177178

179+
function test_knapsack_time_limit()
180+
P = Float64[1 0 0 0; 0 1 0 0; 0 0 0 1; 0 0 1 0]
181+
model = MOA.Optimizer(HiGHS.Optimizer)
182+
MOI.set(model, MOA.Algorithm(), MOA.Lexicographic())
183+
MOI.set(model, MOA.LexicographicAllPermutations(), false)
184+
MOI.set(model, MOA.ObjectiveRelativeTolerance(1), 0.1)
185+
MOI.set(model, MOI.Silent(), true)
186+
x = MOI.add_variables(model, 4)
187+
MOI.add_constraint.(model, x, MOI.GreaterThan(0.0))
188+
MOI.add_constraint.(model, x, MOI.LessThan(1.0))
189+
MOI.set(model, MOI.ObjectiveSense(), MOI.MAX_SENSE)
190+
f = MOI.Utilities.operate(vcat, Float64, P * x...)
191+
f.constants[4] = 1_000.0
192+
MOI.set(model, MOI.ObjectiveFunction{typeof(f)}(), f)
193+
MOI.add_constraint(model, sum(1.0 * x[i] for i in 1:4), MOI.LessThan(2.0))
194+
MOI.set(model, MOI.TimeLimitSec(), 0.0)
195+
MOI.optimize!(model)
196+
@test MOI.get(model, MOI.TerminationStatus()) == MOI.TIME_LIMIT
197+
return
198+
end
199+
178200
end
179201

180202
TestLexicographic.run_tests()

0 commit comments

Comments
 (0)