Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
odow committed Nov 6, 2023
1 parent 3f5db1b commit e0dc56f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Bridges/Constraint/bridges/functionize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ function MOI.get(
return MOI.Utilities.canonical(f)
end

function MOI.get(
::MOI.ModelLike,
::MOI.Bridges.FirstBridge,
bridge::AbstractFunctionConversionBridge,
)
return bridge
end

function MOI.supports(
model::MOI.ModelLike,
attr::MOI.AbstractConstraintAttribute,
Expand Down
10 changes: 10 additions & 0 deletions test/Bridges/Constraint/functionize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,16 @@ function test_canonical_constraint_function()
return
end

function test_first_bridge()
inner = MOI.Utilities.UniversalFallback(MOI.Utilities.Model{Float64}())
model = MOI.Bridges.Constraint.ScalarFunctionize{Float64}(inner)
x = MOI.add_variable(model)
ci = MOI.add_constraint(model, x, MOI.GreaterThan(0.0))
b = MOI.get(model, MOI.Bridges.FirstBridge(), ci)
@test b isa MOI.Bridges.Constraint.ScalarFunctionizeBridge
return
end

end # module

TestConstraintFunctionize.runtests()
16 changes: 16 additions & 0 deletions test/Bridges/bridge_optimizer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1108,6 +1108,22 @@ function test_list_of_constraints_with_attribute_set()
return
end

function test_first_bridge()
inner = MOI.Utilities.UniversalFallback(MOI.Utilities.Model{Float64}())
model = MOI.Bridges.Constraint.ZeroOne{Float64}(inner)
x = MOI.add_variable(model)
ci = MOI.add_constraint(model, x, MOI.ZeroOne())
b = MOI.get(model, MOI.Bridges.FirstBridge(), ci)
@test b isa MOI.Bridges.Constraint.ZeroOneBridge
y = MOI.add_variable(model)
ci = MOI.add_constraint(model, y, MOI.Integer())
@test_throws(
MOI.GetAttributeNotAllowed{MOI.Bridges.FirstBridge},
MOI.get(model, MOI.Bridges.FirstBridge(), ci),
)
return
end

end # module

TestBridgeOptimizer.runtests()

0 comments on commit e0dc56f

Please sign in to comment.