Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat committed Mar 26, 2024
1 parent d1e34b2 commit 05e6f99
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/QCQP/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ end
MOI.is_valid(model::Optimizer, i::MOI.Index) = MOI.is_valid(model.model, i)
function MOI.is_valid(
model::Optimizer{T},
::MOI.ConstraintIndex{PolyJuMP.ScalarPolynomialFunction{T},S},
ci::MOI.ConstraintIndex{<:PolyJuMP.ScalarPolynomialFunction{T},S},
) where {T,S<:MOI.AbstractScalarSet}
return haskey(model.constraints, S) &&
MOI.is_valid(model.constraints[S][2], ci)
Expand Down
12 changes: 11 additions & 1 deletion test/qcqp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ import MultivariatePolynomials as MP
import PolyJuMP
import JuMP

function test_solver_name(_, _, _)
model = Model{Float64}()
inner = MOI.Utilities.MockOptimizer(model)
# We don't specify `T` to test the fallback
optimizer = PolyJuMP.QCQP.Optimizer(inner)
@test optimizer isa PolyJuMP.QCQP.Optimizer{Float64}
@test MOI.get(optimizer, MOI.SolverName()) == "PolyJuMP.QCQP with Mock"
end

function _test_decompose(monos, exps)
vars = MP.variables(monos)
M = eltype(monos)
Expand Down Expand Up @@ -320,7 +329,8 @@ function test_start(x, y, T)
b = MOI.add_variable(model)
MOI.set(model, MOI.VariablePrimalStart(), b, 3one(T))
p = PolyJuMP.ScalarPolynomialFunction(one(T) * x^3 - x * y^2, [a, b])
MOI.add_constraint(model, p, MOI.LessThan(zero(T)))
ci = MOI.add_constraint(model, p, MOI.LessThan(zero(T)))
@test MOI.is_valid(model, ci)
MOI.Utilities.final_touch(model, nothing)
vis = MOI.get(inner, MOI.ListOfVariableIndices())
@test sort(MOI.get(inner, MOI.VariablePrimalStart(), vis)) == T[2, 3, 4, 9]
Expand Down

0 comments on commit 05e6f99

Please sign in to comment.