Skip to content

Commit 6869ad0

Browse files
authored
[Utilities] improve code coverage (#2660)
1 parent 07da8b3 commit 6869ad0

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

test/Utilities/copy.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,6 +1106,22 @@ function test_index_map()
11061106
return
11071107
end
11081108

1109+
function test_copy_names_unsupported()
1110+
src = MOI.Utilities.Model{Float64}()
1111+
MOI.set(src, MOI.Name(), "Abc")
1112+
x = MOI.add_variable(src)
1113+
MOI.set(src, MOI.VariableName(), x, "x")
1114+
c = MOI.add_constraint(src, 1.0 * x, MOI.LessThan(1.0))
1115+
MOI.set(src, MOI.ConstraintName(), c, "c")
1116+
dest = MOI.Utilities.MockOptimizer(
1117+
MOI.Utilities.Model{Float64}();
1118+
supports_names = false,
1119+
)
1120+
index_map = MOI.copy_to(dest, src)
1121+
@test MOI.get(dest, MOI.VariableName(), index_map[x]) == ""
1122+
return
1123+
end
1124+
11091125
end # module
11101126

11111127
TestCopy.runtests()

test/Utilities/mockoptimizer.jl

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,33 @@ function test_modify_not_allowed()
258258
return
259259
end
260260

261+
function test_get_fallback_constraint_dual()
262+
model = MOI.Utilities.MockOptimizer(MOI.Utilities.Model{Float64}())
263+
x = MOI.add_variables(model, 2)
264+
MOI.set(model, MOI.ObjectiveSense(), MOI.MIN_SENSE)
265+
f = MOI.VectorOfVariables(x)
266+
MOI.set(model, MOI.ObjectiveFunction{typeof(f)}(), f)
267+
c = MOI.add_constraint(model, f, MOI.Nonnegatives(2))
268+
@test_throws(
269+
ErrorException(
270+
"Fallback getter for variable constraint dual does not support objective function of type $(MOI.VectorOfVariables). Please report this issue to the solver wrapper package.",
271+
),
272+
MOI.Utilities.get_fallback(model, MOI.ConstraintDual(), c),
273+
)
274+
return
275+
end
276+
277+
struct SetByOptimizeAttribute <: MOI.AbstractOptimizerAttribute end
278+
279+
MOI.is_set_by_optimize(::SetByOptimizeAttribute) = true
280+
281+
function test_is_set_by_optimize_optimizer_attribute()
282+
model = MOI.Utilities.MockOptimizer(MOI.Utilities.Model{Float64}())
283+
MOI.set(model, SetByOptimizeAttribute(), 1.23)
284+
@test MOI.get(model, SetByOptimizeAttribute()) == 1.23
285+
return
286+
end
287+
261288
end # module
262289

263290
TestMockOptimizer.runtests()

0 commit comments

Comments
 (0)