Skip to content

[Utilities] improve code coverage #2660

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions test/Utilities/copy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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()
27 changes: 27 additions & 0 deletions test/Utilities/mockoptimizer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Loading