Skip to content

Commit 8c9083e

Browse files
authored
Refactor test_attribute_VariableBridgingCost function
Refactor test for VariableBridgingCost to improve clarity and maintainability.
1 parent 51d77df commit 8c9083e

1 file changed

Lines changed: 14 additions & 15 deletions

File tree

src/Test/test_attribute.jl

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -392,25 +392,28 @@ function test_attribute_unsupported_constraint(model::MOI.ModelLike, ::Config)
392392
return
393393
end
394394

395+
version_added(::typeof(test_attribute_unsupported_constraint)) = v"1.9.0"
396+
395397
"""
396398
test_attribute_VariableBridgingCost(model::MOI.ModelLike, config::Config)
397399
398400
Test that, for every set `S` that the model claims to support via
399401
`supports_add_constrained_variable(s)`, the corresponding
400402
[`MOI.VariableBridgingCost`](@ref) attribute returns a finite value.
401403
402-
This is the variable-side analogue of the
403-
`ConstraintBridgingCost` check in `_basic_constraint_test_helper`.
404-
The fallback works for most model but it may need
405-
custom method for some MOI layer (see
406-
https://github.com/jump-dev/MathOptInterface.jl/pull/3001#issuecomment-4468198935)
404+
This is the variable-side analog of the `ConstraintBridgingCost` check in
405+
`_basic_constraint_test_helper`.
406+
407+
The fallback works for most model but it may need custom method for some MOI
408+
layers (see https://github.com/jump-dev/MathOptInterface.jl/pull/3001#issuecomment-4468198935).
409+
407410
This test is here to catch that.
408411
"""
409412
function test_attribute_VariableBridgingCost(
410413
model::MOI.ModelLike,
411414
::Config{T},
412415
) where {T}
413-
scalar_sets = Type{<:MOI.AbstractScalarSet}[
416+
for S in Any[
414417
MOI.GreaterThan{T},
415418
MOI.LessThan{T},
416419
MOI.EqualTo{T},
@@ -420,7 +423,11 @@ function test_attribute_VariableBridgingCost(
420423
MOI.Semicontinuous{T},
421424
MOI.Semiinteger{T},
422425
]
423-
vector_sets = Type{<:MOI.AbstractVectorSet}[
426+
if MOI.supports_add_constrained_variable(model, S)
427+
@test MOI.get(model, MOI.VariableBridgingCost{S}()) < Inf
428+
end
429+
end
430+
for S in Any[
424431
MOI.Reals,
425432
MOI.Zeros,
426433
MOI.Nonnegatives,
@@ -430,12 +437,6 @@ function test_attribute_VariableBridgingCost(
430437
MOI.ExponentialCone,
431438
MOI.PositiveSemidefiniteConeTriangle,
432439
]
433-
for S in scalar_sets
434-
if MOI.supports_add_constrained_variable(model, S)
435-
@test MOI.get(model, MOI.VariableBridgingCost{S}()) < Inf
436-
end
437-
end
438-
for S in vector_sets
439440
if MOI.supports_add_constrained_variables(model, S)
440441
@test MOI.get(model, MOI.VariableBridgingCost{S}()) < Inf
441442
end
@@ -444,5 +445,3 @@ function test_attribute_VariableBridgingCost(
444445
end
445446

446447
version_added(::typeof(test_attribute_VariableBridgingCost)) = v"1.52.0"
447-
448-
version_added(::typeof(test_attribute_unsupported_constraint)) = v"1.9.0"

0 commit comments

Comments
 (0)