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
22 changes: 6 additions & 16 deletions src/constraints.jl
Original file line number Diff line number Diff line change
Expand Up @@ -274,14 +274,9 @@ function Base.showerror(io::IO, err::LowerBoundAlreadySet{S1,S2}) where {S1,S2}
return print(
io,
typeof(err),
": Cannot add `SingleVariable`-in`",
S2,
"` constraint for variable ",
err.vi,
" as a `SingleVariable`-in`",
S1,
"` constraint was already set for this variable and both",
" constraints set a lower bound.",
": Cannot add `SingleVariable`-in-`$(S2)` constraint for variable ",
"$(err.vi) as a `SingleVariable`-in-`$(S1)` constraint was already ",
"set for this variable and both constraints set a lower bound.",
)
end

Expand All @@ -301,14 +296,9 @@ function Base.showerror(io::IO, err::UpperBoundAlreadySet{S1,S2}) where {S1,S2}
return print(
io,
typeof(err),
": Cannot add `SingleVariable`-in`",
S2,
"` constraint for variable ",
err.vi,
" as a `SingleVariable`-in`",
S1,
"` constraint was already set for this variable and both",
" constraints set an upper bound.",
": Cannot add `SingleVariable`-in-`$(S2)` constraint for variable ",
"$(err.vi) as a `SingleVariable`-in-`$(S1)` constraint was already ",
"set for this variable and both constraints set an upper bound.",
)
end

Expand Down
55 changes: 47 additions & 8 deletions test/constraints.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
module TestConstraints

using Test

using MathOptInterface
const MOI = MathOptInterface

function runtests()
for name in names(@__MODULE__; all = true)
if startswith("$name", "test_")
@testset "$(name)" begin
getfield(@__MODULE__, name)()
end
end
end
end

function _constant_not_zero_test(::Type{T}) where {T}
S = MOI.EqualTo{T}
x = MOI.VariableIndex(1)
Expand All @@ -25,14 +36,42 @@ function test_constraints_ConstantNotZero()
return
end

function runtests()
for name in names(@__MODULE__; all = true)
if startswith("$name", "test_")
@testset "$(name)" begin
getfield(@__MODULE__, name)()
end
end
end
function test_LowerBoundAlreadySet_error()
x = MOI.VariableIndex(1)
S1 = MOI.LessThan{Int}
S2 = MOI.Interval{Int}
err = MOI.LowerBoundAlreadySet{S1,S2}(x)
@test sprint(showerror, err) ==
"$(typeof(err)): Cannot add `SingleVariable`-in-`$(S2)` constraint " *
"for variable $(x) as a `SingleVariable`-in-`$(S1)` constraint was " *
"already set for this variable and both constraints set a lower bound."
return
end

function test_UpperBoundAlreadySet_error()
x = MOI.VariableIndex(1)
S1 = MOI.GreaterThan{Int}
S2 = MOI.Interval{Int}
err = MOI.UpperBoundAlreadySet{S1,S2}(x)
@test sprint(showerror, err) ==
"$(typeof(err)): Cannot add `SingleVariable`-in-`$(S2)` constraint " *
"for variable $(x) as a `SingleVariable`-in-`$(S1)` constraint was " *
"already set for this variable and both constraints set an upper bound."
return
end

function test_ScalarFunctionConstantNotZero_error()
x = MOI.VariableIndex(1)
T = Int
F = MOI.ScalarAffineFunction{T}
S = MOI.EqualTo{T}
err = MOI.ScalarFunctionConstantNotZero{T,F,S}(one(T))
@test sprint(showerror, err) ==
"In `$F`-in-`$S` constraint: Constant $(one(T)) of the function is " *
"not zero. The function constant should be moved to the set. You can " *
"use `MOI.Utilities.normalize_and_add_constraint` which does this " *
"automatically."
return
end

end
Expand Down