Skip to content

Commit bcbeff2

Browse files
committed
Improve code coverage
1 parent ad72a47 commit bcbeff2

1 file changed

Lines changed: 14 additions & 12 deletions

File tree

test/Tests/test_attributes.jl

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,12 @@ function _test_constraint_attribute(; constrained_variable::Bool, vector::Bool)
5050
MOI.Utilities.UniversalFallback(MOI.Utilities.Model{T}());
5151
eval_variable_constraint_dual = false,
5252
)
53-
dual = MOI.Utilities.CachingOptimizer(
53+
cached = MOI.Utilities.CachingOptimizer(
5454
MOI.Utilities.UniversalFallback(MOI.Utilities.Model{T}()),
5555
MOI.Utilities.MANUAL, # easier to debug with less try-catch hidding stuff
5656
)
57-
MOI.Utilities.reset_optimizer(dual, Dualization.DualOptimizer(mock))
57+
dual = Dualization.DualOptimizer(mock)
58+
MOI.Utilities.reset_optimizer(cached, dual)
5859
set_constant = T(-4)
5960
if vector
6061
set = MOI.Nonnegatives(1)
@@ -63,24 +64,24 @@ function _test_constraint_attribute(; constrained_variable::Bool, vector::Bool)
6364
end
6465
if constrained_variable
6566
if vector
66-
X, ci = MOI.add_constrained_variables(dual, set)
67+
X, ci = MOI.add_constrained_variables(cached, set)
6768
x = X[]
6869
else
69-
x, ci = MOI.add_constrained_variable(dual, set)
70+
x, ci = MOI.add_constrained_variable(cached, set)
7071
end
7172
else
72-
x = MOI.add_variable(dual)
73+
x = MOI.add_variable(cached)
7374
func = T(1) * x
7475
if vector
7576
func = MOI.Utilities.operate(vcat, T, func - set_constant)
7677
end
77-
ci = MOI.add_constraint(dual, func, set)
78+
ci = MOI.add_constraint(cached, func, set)
7879
end
79-
MOI.set(dual, MOI.ObjectiveSense(), MOI.MIN_SENSE)
80+
MOI.set(cached, MOI.ObjectiveSense(), MOI.MIN_SENSE)
8081
obj = T(2) * x
81-
MOI.set(dual, MOI.ObjectiveFunction{typeof(obj)}(), obj)
82-
MOI.Utilities.attach_optimizer(dual)
83-
MOI.optimize!(dual)
82+
MOI.set(cached, MOI.ObjectiveFunction{typeof(obj)}(), obj)
83+
MOI.Utilities.attach_optimizer(cached)
84+
MOI.optimize!(cached)
8485
for attr in [MOI.ConstraintDualStart(), MOI.ConstraintPrimalStart()]
8586
attr = MOI.ConstraintDualStart()
8687
@test MOI.supports(dual, attr, typeof(ci))
@@ -93,6 +94,7 @@ function _test_constraint_attribute(; constrained_variable::Bool, vector::Bool)
9394
ci,
9495
value,
9596
)
97+
@test isnothing(MOI.get(dual, attr, ci))
9698
else
9799
MOI.set(dual, attr, ci, value)
98100
@test MOI.get(dual, attr, ci) == value
@@ -110,7 +112,7 @@ function _test_constraint_attribute(; constrained_variable::Bool, vector::Bool)
110112
end
111113
end
112114
#MOI.set(mock, MOI.ConstraintPrimal(), mock_ci, value)
113-
@test MOI.get(dual.optimizer, MOI.ConstraintDual(), ci) value
115+
@test MOI.get(dual, MOI.ConstraintDual(), ci) value
114116

115117
value = rand_value()
116118
if vector && constrained_variable
@@ -124,7 +126,7 @@ function _test_constraint_attribute(; constrained_variable::Bool, vector::Bool)
124126
if !vector
125127
value += set_constant
126128
end
127-
@test MOI.get(dual.optimizer, MOI.ConstraintPrimal(), ci) value
129+
@test MOI.get(dual, MOI.ConstraintPrimal(), ci) value
128130
return
129131
end
130132

0 commit comments

Comments
 (0)