From 1f60a36c70e9646135bc334558afca4f56cc9a19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Fri, 18 Oct 2024 13:44:07 +0200 Subject: [PATCH] Add test --- test/Bridges/Constraint/set_conversion.jl | 36 +++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/test/Bridges/Constraint/set_conversion.jl b/test/Bridges/Constraint/set_conversion.jl index fc288bd5ba..47d9dc408b 100644 --- a/test/Bridges/Constraint/set_conversion.jl +++ b/test/Bridges/Constraint/set_conversion.jl @@ -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} @@ -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()