From 5c3939be23f6cfde82184f400d88a0796b9a83a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Fri, 30 Oct 2026 15:15:44 +0100 Subject: [PATCH 1/2] Reset MockOptimizer result count in empty! When MockOptimizer reports results, empty! clears its stored solutions but leaves ResultCount at the previous value. Reset the count to zero so result queries correctly raise ResultIndexBoundsError after emptying the model. Add a regression covering previous result counts of zero, one, and two, as well as the objective-value result-index bounds check. Validation: all tests in test/Utilities/test_mockoptimizer.jl pass; JuliaFormatter 2.14.0. --- src/Utilities/mockoptimizer.jl | 1 + test/Utilities/test_mockoptimizer.jl | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/Utilities/mockoptimizer.jl b/src/Utilities/mockoptimizer.jl index 00c833b04e..a28525bb02 100644 --- a/src/Utilities/mockoptimizer.jl +++ b/src/Utilities/mockoptimizer.jl @@ -821,6 +821,7 @@ function MOI.empty!(mock::MockOptimizer) empty!(mock.mock_constraint_attribute) mock.optimize_called = false mock.termination_status = MOI.OPTIMIZE_NOT_CALLED + mock.result_count = 0 mock.compute_conflict_called = false mock.conflict_status = MOI.COMPUTE_CONFLICT_NOT_CALLED empty!(mock.constraint_conflict_status) diff --git a/test/Utilities/test_mockoptimizer.jl b/test/Utilities/test_mockoptimizer.jl index 1d297f72b6..955267340c 100644 --- a/test/Utilities/test_mockoptimizer.jl +++ b/test/Utilities/test_mockoptimizer.jl @@ -308,6 +308,22 @@ function test_empty_constructor() return end +function test_empty_result_count() + optimizer = MOIU.MockOptimizer(MOIU.Model{Float64}()) + for result_count in (0, 1, 2) + MOI.add_variable(optimizer) + MOI.set(optimizer, MOI.ResultCount(), result_count) + MOI.empty!(optimizer) + @test MOI.is_empty(optimizer) + @test MOI.get(optimizer, MOI.ResultCount()) == 0 + @test_throws( + MOI.ResultIndexBoundsError(MOI.ObjectiveValue(1), 0), + MOI.get(optimizer, MOI.ObjectiveValue(1)), + ) + end + return +end + function test_delete_mock_variable() model = MOI.Utilities.MockOptimizer(MOI.Utilities.Model{Float64}()) x = MOI.add_variables(model, 3) From 63af5eded50b8b17c696b46ef489cf161a342fe4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Fri, 30 Oct 2026 19:38:57 +0100 Subject: [PATCH 2/2] Declare a result in the cached mock status test Attaching the cache empties the mock and resets its result count. Set ResultCount to one before configuring the feasible status. --- test/Utilities/test_cachingoptimizer.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/test/Utilities/test_cachingoptimizer.jl b/test/Utilities/test_cachingoptimizer.jl index 3b26306a0e..3514c9702e 100644 --- a/test/Utilities/test_cachingoptimizer.jl +++ b/test/Utilities/test_cachingoptimizer.jl @@ -757,6 +757,7 @@ function test_status_codes() optimizer, ) MOI.Utilities.attach_optimizer(model) + MOI.set(optimizer, MOI.ResultCount(), 1) MOI.set(optimizer, MOI.TerminationStatus(), MOI.OPTIMAL) MOI.set(optimizer, MOI.PrimalStatus(), MOI.FEASIBLE_POINT) @test MOI.get(model, MOI.TerminationStatus()) == MOI.OPTIMAL