Skip to content
Merged
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
47 changes: 47 additions & 0 deletions src/Test/modellike.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,53 @@ function default_status_test(model::MOI.ModelLike)
end

function nametest(model::MOI.ModelLike)
@testset "Variables" begin
MOI.empty!(model)
x = MOI.add_variables(model, 2)
MOI.set(model, MOI.VariableName(), x[1], "x1")
@test MOI.get(model, MOI.VariableIndex, "x1") == x[1]
MOI.set(model, MOI.VariableName(), x[1], "x2")
@test MOI.get(model, MOI.VariableIndex, "x1") === nothing
@test MOI.get(model, MOI.VariableIndex, "x2") == x[1]
MOI.set(model, MOI.VariableName(), x[2], "x1")
@test MOI.get(model, MOI.VariableIndex, "x1") == x[2]
MOI.set(model, MOI.VariableName(), x[1], "x1")
@test_throws ErrorException MOI.get(model, MOI.VariableIndex, "x1")
end

@testset "Variable bounds" begin
MOI.empty!(model)
x = MOI.add_variable(model)
c1 = MOI.add_constraint(model, MOI.SingleVariable(x), MOI.GreaterThan(0.0))
c2 = MOI.add_constraint(model, MOI.SingleVariable(x), MOI.LessThan(1.0))
MOI.set(model, MOI.ConstraintName(), c1, "c1")
@test MOI.get(model, MOI.ConstraintIndex, "c1") == c1
MOI.set(model, MOI.ConstraintName(), c1, "c2")
@test MOI.get(model, MOI.ConstraintIndex, "c1") === nothing
@test MOI.get(model, MOI.ConstraintIndex, "c2") == c1
MOI.set(model, MOI.ConstraintName(), c2, "c1")
@test MOI.get(model, MOI.ConstraintIndex, "c1") == c2
MOI.set(model, MOI.ConstraintName(), c1, "c1")
@test_throws ErrorException MOI.get(model, MOI.ConstraintIndex, "c1")
end

@testset "Affine constraints" begin
MOI.empty!(model)
x = MOI.add_variable(model)
f = MOI.ScalarAffineFunction([MOI.ScalarAffineTerm(1.0, x)], 0.0)
c1 = MOI.add_constraint(model, f, MOI.GreaterThan(0.0))
c2 = MOI.add_constraint(model, f, MOI.LessThan(1.0))
MOI.set(model, MOI.ConstraintName(), c1, "c1")
@test MOI.get(model, MOI.ConstraintIndex, "c1") == c1
MOI.set(model, MOI.ConstraintName(), c1, "c2")
@test MOI.get(model, MOI.ConstraintIndex, "c1") === nothing
@test MOI.get(model, MOI.ConstraintIndex, "c2") == c1
MOI.set(model, MOI.ConstraintName(), c2, "c1")
@test MOI.get(model, MOI.ConstraintIndex, "c1") == c2
MOI.set(model, MOI.ConstraintName(), c1, "c1")
@test_throws ErrorException MOI.get(model, MOI.ConstraintIndex, "c1")
end

@testset "Name test with $(typeof(model))" begin
MOI.empty!(model)
@test MOIU.supports_default_copy_to(model, #=copy_names=# true)
Expand Down