Skip to content
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
33 changes: 33 additions & 0 deletions test/Utilities/model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,39 @@ function test_variable_coefficient_VectorQuadraticFunction()
return
end

function test_constraints_invalid_index()
model = MOI.Utilities.Model{Float64}()
F, S = FunctionNotSupportedBySolvers, MOI.ZeroOne
ci = MOI.ConstraintIndex{F,S}(1)
@test_throws(
MOI.InvalidIndex(ci),
MOI.Utilities.constraints(model.constraints, ci),
)
return
end

MOI.Utilities.@struct_of_constraints_by_set_types(
Set4802,
Union{MOI.LessThan{T},MOI.GreaterThan{T}},
MOI.EqualTo{T},
MOI.ZeroOne,
Int,
)

function test_struct_of_constraints_by_set_types()
set = Set4802{Float64,Vector{Float64},Vector{Float64},Vector{Bool},Int}()
@test set.num_variables == 0
@test set.int === nothing
set.int = 1
@test set.moi_zeroone === nothing
set.moi_zeroone = Bool[]
@test set.moi_equalto === nothing
set.moi_equalto = Float64[]
@test set.moi_lessthan === nothing
set.moi_lessthan = Float64[]
return
end

end # module

TestModel.runtests()
4 changes: 4 additions & 0 deletions test/Utilities/parser.jl
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,10 @@ function test_parse_unrecognized_expression()
ErrorException("Unrecognized expression []"),
MOI.Utilities.loadfromstring!(model, "[]"),
)
@test_throws(
ErrorException("Unrecognized expression foo(x)"),
MOI.Utilities.loadfromstring!(model, "variables: x\nfoo(x)"),
)
return
end

Expand Down
11 changes: 11 additions & 0 deletions test/Utilities/print.jl
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,17 @@ function test_print_model_to_stdout()
return
end

function test_print_constraint_name_unsupported()
model = MOI.Utilities.MockOptimizer(
MOI.Utilities.Model{Float64}();
supports_names = false,
)
x = MOI.add_variable(model)
MOI.add_constraint(model, 1.0 * x, MOI.LessThan(1.0))
@test occursin("0.0 + 1.0 v[$(x.value)] <= 1.0", sprint(print, model))
return
end

end

TestPrint.runtests()
18 changes: 6 additions & 12 deletions test/Utilities/product_of_sets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,17 @@ end

function test_scalar_basic()
sets = _ScalarSets{Float64}()
ci = MOI.ConstraintIndex{
MOI.ScalarAffineFunction{Float64},
MOI.EqualTo{Float64},
}(
12345,
)
F, S = MOI.ScalarAffineFunction{Float64}, MOI.EqualTo{Float64}
ci = MOI.ConstraintIndex{F,S}(12345)
@test !MOI.is_valid(sets, ci)
i = MOI.Utilities.set_index(sets, MOI.EqualTo{Float64})
ci_value = MOI.Utilities.add_set(sets, i)
ci = MOI.ConstraintIndex{
MOI.ScalarAffineFunction{Float64},
MOI.EqualTo{Float64},
}(
ci_value,
)
ci = MOI.ConstraintIndex{F,S}(ci_value)
@test MOI.is_valid(sets, ci)
@test MOI.Utilities.rows(sets, ci) == ci.value
ci = MOI.ConstraintIndex{F,MOI.ZeroOne}(1)
@test !MOI.is_valid(sets, ci)
return
end

function test_scalar_dimension()
Expand Down
29 changes: 29 additions & 0 deletions test/Utilities/universalfallback.jl
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,35 @@ function test_ListOfConstraintsWithAttributeSet()
return
end

function test_delete_ci_attribute()
model =
MOI.Utilities.UniversalFallback(ModelForUniversalFallback{Float64}())
x = MOI.add_variable(model)
c = MOI.add_constraint(
model,
MOI.VectorOfVariables([x]),
MOI.Nonnegatives(1),
)
MOI.set(model, MOI.ConstraintPrimalStart(), c, [1.0])
@test model.conattr[MOI.ConstraintPrimalStart()][c] == [1.0]
MOI.delete(model, x)
@test !haskey(model.conattr[MOI.ConstraintPrimalStart()], c)
# Vector
model =
MOI.Utilities.UniversalFallback(ModelForUniversalFallback{Float64}())
x = MOI.add_variable(model)
c = MOI.add_constraint(
model,
MOI.VectorOfVariables([x]),
MOI.Nonnegatives(1),
)
MOI.set(model, MOI.ConstraintPrimalStart(), c, [1.0])
@test model.conattr[MOI.ConstraintPrimalStart()][c] == [1.0]
MOI.delete(model, [x])
@test !haskey(model.conattr[MOI.ConstraintPrimalStart()], c)
return
end

end # module

TestUniversalFallback.runtests()
Loading