From 2b19cfd39834ac5a604fdba874adfcd9d6715353 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Thu, 21 Dec 2023 13:56:16 +0100 Subject: [PATCH] Add tests --- test/Utilities/cachingoptimizer.jl | 53 +++++++++++++++++++++++++----- 1 file changed, 45 insertions(+), 8 deletions(-) diff --git a/test/Utilities/cachingoptimizer.jl b/test/Utilities/cachingoptimizer.jl index 534168cfb5..3173819a54 100644 --- a/test/Utilities/cachingoptimizer.jl +++ b/test/Utilities/cachingoptimizer.jl @@ -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( @@ -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}(), @@ -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)),