Skip to content

Commit 8e59d3a

Browse files
committed
♻️ Refactor DummyModel
1 parent adf58cb commit 8e59d3a

File tree

4 files changed

+21
-15
lines changed

4 files changed

+21
-15
lines changed

test/Test/modellike.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@testset "ModelLike" begin
2-
model = DummyModel{true}()
2+
model = DummyModelWithAdd()
33
MOIT.failcopytestc(model)
44
MOIT.failcopytestia(model)
55
MOIT.failcopytestva(model)

test/attributes.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
@test MOI.is_copyable(MOI.ObjectiveSense())
1111
end
1212
@testset "supports" begin
13-
model = DummyModel{false}()
13+
model = DummyModel()
1414
@test_throws ArgumentError MOI.supports(model, MOI.TerminationStatus())
1515
@test_throws ArgumentError begin
1616
MOI.supports(model, MOI.ConstraintSet(),

test/dummy.jl

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
1-
# DummyModel{true} implements add_variable and add_constraint
2-
struct DummyModel{A} <: MOI.ModelLike
3-
end
4-
MOI.add_variable(::DummyModel{true}) = MOI.VariableIndex(0)
5-
function MOI.empty!(::DummyModel) end
6-
function MOI.copy_to(dest::DummyModel, src::MOI.ModelLike; copy_names=true)
1+
abstract type AbstractDummyModel <: MOI.ModelLike end
2+
3+
function MOI.empty!(::AbstractDummyModel) end
4+
function MOI.copy_to(dest::AbstractDummyModel, src::MOI.ModelLike; copy_names=true)
75
return MOIU.default_copy_to(dest, src, copy_names)
86
end
9-
MOI.supports(::DummyModel, ::MOI.ObjectiveSense) = true
10-
MOI.supports(::DummyModel, ::MOI.ConstraintPrimalStart,
7+
MOI.supports(::AbstractDummyModel, ::MOI.ObjectiveSense) = true
8+
MOI.supports(::AbstractDummyModel, ::MOI.ConstraintPrimalStart,
119
::Type{<:MOI.ConstraintIndex}) = true
12-
MOI.supports_constraint(::DummyModel, ::Type{MOI.SingleVariable},
10+
MOI.supports_constraint(::AbstractDummyModel, ::Type{MOI.SingleVariable},
1311
::Type{MOI.EqualTo{Float64}}) = true
14-
function MOI.add_constraint(::DummyModel{true}, ::MOI.SingleVariable,
12+
MOI.supports_constraint(::AbstractDummyModel, ::Type{MOI.VectorOfVariables},
13+
::Type{MOI.Zeros}) = true
14+
15+
struct DummyModel <: AbstractDummyModel
16+
end
17+
18+
# Implements add_variable and add_constraint
19+
struct DummyModelWithAdd <: AbstractDummyModel
20+
end
21+
MOI.add_variable(::DummyModelWithAdd) = MOI.VariableIndex(0)
22+
function MOI.add_constraint(::DummyModelWithAdd, ::MOI.SingleVariable,
1523
::MOI.EqualTo{Float64})
1624
return MOI.ConstraintIndex{MOI.SingleVariable, MOI.EqualTo{Float64}}(0)
1725
end
18-
MOI.supports_constraint(::DummyModel, ::Type{MOI.VectorOfVariables},
19-
::Type{MOI.Zeros}) = true

test/errors.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@testset "Fallbacks for `set` methods" begin
2-
model = DummyModel{false}()
2+
model = DummyModel()
33

44
@testset "AddVariableNotAllowed" begin
55
@test_throws MOI.AddVariableNotAllowed MOI.add_variable(model)

0 commit comments

Comments
 (0)