From b310db115776536d62b145b2c2196c4f97d1d2d8 Mon Sep 17 00:00:00 2001 From: odow Date: Tue, 25 Feb 2025 17:17:07 +1300 Subject: [PATCH] [Utilities] improve code coverage --- test/Utilities/copy.jl | 16 ++++++++++++++++ test/Utilities/mockoptimizer.jl | 27 +++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/test/Utilities/copy.jl b/test/Utilities/copy.jl index 1adc0a4034..ef3c8671a1 100644 --- a/test/Utilities/copy.jl +++ b/test/Utilities/copy.jl @@ -1106,6 +1106,22 @@ function test_index_map() return end +function test_copy_names_unsupported() + src = MOI.Utilities.Model{Float64}() + MOI.set(src, MOI.Name(), "Abc") + x = MOI.add_variable(src) + MOI.set(src, MOI.VariableName(), x, "x") + c = MOI.add_constraint(src, 1.0 * x, MOI.LessThan(1.0)) + MOI.set(src, MOI.ConstraintName(), c, "c") + dest = MOI.Utilities.MockOptimizer( + MOI.Utilities.Model{Float64}(); + supports_names = false, + ) + index_map = MOI.copy_to(dest, src) + @test MOI.get(dest, MOI.VariableName(), index_map[x]) == "" + return +end + end # module TestCopy.runtests() diff --git a/test/Utilities/mockoptimizer.jl b/test/Utilities/mockoptimizer.jl index c7f76b8cc2..46d30b0243 100644 --- a/test/Utilities/mockoptimizer.jl +++ b/test/Utilities/mockoptimizer.jl @@ -258,6 +258,33 @@ function test_modify_not_allowed() return end +function test_get_fallback_constraint_dual() + model = MOI.Utilities.MockOptimizer(MOI.Utilities.Model{Float64}()) + x = MOI.add_variables(model, 2) + MOI.set(model, MOI.ObjectiveSense(), MOI.MIN_SENSE) + f = MOI.VectorOfVariables(x) + MOI.set(model, MOI.ObjectiveFunction{typeof(f)}(), f) + c = MOI.add_constraint(model, f, MOI.Nonnegatives(2)) + @test_throws( + ErrorException( + "Fallback getter for variable constraint dual does not support objective function of type $(MOI.VectorOfVariables). Please report this issue to the solver wrapper package.", + ), + MOI.Utilities.get_fallback(model, MOI.ConstraintDual(), c), + ) + return +end + +struct SetByOptimizeAttribute <: MOI.AbstractOptimizerAttribute end + +MOI.is_set_by_optimize(::SetByOptimizeAttribute) = true + +function test_is_set_by_optimize_optimizer_attribute() + model = MOI.Utilities.MockOptimizer(MOI.Utilities.Model{Float64}()) + MOI.set(model, SetByOptimizeAttribute(), 1.23) + @test MOI.get(model, SetByOptimizeAttribute()) == 1.23 + return +end + end # module TestMockOptimizer.runtests()