From 3a9f0053f12cbae368cb5a379c362b3c9aad4acf Mon Sep 17 00:00:00 2001 From: odow Date: Mon, 5 Jul 2021 13:32:07 +1200 Subject: [PATCH 1/4] Update the tests of UniversalFallback to new MOI.Test --- src/Utilities/universalfallback.jl | 21 +- test/Utilities/universalfallback.jl | 527 ++++++++++++++-------------- 2 files changed, 286 insertions(+), 262 deletions(-) diff --git a/src/Utilities/universalfallback.jl b/src/Utilities/universalfallback.jl index 306e4ff261..6238896fbd 100644 --- a/src/Utilities/universalfallback.jl +++ b/src/Utilities/universalfallback.jl @@ -306,7 +306,7 @@ function _get( end function _get( - uf, + uf::UniversalFallback, attr::MOI.CanonicalConstraintFunction, ci::MOI.ConstraintIndex, ) @@ -445,8 +445,19 @@ function MOI.get( listattr::MOI.ListOfConstraintAttributesSet{F,S}, ) where {F,S} list = MOI.get(uf.model, listattr) - for attr in keys(uf.conattr) - push!(list, attr) + for (attr, dict) in uf.conattr + if any(k -> k isa MOI.ConstraintIndex{F,S}, keys(dict)) + push!(list, attr) + end + end + # ConstraintName isn't stored in conattr, but in the .con_to_name dictionary + # instead. Only add it to `list` if it isn't already, and if a constraint + # of the right type has a name set. This avoids, for example, returning + # ConstraintName for SingleVariable constraints. + if !(MOI.ConstraintName() in list) + if any(k -> k isa MOI.ConstraintIndex{F,S}, keys(uf.con_to_name)) + push!(list, MOI.ConstraintName()) + end end return list end @@ -648,7 +659,7 @@ function _set(uf::UniversalFallback, attr::MOI.AbstractModelAttribute, value) end function _set( - uf, + uf::UniversalFallback, attr::MOI.AbstractVariableAttribute, vi::MOI.VariableIndex, value, @@ -661,7 +672,7 @@ function _set( end function _set( - uf, + uf::UniversalFallback, attr::MOI.AbstractConstraintAttribute, ci::MOI.ConstraintIndex, value, diff --git a/test/Utilities/universalfallback.jl b/test/Utilities/universalfallback.jl index c95c433346..23e0b2ede4 100644 --- a/test/Utilities/universalfallback.jl +++ b/test/Utilities/universalfallback.jl @@ -1,18 +1,103 @@ +module TestUniversalFallback + using Test + import MathOptInterface + const MOI = MathOptInterface -const MOIT = MOI.DeprecatedTest -const MOIU = MOI.Utilities -function test_optmodattrs(uf, model, attr, listattr) +function runtests() + for name in names(@__MODULE__; all = true) + if startswith("$(name)", "test_") + @testset "$(name)" begin + getfield(@__MODULE__, name)() + end + end + end + return +end + +### +### Utilities for running the tests +### + +struct UnknownOptimizerAttribute <: MOI.AbstractOptimizerAttribute end + +# A few objective/constraint types are supported to test both the fallback and the +# delegation to the internal model +MOI.Utilities.@model( + ModelForUniversalFallback, + (), + (MOI.LessThan,), + (), + (), + (), + (MOI.ScalarAffineFunction,), + (), + () +) + +function MOI.supports( + ::ModelForUniversalFallback{T}, + ::MOI.ObjectiveFunction{MOI.ScalarAffineFunction{T}}, +) where {T} + return false +end + +function MOI.supports_constraint( + ::ModelForUniversalFallback{T}, + ::Type{MOI.SingleVariable}, + ::Type{ + <:Union{ + MOI.EqualTo{T}, + MOI.GreaterThan{T}, + MOI.Interval{T}, + MOI.Integer, + MOI.ZeroOne, + }, + }, +) where {T} + return false +end + +### +### The tests +### + +function test_MOI_Test() + inner = ModelForUniversalFallback{Float64}() + model = MOI.Utilities.UniversalFallback(inner) + MOI.Test.runtests( + model, + MOI.Test.Config(exclude = Any[MOI.optimize!]), + exclude = String[ + # This test is optional. + "test_model_ScalarFunctionConstantNotZero", + # UniversalFallback fails all these tests because it supports + # everything... + "test_attribute_", + "test_model_supports_constraint_", + "test_model_copy_to_Unsupported", + # Bugs in UniversalFallback + "test_model_LowerBoundAlreadySet", + "test_model_UpperBoundAlreadySet", + ], + ) + return +end + + +function _test_Optimizer_Model_attributes(uf, model, attr, listattr) @test !MOI.supports(model, attr) @test MOI.supports(uf, attr) @test isempty(MOI.get(uf, listattr)) MOI.set(uf, attr, 0) @test MOI.get(uf, attr) == 0 @test MOI.get(uf, listattr) == [attr] + return end -function test_varconattrs( + +function _test_Variable_Constraint_attributes( uf, model, attr, @@ -34,285 +119,208 @@ function test_varconattrs( @test MOI.get(uf, attr, y) == 0 @test MOI.get(uf, attr, [z, x]) == [5, 2] @test MOI.get(uf, listattr) == [attr] - u = addfun(uf) @test MOI.get(uf, attr, u) === nothing @test MOI.get(uf, listattr) == [attr] MOI.set(uf, attr, u, 8) @test MOI.get(uf, listattr) == [attr] - w = addfun(uf) @test MOI.get(uf, listattr) == [attr] @test MOI.get(uf, attr, w) === nothing - @test MOI.is_valid(uf, u) MOI.delete(uf, u) @test !MOI.is_valid(uf, u) @test_throws MOI.InvalidIndex{typeof(u)} MOI.delete(uf, u) @test MOI.get(uf, listattr) == [attr] - MOI.set(uf, attr, [w, z], [9, 4]) @test MOI.get(uf, listattr) == [attr] @test MOI.get(uf, attr, w) == 9 @test MOI.get(uf, attr, x) == 2 @test MOI.get(uf, attr, z) == 4 @test MOI.get(uf, attr, y) == 0 + return end -struct UnknownOptimizerAttribute <: MOI.AbstractOptimizerAttribute end - -# A few objective/constraint types are supported to test both the fallback and the -# delegation to the internal model -MOIU.@model( - ModelForUniversalFallback, - (), - (MOI.LessThan,), - (), - (), - (), - (MOI.ScalarAffineFunction,), - (), - () -) -function MOI.supports( - ::ModelForUniversalFallback{T}, - ::Type{MOI.ObjectiveFunction{MOI.ScalarAffineFunction{T}}}, -) where {T} - return false -end -function MOI.supports_constraint( - ::ModelForUniversalFallback{T}, - ::Type{MOI.SingleVariable}, - ::Type{ - <:Union{ - MOI.EqualTo{T}, - MOI.GreaterThan{T}, - MOI.Interval{T}, - MOI.Integer, - MOI.ZeroOne, - }, - }, -) where {T} - return false +function test_optimizer_attributes() + model = ModelForUniversalFallback{Float64}() + uf = MOI.Utilities.UniversalFallback(model) + _test_Optimizer_Model_attributes( + uf, + model, + UnknownOptimizerAttribute(), + MOI.ListOfOptimizerAttributesSet(), + ) + return end -# TODO: Restructure to avoid sharing state across testsets. It doesn't seem -# necessary to use the same uf object for all the tests. -model = ModelForUniversalFallback{Float64}() -uf = MOIU.UniversalFallback(model) -@test MOI.is_empty(uf) -@testset "Copy Test" begin - MOIT.copytest(uf, MOIU.Model{Float64}()) - @test !MOI.is_empty(uf) - MOI.empty!(uf) - @test MOI.is_empty(uf) -end -@testset "Start Values Test" begin - src = MOIU.UniversalFallback(MOIU.Model{Float64}()) - dest = MOIU.UniversalFallback(MOIU.Model{Float64}()) - MOIT.start_values_test(dest, src) -end -@testset "Valid Test" begin - MOIT.validtest(uf) - @test !MOI.is_empty(uf) - MOI.empty!(uf) - @test MOI.is_empty(uf) -end -@testset "Empty Test" begin - MOIT.emptytest(uf) - @test MOI.is_empty(uf) -end -@testset "Name Test" begin - MOIT.nametest(uf) +function test_model_attributes() + model = ModelForUniversalFallback{Float64}() + uf = MOI.Utilities.UniversalFallback(model) + _test_Optimizer_Model_attributes( + uf, + model, + MOI.Test.UnknownModelAttribute(), + MOI.ListOfModelAttributesSet(), + ) + # Test that emptying the uf get's rid of the model attributes! @test !MOI.is_empty(uf) MOI.empty!(uf) @test MOI.is_empty(uf) + return end -@testset "Optimizer Attribute" begin - attr = UnknownOptimizerAttribute() - listattr = MOI.ListOfOptimizerAttributesSet() - empty!(uf.optattr) - test_optmodattrs(uf, model, attr, listattr) + +function test_variable_attributes() + model = ModelForUniversalFallback{Float64}() + uf = MOI.Utilities.UniversalFallback(model) + _test_Variable_Constraint_attributes( + uf, + model, + MOI.Test.UnknownVariableAttribute(), + MOI.ListOfVariableAttributesSet(), + MOI.VariableIndex, + MOI.add_variable, + MOI.add_variables(uf, 3)... + ) + return end -@testset "Model Attribute" begin - attr = MOIT.UnknownModelAttribute() - listattr = MOI.ListOfModelAttributesSet() - test_optmodattrs(uf, model, attr, listattr) - @test !MOI.is_empty(uf) - MOI.empty!(uf) - @test MOI.is_empty(uf) + +function test_supported_objective_attributes() + model = ModelForUniversalFallback{Float64}() + uf = MOI.Utilities.UniversalFallback(model) + x, y = MOI.add_variables(uf, 2) + attr = MOI.ObjectiveFunction{MOI.SingleVariable}() + @test MOI.supports(model, attr) + MOI.set(uf, attr, MOI.SingleVariable(x)) + @test MOI.get(uf, attr) ≈ MOI.SingleVariable(x) + MOI.set(uf, attr, MOI.SingleVariable(y)) + @test MOI.get(uf, attr) ≈ MOI.SingleVariable(y) + return end -x = MOI.add_variable(uf) -y, z = MOI.add_variables(uf, 2) -@testset "Variable Attribute" begin - VI = MOI.VariableIndex - attr = MOIT.UnknownVariableAttribute() - listattr = MOI.ListOfVariableAttributesSet() - test_varconattrs(uf, model, attr, listattr, VI, MOI.add_variable, x, y, z) + +function test_unsupported_objective_attributes() + model = ModelForUniversalFallback{Float64}() + uf = MOI.Utilities.UniversalFallback(model) + x, y = MOI.add_variables(uf, 2) + attr = MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}}() + @test !MOI.supports(model, attr) + @test MOI.supports(uf, attr) + f = MOI.ScalarAffineFunction([MOI.ScalarAffineTerm(1.0, x)], 0.0) + MOI.set(uf, attr, f) + @test MOI.get(uf, attr) ≈ f + MOI.modify(uf, attr, MOI.ScalarCoefficientChange(y, 1.0)) + new_obj = MOI.ScalarAffineFunction( + [MOI.ScalarAffineTerm(1.0, x), MOI.ScalarAffineTerm(1.0, y)], + 0.0, + ) + @test MOI.get(uf, attr) ≈ new_obj + return end -@testset "Objective Attribute" begin - global x, y, z - _single(vi) = MOI.SingleVariable(vi) - function _affine(vi) - return convert( - MOI.ScalarAffineFunction{Float64}, - MOI.SingleVariable(vi), - ) - end - function _add_single_objective(vi) - return MOI.set( - uf, - MOI.ObjectiveFunction{MOI.SingleVariable}(), - _single(vi), - ) - end - function _add_affine_objective(vi) - return MOI.set( - uf, - MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}}(), - _affine(vi), - ) - end - @testset "Supported objective" begin - F = MOI.SingleVariable - @test MOI.supports(model, MOI.ObjectiveFunction{F}()) - _add_single_objective(x) - @test MOI.get(uf, MOI.ObjectiveFunction{F}()) ≈ _single(x) - MOI.set(uf, MOI.ObjectiveFunction{F}(), _single(y)) - @test MOI.get(uf, MOI.ObjectiveFunction{F}()) ≈ _single(y) - end - @testset "Unsupported objective" begin - F = MOI.ScalarAffineFunction{Float64} - @test !MOI.supports(model, MOI.ObjectiveFunction{F}) - @test MOI.supports(uf, MOI.ObjectiveFunction{F}()) - _add_affine_objective(x) - @test MOI.get(uf, MOI.ObjectiveFunction{F}()) ≈ _affine(x) - MOI.modify( + +function test_supported_constraint_attributes() + model = ModelForUniversalFallback{Float64}() + uf = MOI.Utilities.UniversalFallback(model) + x, y, z = MOI.add_variables(uf, 3) + function _add_constraint(uf, x::MOI.VariableIndex, ub::Float64) + return MOI.add_constraint( uf, - MOI.ObjectiveFunction{F}(), - MOI.ScalarCoefficientChange(y, 1.0), + MOI.ScalarAffineFunction([MOI.ScalarAffineTerm(1.0, x)], 0.0), + MOI.LessThan(ub), ) - fx = MOI.SingleVariable(x) - fy = MOI.SingleVariable(y) - obj = 1fx + 1fy - @test MOI.get(uf, MOI.ObjectiveFunction{F}()) ≈ obj end -end -@testset "Constraint Attribute" begin - global x, y, z - function _affine(vi) - return convert( + cx = _add_constraint(uf, x, 0.0) + cy = _add_constraint(uf, y, 1.0) + cz = _add_constraint(uf, z, 2.0) + _test_Variable_Constraint_attributes( + uf, + model, + MOI.Test.UnknownConstraintAttribute(), + MOI.ListOfConstraintAttributesSet{ MOI.ScalarAffineFunction{Float64}, - MOI.SingleVariable(vi), - ) - end - function _add_affine_constraint(vi, ub) - return MOI.add_constraint(uf, _affine(vi), MOI.LessThan(ub)) - end - attr = MOIT.UnknownConstraintAttribute() - @testset "Supported constraint" begin - cx = _add_affine_constraint(x, 0.0) - cy = _add_affine_constraint(y, 1.0) - cz = _add_affine_constraint(z, 2.0) - CI = MOI.ConstraintIndex{MOI.SingleVariable,MOI.LessThan{Float64}} - listattr = MOI.ListOfConstraintAttributesSet{ - MOI.SingleVariable, MOI.LessThan{Float64}, - }() - test_varconattrs( - uf, - model, - attr, - listattr, - CI, - uf -> _add_affine_constraint(x, 0.0), - cx, - cy, - cz, - ) - - MOI.set(uf, MOI.ConstraintFunction(), cx, _affine(y)) - @test MOI.get(uf, MOI.ConstraintFunction(), cx) ≈ _affine(y) - @test MOI.get(uf, MOI.CanonicalConstraintFunction(), cx) ≈ _affine(y) - @test MOIU.is_canonical( - MOI.get(uf, MOI.CanonicalConstraintFunction(), cx), - ) + }(), + MOI.ConstraintIndex{ + MOI.ScalarAffineFunction{Float64}, + MOI.LessThan{Float64}, + }, + uf -> _add_constraint(uf, x, 0.0), + cx, + cy, + cz, + ) + fy = MOI.ScalarAffineFunction([MOI.ScalarAffineTerm(1.0, y)], 0.0) + MOI.set(uf, MOI.ConstraintFunction(), cx, fy) + @test MOI.get(uf, MOI.ConstraintFunction(), cx) ≈ fy + @test MOI.get(uf, MOI.CanonicalConstraintFunction(), cx) ≈ fy + @test MOI.Utilities.is_canonical( + MOI.get(uf, MOI.CanonicalConstraintFunction(), cx), + ) + @test MOI.supports(uf, MOI.ConstraintName(), typeof(cx)) + MOI.set(uf, MOI.ConstraintName(), cx, "LessThan") + @test MOI.get(uf, MOI.ConstraintName(), cx) == "LessThan" + @test MOI.get(uf, typeof(cx), "LessThan") == cx + MOI.delete(uf, cx) + @test MOI.get(uf, typeof(cx), "LessThan") === nothing + return +end - @test MOI.supports(uf, MOI.ConstraintName(), typeof(cx)) - MOI.set(uf, MOI.ConstraintName(), cx, "LessThan") - @test MOI.get(uf, MOI.ConstraintName(), cx) == "LessThan" - @test MOI.get(uf, typeof(cx), "LessThan") == cx - MOI.delete(uf, cx) - @test MOI.get(uf, typeof(cx), "LessThan") === nothing - end - # To remove the constraint attributes added in the previous testset - MOI.empty!(uf) - x = MOI.add_variable(uf) - y, z = MOI.add_variables(uf, 2) - @testset "Unsupported constraint" begin - cx = _add_affine_constraint(x, 0.0) - cy = _add_affine_constraint(y, 1.0) - cz = _add_affine_constraint(z, 2.0) - CI = MOI.ConstraintIndex{MOI.SingleVariable,MOI.EqualTo{Float64}} - listattr = MOI.ListOfConstraintAttributesSet{ - MOI.SingleVariable, - MOI.EqualTo{Float64}, - }() - test_varconattrs( +function test_unsupported_constraint_attributes() + model = ModelForUniversalFallback{Float64}() + uf = MOI.Utilities.UniversalFallback(model) + x, y, z = MOI.add_variables(uf, 3) + function _add_constraint(uf, x::MOI.VariableIndex, ub::Float64) + return MOI.add_constraint( uf, - model, - attr, - listattr, - CI, - uf -> _add_affine_constraint(x, 0.0), - cx, - cy, - cz, + MOI.ScalarAffineFunction([MOI.ScalarAffineTerm(1.0, x)], 0.0), + MOI.EqualTo(ub), ) - - MOI.set(uf, MOI.ConstraintFunction(), cx, _affine(y)) - @test MOI.get(uf, MOI.ConstraintFunction(), cx) ≈ _affine(y) - @test MOI.get(uf, MOI.CanonicalConstraintFunction(), cx) ≈ _affine(y) - @test MOIU.is_canonical( - MOI.get(uf, MOI.CanonicalConstraintFunction(), cx), - ) - - @test MOI.supports(uf, MOI.ConstraintName(), typeof(cx)) - MOI.set(uf, MOI.ConstraintName(), cx, "EqualTo") - @test MOI.get(uf, MOI.ConstraintName(), cx) == "EqualTo" - @test MOI.get(uf, typeof(cx), "EqualTo") == cx - MOI.delete(uf, cx) - @test MOI.get(uf, typeof(cx), "EqualTo") === nothing end -end -config = MOIT.Config(solve = false) -@testset "empty" begin - MOI.empty!(uf) - @test MOI.is_empty(uf) -end -@testset "Unit" begin - MOIT.unittest(uf, config) -end -@testset "Modification" begin - MOIT.modificationtest(uf, config) -end -@testset "Continuous Linear" begin - MOIT.contlineartest(uf, config) + cx = _add_constraint(uf, x, 0.0) + cy = _add_constraint(uf, y, 1.0) + cz = _add_constraint(uf, z, 2.0) + _test_Variable_Constraint_attributes( + uf, + model, + MOI.Test.UnknownConstraintAttribute(), + MOI.ListOfConstraintAttributesSet{ + MOI.ScalarAffineFunction{Float64}, + MOI.EqualTo{Float64}, + }(), + MOI.ConstraintIndex{ + MOI.ScalarAffineFunction{Float64}, + MOI.EqualTo{Float64}, + }, + uf -> _add_constraint(uf, x, 0.0), + cx, + cy, + cz, + ) + fy = MOI.ScalarAffineFunction([MOI.ScalarAffineTerm(1.0, y)], 0.0) + MOI.set(uf, MOI.ConstraintFunction(), cx, fy) + @test MOI.get(uf, MOI.ConstraintFunction(), cx) ≈ fy + @test MOI.get(uf, MOI.CanonicalConstraintFunction(), cx) ≈ fy + @test MOI.Utilities.is_canonical( + MOI.get(uf, MOI.CanonicalConstraintFunction(), cx), + ) + @test MOI.supports(uf, MOI.ConstraintName(), typeof(cx)) + MOI.set(uf, MOI.ConstraintName(), cx, "EqualTo") + @test MOI.get(uf, MOI.ConstraintName(), cx) == "EqualTo" + @test MOI.get(uf, typeof(cx), "EqualTo") == cx + MOI.delete(uf, cx) + @test MOI.get(uf, typeof(cx), "EqualTo") === nothing + return end -@testset "Duplicate names" begin +function test_duplicate_names() model = ModelForUniversalFallback{Float64}() - uf = MOIU.UniversalFallback(model) + uf = MOI.Utilities.UniversalFallback(model) x = MOI.add_variable(uf) # These are both intercepted by the fallback. - function _affine(vi) - return convert( - MOI.ScalarAffineFunction{Float64}, - MOI.SingleVariable(vi), - ) - end - x_eq = MOI.add_constraint(uf, _affine(x), MOI.EqualTo(1.0)) - x_gt = MOI.add_constraint(uf, _affine(x), MOI.GreaterThan(1.0)) + f = MOI.ScalarAffineFunction{Float64}( + [MOI.ScalarAffineTerm(1.0, x)], + 0.0, + ) + x_eq = MOI.add_constraint(uf, f, MOI.EqualTo(1.0)) + x_gt = MOI.add_constraint(uf, f, MOI.GreaterThan(1.0)) MOI.set(uf, MOI.ConstraintName(), x_eq, "a name") MOI.set(uf, MOI.ConstraintName(), x_gt, "a name") @test_throws Exception MOI.get( @@ -324,26 +332,31 @@ end "a name", ) @test_throws Exception MOI.get(uf, MOI.ConstraintIndex, "a name") + return end -@testset "Deterministic constraint ordering" begin - F = MOI.ScalarAffineFunction{Float64} - _affine(vi) = convert(F, MOI.SingleVariable(vi)) +function test_deterministic_constraint_ordering() + model = ModelForUniversalFallback{Float64}() + uf = MOI.Utilities.UniversalFallback(model) set1 = MOI.EqualTo(1.0) set2 = MOI.GreaterThan(1.0) + F = MOI.ScalarAffineFunction{Float64} for sets in [[set1, set2], [set2, set1]] model = ModelForUniversalFallback{Float64}() - uf = MOIU.UniversalFallback(model) + uf = MOI.Utilities.UniversalFallback(model) x = MOI.add_variable(uf) y = MOI.add_variable(uf) - cx1 = MOI.add_constraint(uf, _affine(x), sets[1]) - cx2 = MOI.add_constraint(uf, _affine(x), sets[2]) - cy1 = MOI.add_constraint(uf, _affine(y), sets[1]) - cy2 = MOI.add_constraint(uf, _affine(y), sets[2]) + fx = MOI.ScalarAffineFunction([MOI.ScalarAffineTerm(1.0, x)], 0.0) + fy = MOI.ScalarAffineFunction([MOI.ScalarAffineTerm(1.0, y)], 0.0) + MOI.add_constraint(uf, fx, sets[1]) + MOI.add_constraint(uf, fx, sets[2]) + MOI.add_constraint(uf, fy, sets[1]) + MOI.add_constraint(uf, fy, sets[2]) # check that the constraint types are in the order they were added in @test MOI.get(uf, MOI.ListOfConstraintTypesPresent()) == [(F, typeof(sets[1])), (F, typeof(sets[2]))] - # check that the constraints given the constraint type are in the order they were added in + # check that the constraints given the constraint type are in the order + # they were added in for set in sets @test MOI.get(uf, MOI.ListOfConstraintIndices{F,typeof(set)}()) == [ MOI.ConstraintIndex{F,typeof(set)}(1), @@ -351,18 +364,18 @@ end ] end end + return end -@testset "Delete" begin +function test_show() model = ModelForUniversalFallback{Float64}() - uf = MOIU.UniversalFallback(model) - MOIT.delete_test(uf) -end - -@testset "Show" begin - model = ModelForUniversalFallback{Float64}() - uf = MOIU.UniversalFallback(model) + uf = MOI.Utilities.UniversalFallback(model) @test sprint(show, uf) == MOI.Utilities.replace_acronym(""" - $(MOIU.UniversalFallback{ModelForUniversalFallback{Float64}}) + $(MOI.Utilities.UniversalFallback{ModelForUniversalFallback{Float64}}) fallback for $(ModelForUniversalFallback{Float64})""") + return end + +end # module + +TestUniversalFallback.runtests() From c701f7c8e676c648844a152ecbb782dfa13395e8 Mon Sep 17 00:00:00 2001 From: odow Date: Mon, 5 Jul 2021 13:34:22 +1200 Subject: [PATCH 2/4] Fix formatting --- test/Utilities/universalfallback.jl | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/test/Utilities/universalfallback.jl b/test/Utilities/universalfallback.jl index 23e0b2ede4..054ddcb4e1 100644 --- a/test/Utilities/universalfallback.jl +++ b/test/Utilities/universalfallback.jl @@ -86,7 +86,6 @@ function test_MOI_Test() return end - function _test_Optimizer_Model_attributes(uf, model, attr, listattr) @test !MOI.supports(model, attr) @test MOI.supports(uf, attr) @@ -179,7 +178,7 @@ function test_variable_attributes() MOI.ListOfVariableAttributesSet(), MOI.VariableIndex, MOI.add_variable, - MOI.add_variables(uf, 3)... + MOI.add_variables(uf, 3)..., ) return end @@ -315,10 +314,7 @@ function test_duplicate_names() uf = MOI.Utilities.UniversalFallback(model) x = MOI.add_variable(uf) # These are both intercepted by the fallback. - f = MOI.ScalarAffineFunction{Float64}( - [MOI.ScalarAffineTerm(1.0, x)], - 0.0, - ) + f = MOI.ScalarAffineFunction{Float64}([MOI.ScalarAffineTerm(1.0, x)], 0.0) x_eq = MOI.add_constraint(uf, f, MOI.EqualTo(1.0)) x_gt = MOI.add_constraint(uf, f, MOI.GreaterThan(1.0)) MOI.set(uf, MOI.ConstraintName(), x_eq, "a name") @@ -373,7 +369,7 @@ function test_show() @test sprint(show, uf) == MOI.Utilities.replace_acronym(""" $(MOI.Utilities.UniversalFallback{ModelForUniversalFallback{Float64}}) fallback for $(ModelForUniversalFallback{Float64})""") - return + return end end # module From 8d87519a8f0e518d3c16b1281461127f7b7e0dd6 Mon Sep 17 00:00:00 2001 From: odow Date: Mon, 5 Jul 2021 14:39:48 +1200 Subject: [PATCH 3/4] Add more tests --- src/Utilities/universalfallback.jl | 5 +---- test/Utilities/universalfallback.jl | 2 ++ 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Utilities/universalfallback.jl b/src/Utilities/universalfallback.jl index 6238896fbd..8c8eaf1c40 100644 --- a/src/Utilities/universalfallback.jl +++ b/src/Utilities/universalfallback.jl @@ -766,11 +766,8 @@ end function constraints( uf::UniversalFallback, - ci::MOI.ConstraintIndex{F,S}, + ::MOI.ConstraintIndex{F,S}, ) where {F,S} - if !MOI.supports_constraint(uf, F, S) - throw(MOI.InvalidIndex(ci)) - end return constraints(uf, F, S) end diff --git a/test/Utilities/universalfallback.jl b/test/Utilities/universalfallback.jl index 054ddcb4e1..6f7e4a22c2 100644 --- a/test/Utilities/universalfallback.jl +++ b/test/Utilities/universalfallback.jl @@ -212,6 +212,8 @@ function test_unsupported_objective_attributes() 0.0, ) @test MOI.get(uf, attr) ≈ new_obj + @test attr in MOI.get(uf, MOI.ListOfModelAttributesSet()) + @test MOI.get(uf, MOI.ObjectiveFunctionType()) == MOI.ScalarAffineFunction{Float64} return end From 7dc2980c5ee8ee265909a7fe3a9f427335e7888d Mon Sep 17 00:00:00 2001 From: odow Date: Mon, 5 Jul 2021 14:43:06 +1200 Subject: [PATCH 4/4] Fix formatting --- test/Utilities/universalfallback.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/Utilities/universalfallback.jl b/test/Utilities/universalfallback.jl index 6f7e4a22c2..cde177e20d 100644 --- a/test/Utilities/universalfallback.jl +++ b/test/Utilities/universalfallback.jl @@ -213,7 +213,8 @@ function test_unsupported_objective_attributes() ) @test MOI.get(uf, attr) ≈ new_obj @test attr in MOI.get(uf, MOI.ListOfModelAttributesSet()) - @test MOI.get(uf, MOI.ObjectiveFunctionType()) == MOI.ScalarAffineFunction{Float64} + @test MOI.get(uf, MOI.ObjectiveFunctionType()) == + MOI.ScalarAffineFunction{Float64} return end