Skip to content
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

Fix tests adding multiple variable bounds #434

Merged
merged 2 commits into from
Jul 29, 2018
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
36 changes: 18 additions & 18 deletions src/Test/UnitTests/basic_constraint_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,9 @@ function basic_constraint_test_helper(model::MOI.ModelLike, config::TestConfig,
end

@testset "addconstraint!" begin
n = MOI.get(model, MOI.NumberOfConstraints{F,S}())
@test MOI.get(model, MOI.NumberOfConstraints{F,S}()) == 0
c = MOI.addconstraint!(model, constraint_function, set)
@test MOI.get(model, MOI.NumberOfConstraints{F,S}()) == n + 1
@test MOI.get(model, MOI.NumberOfConstraints{F,S}()) == 1

@testset "ConstraintName" begin
@test MOI.canget(model, MOI.ConstraintName(), typeof(c))
Expand All @@ -200,37 +200,37 @@ function basic_constraint_test_helper(model::MOI.ModelLike, config::TestConfig,
end
end

@testset "addconstraints!" begin
n = MOI.get(model, MOI.NumberOfConstraints{F,S}())
cc = MOI.addconstraints!(model,
[constraint_function, constraint_function],
[set, set]
)
@test MOI.get(model, MOI.NumberOfConstraints{F,S}()) == n + 2
end

@testset "ListOfConstraintIndices" begin
@test MOI.canget(model, MOI.ListOfConstraintIndices{F,S}())
c_indices = MOI.get(model, MOI.ListOfConstraintIndices{F,S}())
# for sanity, check that we've added 3 constraints as expected.
@test length(c_indices) == MOI.get(model, MOI.NumberOfConstraints{F,S}()) == 3
@test length(c_indices) == MOI.get(model, MOI.NumberOfConstraints{F,S}()) == 1
end

if F != MOI.SingleVariable
# We can't add multiple single variable constraints as these are
# interpreted as bounds etc.
@testset "addconstraints!" begin
n = MOI.get(model, MOI.NumberOfConstraints{F,S}())
cc = MOI.addconstraints!(model,
[constraint_function, constraint_function],
[set, set]
)
@test MOI.get(model, MOI.NumberOfConstraints{F,S}()) == 3
@test length(MOI.get(model, MOI.ListOfConstraintIndices{F,S}())) == 3
end
end

@testset "isvalid" begin
c_indices = MOI.get(model, MOI.ListOfConstraintIndices{F,S}())
# for sanity, check that we've added 3 constraints as expected.
@test length(c_indices) == 3
@test all(MOI.isvalid.(Ref(model), c_indices))
end

if delete
@testset "delete!" begin
c_indices = MOI.get(model, MOI.ListOfConstraintIndices{F,S}())
# for sanity, check that we've added 3 constraints as expected.
@test length(c_indices) == 3
@test MOI.candelete(model, c_indices[1])
MOI.delete!(model, c_indices[1])
@test MOI.get(model, MOI.NumberOfConstraints{F,S}()) == length(c_indices)-1 == 2
@test MOI.get(model, MOI.NumberOfConstraints{F,S}()) == length(c_indices)-1
@test !MOI.isvalid(model, c_indices[1])
end
end
Expand Down
12 changes: 6 additions & 6 deletions src/Test/modellike.jl
Original file line number Diff line number Diff line change
Expand Up @@ -315,17 +315,17 @@ function orderedindicestest(model::MOI.ModelLike)
@test MOI.get(model, MOI.ListOfVariableIndices()) == [v2]
v3 = MOI.addvariable!(model)
@test MOI.get(model, MOI.ListOfVariableIndices()) == [v2, v3]
v4 = MOI.addvariable!(model)
@test MOI.get(model, MOI.ListOfVariableIndices()) == [v2, v3, v4]

# Note: there are too many combinations to
# test, so we're just going to check
# SingleVariable-in-LessThan and hope it
# works for the rest
# Note: there are too many combinations to test, so we're just going to
# check SingleVariable-in-LessThan and hope it works for the rest
c1 = MOI.addconstraint!(model, MOI.SingleVariable(v2), MOI.LessThan(1.0))
@test MOI.get(model, MOI.ListOfConstraintIndices{MOI.SingleVariable, MOI.LessThan{Float64}}()) == [c1]
c2 = MOI.addconstraint!(model, MOI.SingleVariable(v2), MOI.LessThan(2.0))
c2 = MOI.addconstraint!(model, MOI.SingleVariable(v3), MOI.LessThan(2.0))
@test MOI.get(model, MOI.ListOfConstraintIndices{MOI.SingleVariable, MOI.LessThan{Float64}}()) == [c1, c2]
MOI.delete!(model, c1)
@test MOI.get(model, MOI.ListOfConstraintIndices{MOI.SingleVariable, MOI.LessThan{Float64}}()) == [c2]
c3 = MOI.addconstraint!(model, MOI.SingleVariable(v2), MOI.LessThan(3.0))
c3 = MOI.addconstraint!(model, MOI.SingleVariable(v4), MOI.LessThan(3.0))
@test MOI.get(model, MOI.ListOfConstraintIndices{MOI.SingleVariable, MOI.LessThan{Float64}}()) == [c2, c3]
end