Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat committed Oct 18, 2024
1 parent a32e2e8 commit 1f60a36
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions test/Bridges/Constraint/set_conversion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ function Base.convert(::Type{Zero}, s::MOI.EqualTo)
return Zero()
end

# Does not make sense that this is convertible but it's
# just to test `conversion_cost`
function MOI.Bridges.Constraint.conversion_cost(
::Type{MOI.LessThan{Float64}},
::Type{Zero},
)
return 10.0
end

const EqualToBridge{T,S1,F} =
MOI.Bridges.Constraint.SetConversionBridge{T,MOI.EqualTo{T},S1,F}

Expand All @@ -57,6 +66,33 @@ function test_runtests()
return
end

function test_conversion_cost(T = Float64)
model = MOI.Utilities.Model{T}()
bridged = MOI.Bridges.LazyBridgeOptimizer(model)
MOI.Bridges.add_bridge(
bridged,
MOI.Bridges.Constraint.SetConversionBridge{T,MOI.LessThan{T}},
)
@test MOI.Bridges.bridge_type(bridged, MOI.VariableIndex, Zero) ==
MOI.Bridges.Constraint.SetConversionBridge{
T,
MOI.LessThan{T},
Zero,
MOI.VariableIndex,
}
MOI.Bridges.add_bridge(
bridged,
MOI.Bridges.Constraint.SetConversionBridge{T,MOI.EqualTo{T}},
)
@test MOI.Bridges.bridge_type(bridged, MOI.VariableIndex, Zero) ==
MOI.Bridges.Constraint.SetConversionBridge{
T,
MOI.EqualTo{T},
Zero,
MOI.VariableIndex,
}
end

end # module

TestConstraintSetConversion.runtests()

0 comments on commit 1f60a36

Please sign in to comment.