From d65e9719f7c7072d4b1030594282dcccbd1625bd Mon Sep 17 00:00:00 2001 From: odow Date: Thu, 27 Feb 2025 10:15:20 +1300 Subject: [PATCH 1/2] [Test] improve test coverage --- src/Bridges/Bridges.jl | 14 +++----------- .../AllDifferentToCountDistinctBridge.jl | 3 ++- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/src/Bridges/Bridges.jl b/src/Bridges/Bridges.jl index 133faec998..4c9cedd955 100644 --- a/src/Bridges/Bridges.jl +++ b/src/Bridges/Bridges.jl @@ -178,16 +178,10 @@ function _test_structural_identical( Test.@test (F, S) in b_constraint_types || MOI.get(a, attr) == 0 end for (F, S) in b_constraint_types + @test haskey(constraints, (F, S)) # Check that the same number of constraints are present attr = MOI.NumberOfConstraints{F,S}() - if !haskey(constraints, (F, S)) - # Constraint is reported in `b`, but not in `a`. Check that there - # are no actual constraints in `b`. - Test.@test MOI.get(b, attr) == 0 - continue - else - Test.@test MOI.get(a, attr) == MOI.get(b, attr) - end + Test.@test MOI.get(a, attr) == MOI.get(b, attr) # Check that supports_constraint is implemented Test.@test MOI.supports_constraint(b, F, S) # Check that each function in `b` matches a function in `a` @@ -402,9 +396,7 @@ function _test_delete(Bridge, model, inner) MOI.delete.(model, MOI.get(model, MOI.ListOfConstraintIndices{F,S}())) end # * So now there should be no constraints in the problem - for (F, S) in MOI.get(inner, MOI.ListOfConstraintTypesPresent()) - Test.@test MOI.get(inner, MOI.NumberOfConstraints{F,S}()) == 0 - end + @test isempty(MOI.get(inner, MOI.ListOfConstraintTypesPresent())) # * And there should be the same number of variables attr = MOI.NumberOfVariables() Test.@test MOI.get(inner, attr) == MOI.get(model, attr) diff --git a/test/Bridges/Constraint/AllDifferentToCountDistinctBridge.jl b/test/Bridges/Constraint/AllDifferentToCountDistinctBridge.jl index edc07a4dbb..7ebdc83fd3 100644 --- a/test/Bridges/Constraint/AllDifferentToCountDistinctBridge.jl +++ b/test/Bridges/Constraint/AllDifferentToCountDistinctBridge.jl @@ -40,7 +40,8 @@ function test_runtests_VectorOfVariables() y <= 3.0 z == 2.0 n == 3.0 - """, + """; + print_inner_model = true, ) return end From 56c32f4cbd492577b1dc26594720a91d25968ca4 Mon Sep 17 00:00:00 2001 From: Oscar Dowson Date: Thu, 27 Feb 2025 10:26:59 +1300 Subject: [PATCH 2/2] Apply suggestions from code review --- src/Bridges/Bridges.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Bridges/Bridges.jl b/src/Bridges/Bridges.jl index 4c9cedd955..c10d54790d 100644 --- a/src/Bridges/Bridges.jl +++ b/src/Bridges/Bridges.jl @@ -178,7 +178,7 @@ function _test_structural_identical( Test.@test (F, S) in b_constraint_types || MOI.get(a, attr) == 0 end for (F, S) in b_constraint_types - @test haskey(constraints, (F, S)) + Test.@test haskey(constraints, (F, S)) # Check that the same number of constraints are present attr = MOI.NumberOfConstraints{F,S}() Test.@test MOI.get(a, attr) == MOI.get(b, attr) @@ -396,7 +396,7 @@ function _test_delete(Bridge, model, inner) MOI.delete.(model, MOI.get(model, MOI.ListOfConstraintIndices{F,S}())) end # * So now there should be no constraints in the problem - @test isempty(MOI.get(inner, MOI.ListOfConstraintTypesPresent())) + Test.@test isempty(MOI.get(inner, MOI.ListOfConstraintTypesPresent())) # * And there should be the same number of variables attr = MOI.NumberOfVariables() Test.@test MOI.get(inner, attr) == MOI.get(model, attr)