Skip to content

Commit

Permalink
fix test that depend of set order
Browse files Browse the repository at this point in the history
  • Loading branch information
Joaquim Garcia committed Nov 30, 2023
1 parent e48622e commit 95a24ce
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 22 deletions.
56 changes: 36 additions & 20 deletions test/jump_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -259,15 +259,20 @@ function test_jump_interpret_parameteric_bounds()
@constraint(model, [i in 1:2], x[i] >= p[i])
@objective(model, Min, sum(x))
optimize!(model)
@test MOI.get(model, MOI.ListOfConstraintTypesPresent()) ==
Tuple{Type,Type}[
expected = Tuple{Type,Type}[
(MOI.ScalarAffineFunction{Float64}, MOI.GreaterThan{Float64}),
(MOI.VariableIndex, MOI.Parameter{Float64}),
]
@test MOI.get(
result = MOI.get(model, MOI.ListOfConstraintTypesPresent())
@test Set(result) == Set(expected)
@test length(result) == length(expected)
expected = Tuple{Type,Type}[(MOI.VariableIndex, MOI.GreaterThan{Float64})]
result = MOI.get(
backend(model).optimizer.model.optimizer,
MOI.ListOfConstraintTypesPresent(),
) == Tuple{Type,Type}[(MOI.VariableIndex, MOI.GreaterThan{Float64})]
)
@test Set(result) == Set(expected)
@test length(result) == length(expected)
@test objective_value(model) == -2
MOI.set(model, POI.ParameterValue(), p[1], 4.0)
optimize!(model)
Expand All @@ -283,15 +288,20 @@ function test_jump_interpret_parameteric_bounds_expression()
@constraint(model, [i in 1:2], x[i] >= p[i] + p[1])
@objective(model, Min, sum(x))
optimize!(model)
@test MOI.get(model, MOI.ListOfConstraintTypesPresent()) ==
Tuple{Type,Type}[
expected = Tuple{Type,Type}[
(MOI.ScalarAffineFunction{Float64}, MOI.GreaterThan{Float64}),
(MOI.VariableIndex, MOI.Parameter{Float64}),
]
@test MOI.get(
result = MOI.get(model, MOI.ListOfConstraintTypesPresent())
@test Set(result) == Set(expected)
@test length(result) == length(expected)
expected = Tuple{Type,Type}[(MOI.VariableIndex, MOI.GreaterThan{Float64})]
result = MOI.get(
backend(model).optimizer.model.optimizer,
MOI.ListOfConstraintTypesPresent(),
) == Tuple{Type,Type}[(MOI.VariableIndex, MOI.GreaterThan{Float64})]
)
@test Set(result) == Set(expected)
@test length(result) == length(expected)
@test objective_value(model) == -4
MOI.set(model, POI.ParameterValue(), p[1], 4.0)
optimize!(model)
Expand All @@ -307,15 +317,18 @@ function test_jump_direct_interpret_parameteric_bounds()
@constraint(model, [i in 1:2], x[i] >= p[i])
@objective(model, Min, sum(x))
optimize!(model)
@test MOI.get(model, MOI.ListOfConstraintTypesPresent()) ==
Tuple{Type,Type}[
expected = Tuple{Type,Type}[
(MOI.ScalarAffineFunction{Float64}, MOI.GreaterThan{Float64}),
(MOI.VariableIndex, MOI.Parameter{Float64}),
]
@test MOI.get(
backend(model).optimizer,
MOI.ListOfConstraintTypesPresent(),
) == Tuple{Type,Type}[(MOI.VariableIndex, MOI.GreaterThan{Float64})]
result = MOI.get(model, MOI.ListOfConstraintTypesPresent())
@test Set(result) == Set(expected)
@test length(result) == length(expected)
expected = Tuple{Type,Type}[(MOI.VariableIndex, MOI.GreaterThan{Float64})]
result =
MOI.get(backend(model).optimizer, MOI.ListOfConstraintTypesPresent())
@test Set(result) == Set(expected)
@test length(result) == length(expected)
@test objective_value(model) == -2
MOI.set(model, POI.ParameterValue(), p[1], 4.0)
optimize!(model)
Expand All @@ -331,18 +344,21 @@ function test_jump_direct_interpret_parameteric_bounds_no_interpretation()
@constraint(model, [i in 1:2], x[i] >= p[i])
@objective(model, Min, sum(x))
optimize!(model)
@test MOI.get(model, MOI.ListOfConstraintTypesPresent()) ==
Tuple{Type,Type}[
expected = Tuple{Type,Type}[
(MOI.ScalarAffineFunction{Float64}, MOI.GreaterThan{Float64}),
(MOI.VariableIndex, MOI.Parameter{Float64}),
]
@test MOI.get(
backend(model).optimizer,
MOI.ListOfConstraintTypesPresent(),
) == Tuple{Type,Type}[(
result = MOI.get(model, MOI.ListOfConstraintTypesPresent())
@test Set(result) == Set(expected)
@test length(result) == length(expected)
expected = Tuple{Type,Type}[(
MOI.ScalarAffineFunction{Float64},
MOI.GreaterThan{Float64},
),]
result =
MOI.get(backend(model).optimizer, MOI.ListOfConstraintTypesPresent())
@test Set(result) == Set(expected)
@test length(result) == length(expected)
@test objective_value(model) == -2
MOI.set(model, POI.ParameterValue(), p[1], 4.0)
optimize!(model)
Expand Down
6 changes: 4 additions & 2 deletions test/moi_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -299,11 +299,13 @@ function test_moi_ListOfConstraintTypesPresent()
),
MOI.GreaterThan(1.0),
)
list_ctrs_types = MOI.get(model, MOI.ListOfConstraintTypesPresent())
@test list_ctrs_types == [
result = MOI.get(model, MOI.ListOfConstraintTypesPresent())
expected = [
(MOI.ScalarQuadraticFunction{Float64}, MOI.GreaterThan{Float64}),
(MOI.VariableIndex, MOI.Parameter{Float64}),
]
@test Set(result) == Set(expected)
@test length(result) == length(expected)
return
end

Expand Down

0 comments on commit 95a24ce

Please sign in to comment.