Skip to content

Commit

Permalink
Fix tests adding multiple variable bounds (#434)
Browse files Browse the repository at this point in the history
* Stop adding multiple SingleVariable-in-Set constraints in the unit
tests.

* Fix orderedindices test
  • Loading branch information
odow authored Jul 29, 2018
1 parent 46838d5 commit cdb6d1a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
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

0 comments on commit cdb6d1a

Please sign in to comment.