From 53ae41b9d2ffd0615d652d5b762ba0543cdcbc32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Thu, 25 Oct 2018 14:51:17 +0200 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=90=9B=20Fix=20error=20with=20Unknown?= =?UTF-8?q?Set?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Test/modellike.jl | 13 +++++++------ test/Test/modellike.jl | 7 +++++++ test/dummy.jl | 9 +++++++++ 3 files changed, 23 insertions(+), 6 deletions(-) create mode 100644 test/Test/modellike.jl diff --git a/src/Test/modellike.jl b/src/Test/modellike.jl index 239259349c..bfe450e4f3 100644 --- a/src/Test/modellike.jl +++ b/src/Test/modellike.jl @@ -1,6 +1,7 @@ # TODO: Move generic model tests from MOIU to here -struct UnknownSet <: MOI.AbstractSet end +struct UnknownScalarSet <: MOI.AbstractScalarSet end +struct UnknownVectorSet <: MOI.AbstractVectorSet end function nametest(model::MOI.ModelLike) @testset "Name test" begin @@ -145,9 +146,9 @@ MOI.get(::BadModel, ::MOI.ConstraintSet, ::MOI.ConstraintIndex{MOI.SingleVariabl MOI.get(::BadModel, ::MOI.ListOfConstraintAttributesSet) = MOI.AbstractConstraintAttribute[] struct BadConstraintModel <: BadModel end -MOI.get(::BadConstraintModel, ::MOI.ListOfConstraints) = [(MOI.SingleVariable, MOI.EqualTo{Float64}), (MOI.SingleVariable, UnknownSet)] -MOI.get(::BadModel, ::MOI.ConstraintFunction, ::MOI.ConstraintIndex{MOI.SingleVariable,UnknownSet}) = MOI.SingleVariable(MOI.VariableIndex(1)) -MOI.get(::BadModel, ::MOI.ConstraintSet, ::MOI.ConstraintIndex{MOI.SingleVariable,UnknownSet}) = UnknownSet() +MOI.get(::BadConstraintModel, ::MOI.ListOfConstraints) = [(MOI.SingleVariable, MOI.EqualTo{Float64}), (MOI.SingleVariable, UnknownScalarSet)] +MOI.get(::BadModel, ::MOI.ConstraintFunction, ::MOI.ConstraintIndex{MOI.SingleVariable,UnknownScalarSet}) = MOI.SingleVariable(MOI.VariableIndex(1)) +MOI.get(::BadModel, ::MOI.ConstraintSet, ::MOI.ConstraintIndex{MOI.SingleVariable,UnknownScalarSet}) = UnknownScalarSet() struct UnknownModelAttribute <: MOI.AbstractModelAttribute end struct BadModelAttributeModel <: BadModel end @@ -165,7 +166,7 @@ MOI.get(::BadConstraintAttributeModel, ::UnknownConstraintAttribute, ::MOI.Const MOI.get(::BadConstraintAttributeModel, ::MOI.ListOfConstraintAttributesSet) = MOI.AbstractConstraintAttribute[UnknownConstraintAttribute()] function failcopytestc(dest::MOI.ModelLike) - @test !MOI.supports_constraint(dest, MOI.SingleVariable, UnknownSet) + @test !MOI.supports_constraint(dest, MOI.SingleVariable, UnknownScalarSet) @test_throws MOI.UnsupportedConstraint MOI.copy_to(dest, BadConstraintModel()) end function failcopytestia(dest::MOI.ModelLike) @@ -253,7 +254,7 @@ function supports_constrainttest(model::MOI.ModelLike, ::Type{GoodT}, ::Type{Bad @test MOI.supports_constraint(model, MOI.VectorOfVariables, MOI.Zeros) @test !MOI.supports_constraint(model, MOI.VectorOfVariables, MOI.EqualTo{GoodT}) # vector in scalar @test !MOI.supports_constraint(model, MOI.SingleVariable, MOI.Zeros) # scalar in vector - @test !MOI.supports_constraint(model, MOI.VectorOfVariables, UnknownSet) # set not supported + @test !MOI.supports_constraint(model, MOI.VectorOfVariables, UnknownVectorSet) # set not supported end """ diff --git a/test/Test/modellike.jl b/test/Test/modellike.jl new file mode 100644 index 0000000000..c3e85f5e49 --- /dev/null +++ b/test/Test/modellike.jl @@ -0,0 +1,7 @@ +@testset "ModelLike" begin + model = DummyModel() + MOIT.failcopytestc(model) + MOIT.failcopytestia(model) + MOIT.failcopytestva(model) + MOIT.failcopytestca(model) +end diff --git a/test/dummy.jl b/test/dummy.jl index 8a980f1366..f8799ac696 100644 --- a/test/dummy.jl +++ b/test/dummy.jl @@ -1,9 +1,18 @@ struct DummyModel <: MOI.ModelLike end +MOI.add_variable(::DummyModel) = MOI.VariableIndex(0) +function MOI.empty!(::DummyModel) end +function MOI.copy_to(dest::DummyModel, src::MOI.ModelLike; copy_names=true) + return MOIU.default_copy_to(dest, src, copy_names) +end MOI.supports(::DummyModel, ::MOI.ObjectiveSense) = true MOI.supports(::DummyModel, ::MOI.ConstraintPrimalStart, ::Type{<:MOI.ConstraintIndex}) = true MOI.supports_constraint(::DummyModel, ::Type{MOI.SingleVariable}, ::Type{MOI.EqualTo{Float64}}) = true +function MOI.add_constraint(::DummyModel, ::MOI.SingleVariable, + ::MOI.EqualTo{Float64}) + return MOI.ConstraintIndex{MOI.SingleVariable, MOI.EqualTo{Float64}}(0) +end MOI.supports_constraint(::DummyModel, ::Type{MOI.VectorOfVariables}, ::Type{MOI.Zeros}) = true From adf58cbdbd9911384ca1aeac2b69b372267b5fbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Thu, 25 Oct 2018 16:08:23 +0200 Subject: [PATCH 2/3] Fix DummyModel --- test/Test/modellike.jl | 2 +- test/attributes.jl | 2 +- test/dummy.jl | 7 ++++--- test/errors.jl | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/test/Test/modellike.jl b/test/Test/modellike.jl index c3e85f5e49..fb70e94d83 100644 --- a/test/Test/modellike.jl +++ b/test/Test/modellike.jl @@ -1,5 +1,5 @@ @testset "ModelLike" begin - model = DummyModel() + model = DummyModel{true}() MOIT.failcopytestc(model) MOIT.failcopytestia(model) MOIT.failcopytestva(model) diff --git a/test/attributes.jl b/test/attributes.jl index 8100246cfb..daa72fa0d3 100644 --- a/test/attributes.jl +++ b/test/attributes.jl @@ -10,7 +10,7 @@ @test MOI.is_copyable(MOI.ObjectiveSense()) end @testset "supports" begin - model = DummyModel() + model = DummyModel{false}() @test_throws ArgumentError MOI.supports(model, MOI.TerminationStatus()) @test_throws ArgumentError begin MOI.supports(model, MOI.ConstraintSet(), diff --git a/test/dummy.jl b/test/dummy.jl index f8799ac696..96a64e7cf0 100644 --- a/test/dummy.jl +++ b/test/dummy.jl @@ -1,6 +1,7 @@ -struct DummyModel <: MOI.ModelLike +# DummyModel{true} implements add_variable and add_constraint +struct DummyModel{A} <: MOI.ModelLike end -MOI.add_variable(::DummyModel) = MOI.VariableIndex(0) +MOI.add_variable(::DummyModel{true}) = MOI.VariableIndex(0) function MOI.empty!(::DummyModel) end function MOI.copy_to(dest::DummyModel, src::MOI.ModelLike; copy_names=true) return MOIU.default_copy_to(dest, src, copy_names) @@ -10,7 +11,7 @@ MOI.supports(::DummyModel, ::MOI.ConstraintPrimalStart, ::Type{<:MOI.ConstraintIndex}) = true MOI.supports_constraint(::DummyModel, ::Type{MOI.SingleVariable}, ::Type{MOI.EqualTo{Float64}}) = true -function MOI.add_constraint(::DummyModel, ::MOI.SingleVariable, +function MOI.add_constraint(::DummyModel{true}, ::MOI.SingleVariable, ::MOI.EqualTo{Float64}) return MOI.ConstraintIndex{MOI.SingleVariable, MOI.EqualTo{Float64}}(0) end diff --git a/test/errors.jl b/test/errors.jl index bf59bfc47a..336ebdf54a 100644 --- a/test/errors.jl +++ b/test/errors.jl @@ -1,5 +1,5 @@ @testset "Fallbacks for `set` methods" begin - model = DummyModel() + model = DummyModel{false}() @testset "AddVariableNotAllowed" begin @test_throws MOI.AddVariableNotAllowed MOI.add_variable(model) From 8e59d3a4b76dce27184f2a928e17f6d0913922fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Fri, 26 Oct 2018 10:06:29 +0200 Subject: [PATCH 3/3] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Refactor=20DummyModel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/Test/modellike.jl | 2 +- test/attributes.jl | 2 +- test/dummy.jl | 30 ++++++++++++++++++------------ test/errors.jl | 2 +- 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/test/Test/modellike.jl b/test/Test/modellike.jl index fb70e94d83..561483a797 100644 --- a/test/Test/modellike.jl +++ b/test/Test/modellike.jl @@ -1,5 +1,5 @@ @testset "ModelLike" begin - model = DummyModel{true}() + model = DummyModelWithAdd() MOIT.failcopytestc(model) MOIT.failcopytestia(model) MOIT.failcopytestva(model) diff --git a/test/attributes.jl b/test/attributes.jl index daa72fa0d3..8100246cfb 100644 --- a/test/attributes.jl +++ b/test/attributes.jl @@ -10,7 +10,7 @@ @test MOI.is_copyable(MOI.ObjectiveSense()) end @testset "supports" begin - model = DummyModel{false}() + model = DummyModel() @test_throws ArgumentError MOI.supports(model, MOI.TerminationStatus()) @test_throws ArgumentError begin MOI.supports(model, MOI.ConstraintSet(), diff --git a/test/dummy.jl b/test/dummy.jl index 96a64e7cf0..e9b6081306 100644 --- a/test/dummy.jl +++ b/test/dummy.jl @@ -1,19 +1,25 @@ -# DummyModel{true} implements add_variable and add_constraint -struct DummyModel{A} <: MOI.ModelLike -end -MOI.add_variable(::DummyModel{true}) = MOI.VariableIndex(0) -function MOI.empty!(::DummyModel) end -function MOI.copy_to(dest::DummyModel, src::MOI.ModelLike; copy_names=true) +abstract type AbstractDummyModel <: MOI.ModelLike end + +function MOI.empty!(::AbstractDummyModel) end +function MOI.copy_to(dest::AbstractDummyModel, src::MOI.ModelLike; copy_names=true) return MOIU.default_copy_to(dest, src, copy_names) end -MOI.supports(::DummyModel, ::MOI.ObjectiveSense) = true -MOI.supports(::DummyModel, ::MOI.ConstraintPrimalStart, +MOI.supports(::AbstractDummyModel, ::MOI.ObjectiveSense) = true +MOI.supports(::AbstractDummyModel, ::MOI.ConstraintPrimalStart, ::Type{<:MOI.ConstraintIndex}) = true -MOI.supports_constraint(::DummyModel, ::Type{MOI.SingleVariable}, +MOI.supports_constraint(::AbstractDummyModel, ::Type{MOI.SingleVariable}, ::Type{MOI.EqualTo{Float64}}) = true -function MOI.add_constraint(::DummyModel{true}, ::MOI.SingleVariable, +MOI.supports_constraint(::AbstractDummyModel, ::Type{MOI.VectorOfVariables}, + ::Type{MOI.Zeros}) = true + +struct DummyModel <: AbstractDummyModel +end + +# Implements add_variable and add_constraint +struct DummyModelWithAdd <: AbstractDummyModel +end +MOI.add_variable(::DummyModelWithAdd) = MOI.VariableIndex(0) +function MOI.add_constraint(::DummyModelWithAdd, ::MOI.SingleVariable, ::MOI.EqualTo{Float64}) return MOI.ConstraintIndex{MOI.SingleVariable, MOI.EqualTo{Float64}}(0) end -MOI.supports_constraint(::DummyModel, ::Type{MOI.VectorOfVariables}, - ::Type{MOI.Zeros}) = true diff --git a/test/errors.jl b/test/errors.jl index 336ebdf54a..bf59bfc47a 100644 --- a/test/errors.jl +++ b/test/errors.jl @@ -1,5 +1,5 @@ @testset "Fallbacks for `set` methods" begin - model = DummyModel{false}() + model = DummyModel() @testset "AddVariableNotAllowed" begin @test_throws MOI.AddVariableNotAllowed MOI.add_variable(model)