Skip to content

Commit

Permalink
Migrate tests of Variable bridges (#1481)
Browse files Browse the repository at this point in the history
  • Loading branch information
odow authored Jul 21, 2021
1 parent a538d06 commit 57bb8dc
Show file tree
Hide file tree
Showing 11 changed files with 1,115 additions and 981 deletions.
20 changes: 9 additions & 11 deletions src/Test/test_linear.jl
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,8 @@ end
config::Config{T},
) where {T}
Test solving a linear program with variabless containing lower and upper bounds.
Test solving a linear program with ScalarAffineFunction-in-LessThan and
GreaterThan constraints.
"""
function test_linear_LessThan_and_GreaterThan(
model::MOI.ModelLike,
Expand All @@ -852,12 +853,12 @@ function test_linear_LessThan_and_GreaterThan(
@requires MOI.supports(model, MOI.ObjectiveSense())
@requires MOI.supports_constraint(
model,
MOI.SingleVariable,
MOI.ScalarAffineFunction{T},
MOI.GreaterThan{T},
)
@requires MOI.supports_constraint(
model,
MOI.SingleVariable,
MOI.ScalarAffineFunction{T},
MOI.LessThan{T},
)
x = MOI.add_variable(model)
Expand All @@ -874,14 +875,10 @@ function test_linear_LessThan_and_GreaterThan(
),
)
MOI.set(model, MOI.ObjectiveSense(), MOI.MIN_SENSE)
c1 = MOI.add_constraint(
model,
MOI.SingleVariable(x),
MOI.GreaterThan(zero(T)),
)
@test c1.value == x.value
c2 = MOI.add_constraint(model, MOI.SingleVariable(y), MOI.LessThan(zero(T)))
@test c2.value == y.value
fx = MOI.ScalarAffineFunction([MOI.ScalarAffineTerm(one(T), x)], zero(T))
c1 = MOI.add_constraint(model, fx, MOI.GreaterThan(zero(T)))
fy = MOI.ScalarAffineFunction([MOI.ScalarAffineTerm(one(T), y)], zero(T))
c2 = MOI.add_constraint(model, fy, MOI.LessThan(zero(T)))
if _supports(config, MOI.optimize!)
@test MOI.get(model, MOI.TerminationStatus()) == MOI.OPTIMIZE_NOT_CALLED
MOI.optimize!(model)
Expand Down Expand Up @@ -924,6 +921,7 @@ function test_linear_LessThan_and_GreaterThan(
@test MOI.get(model, MOI.VariablePrimal(), y) -T(100) atol = atol rtol =
rtol
end
return
end

function setup_test(
Expand Down
29 changes: 22 additions & 7 deletions test/Bridges/Variable/bridge.jl
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
module TestVariableBridge

using Test

using MathOptInterface
const MOI = MathOptInterface
const MOIT = MathOptInterface.DeprecatedTest
const MOIU = MathOptInterface.Utilities
const MOIB = MathOptInterface.Bridges

struct DummyVariableBridge <: MOIB.Variable.AbstractBridge end
function runtests()
for name in names(@__MODULE__; all = true)
if startswith("$(name)", "test_")
@testset "$(name)" begin
getfield(@__MODULE__, name)()
end
end
end
return
end

struct DummyVariableBridge <: MOI.Bridges.Variable.AbstractBridge end

@testset "AbstractBridge" begin
model = MOIU.Model{Float64}()
function test_AbstractBridge()
model = MOI.Utilities.Model{Float64}()
bridge = DummyVariableBridge()
attr = MOI.VariablePrimalStart()
@test !MOI.supports(model, attr, typeof(bridge))
i = MOIB.IndexInVector(1)
i = MOI.Bridges.IndexInVector(1)
@test_throws MOI.UnsupportedAttribute(attr) MOI.set(
model,
attr,
Expand All @@ -31,4 +41,9 @@ struct DummyVariableBridge <: MOIB.Variable.AbstractBridge end
err = MOI.SetAttributeNotAllowed(attr)
@test_throws err MOI.set(model, attr, bridge, 1.0)
@test_throws err MOI.set(model, attr, bridge, 1.0, i)
return
end

end # module

TestVariableBridge.runtests()
Loading

0 comments on commit 57bb8dc

Please sign in to comment.