Skip to content

Commit

Permalink
Improve test coverage (#444)
Browse files Browse the repository at this point in the history
  • Loading branch information
odow authored Nov 24, 2024
1 parent 06b5371 commit 739042f
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions test/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ end

function test_ConstraintDualStart()
model = Ipopt.Optimizer()
MOI.set(model, MOI.Silent(), true)
x = MOI.add_variables(model, 2)
l = MOI.add_constraint(model, x[1], MOI.GreaterThan(1.0))
u = MOI.add_constraint(model, x[1], MOI.LessThan(1.0))
Expand Down Expand Up @@ -748,6 +749,39 @@ function test_RawOptimizerAttribute()
return
end

function test_empty_nlp_evaluator()
model = Ipopt.Optimizer()
block = MOI.get(model, MOI.NLPBlock())
evaluator = block.evaluator
@test MOI.features_available(evaluator) == [:Grad, :Jac, :Hess]
MOI.initialize(evaluator, [:Grad, :Jac, :Hess])
x = Float64[]
@test MOI.eval_constraint(evaluator, Float64[], x) === nothing
@test MOI.jacobian_structure(evaluator) == Tuple{Int,Int}[]
@test MOI.hessian_lagrangian_structure(evaluator) == Tuple{Int,Int}[]
@test MOI.eval_constraint_jacobian(evaluator, Float64[], x) === nothing
H, mu = Float64[], Float64[]
@test MOI.eval_hessian_lagrangian(evaluator, H, x, 1.0, mu) === nothing
return
end

function test_NLPBlockDualStart()
model = Ipopt.Optimizer()
MOI.set(model, MOI.Silent(), true)
x = MOI.add_variables(model, 4)
MOI.set.(model, MOI.VariablePrimalStart(), x, 1.0)
block = MOI.NLPBlockData(
MOI.NLPBoundsPair.([25.0, 40.0], [Inf, 40.0]),
MOI.Test.HS071(false),
true,
)
MOI.set(model, MOI.NLPBlock(), block)
MOI.set(model, MOI.NLPBlockDualStart(), [1.0, -1.0])
MOI.optimize!(model)
@test isapprox(MOI.get(model, MOI.NLPBlockDual()), [0.0, 0.0]; atol = 1e-6)
return
end

function test_function_type_to_func()
model = Ipopt.Optimizer()
x = MOI.add_variable(model)
Expand Down

0 comments on commit 739042f

Please sign in to comment.