Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat committed Dec 21, 2023
1 parent 79cf79d commit 2b19cfd
Showing 1 changed file with 45 additions and 8 deletions.
53 changes: 45 additions & 8 deletions test/Utilities/cachingoptimizer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -851,13 +851,13 @@ function MOI.get(
return 1.2
end

function MOI.get(
::_GetFallbackModel1310,
::MOI.ConstraintDual,
::MOI.ConstraintIndex,
)
return 1.2
end
#function MOI.get(
# ::_GetFallbackModel1310,
# ::MOI.ConstraintDual,
# ::MOI.ConstraintIndex{MOI.ScalarAffineFunction},
#)
# return 1.2
#end

function test_ConstraintPrimal_fallback()
model = MOI.Utilities.CachingOptimizer(
Expand All @@ -880,6 +880,43 @@ function test_ConstraintPrimal_fallback()
return
end

function test_ConstraintDual_variable_fallback()
model = MOI.Utilities.CachingOptimizer(
MOI.Utilities.Model{Float64}(),
_GetFallbackModel1310(),
)
x = MOI.add_variable(model)
cx = MOI.add_constraint(model, x, MOI.GreaterThan(1.0))
MOI.set(model, MOI.ObjectiveSense(), MOI.MIN_SENSE)
MOI.set(model, MOI.ObjectiveFunction{MOI.VariableIndex}(), x)
MOI.optimize!(model)
@test MOI.get(model, MOI.ConstraintDual(), cx) == 1.0
@test_throws(
MOI.ResultIndexBoundsError(MOI.ConstraintDual(2), 1),
MOI.get(model, MOI.ConstraintDual(2), cx),
)
@test_throws(
MOI.ResultIndexBoundsError(MOI.ConstraintDual(2), 1),
MOI.get(model, MOI.ConstraintDual(2), [cx]),
)
return
end

function test_ConstraintDual_nonvariable_nofallback()
model = MOI.Utilities.CachingOptimizer(
MOI.Utilities.Model{Float64}(),
_GetFallbackModel1310(),
)
x = MOI.add_variable(model)
cx = MOI.add_constraint(model, x + 1.0, MOI.GreaterThan(1.0))
MOI.optimize!(model)
@test_throws(
MOI.GetAttributeNotAllowed,
MOI.get(model, MOI.ConstraintDual(), cx),
)
return
end

function test_ConstraintPrimal_fallback_error()
model = MOI.Utilities.CachingOptimizer(
MOI.Utilities.Model{Float64}(),
Expand Down Expand Up @@ -926,7 +963,7 @@ function test_DualObjectiveValue_fallback()
MOI.set(model, MOI.ObjectiveSense(), MOI.MIN_SENSE)
MOI.set(model, MOI.ObjectiveFunction{typeof(x)}(), x)
MOI.optimize!(model)
@test MOI.get(model, MOI.DualObjectiveValue()) == 1.2
@test MOI.get(model, MOI.DualObjectiveValue()) == 1.0
@test_throws(
MOI.ResultIndexBoundsError(MOI.DualObjectiveValue(2), 1),
MOI.get(model, MOI.DualObjectiveValue(2)),
Expand Down

0 comments on commit 2b19cfd

Please sign in to comment.