Skip to content

Commit

Permalink
Add more tests to improve code coverage (#215)
Browse files Browse the repository at this point in the history
  • Loading branch information
odow authored Jun 19, 2024
1 parent b5d5a3f commit 5459398
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,9 @@ mutable struct Optimizer <: MOI.AbstractOptimizer
_Solution(),
)
MOI.empty!(model)
@static if Sys.iswindows()
# Set number of threads by default on Windows. This fixes a
# hang in some versions of Highs_jll. For discussion, see
if Sys.iswindows()
# Set number of threads by default on Windows. This fixes a hang in
# some versions of Highs_jll. For discussion, see
# https://github.com/ERGO-Code/HiGHS/issues/1257
n_threads = max(1, div(length(Sys.cpu_info()), 2))
MOI.set(model, MOI.NumberOfThreads(), n_threads)
Expand Down
38 changes: 38 additions & 0 deletions test/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,44 @@ function test_copy_to_unsupported_constraint()
return
end

function test_delete_constraint_twice()
model = HiGHS.Optimizer()
x = MOI.add_variable(model)
ci = MOI.add_constraint(model, 1.0 * x, MOI.EqualTo(1.0))
@test_throws(
ErrorException(
"Encountered an error in HiGHS (Status -1). Check the log " *
"for details.",
),
MOI.delete(model, [ci, ci]),
)
return
end

function test_RawStatusStringOptimizeNotCalled()
model = HiGHS.Optimizer()
@test MOI.get(model, MOI.RawStatusString()) == "OPTIMIZE_NOT_CALLED"
@test MOI.get(model, MOI.ResultCount()) == 0
return
end

function test_nonbasic_equality_constraint()
model = HiGHS.Optimizer()
x = MOI.add_variable(model)
ci = MOI.add_constraint(model, 1.0 * x, MOI.EqualTo(1.0))
MOI.optimize!(model)
@test MOI.get(model, MOI.ConstraintBasisStatus(), ci) == MOI.NONBASIC
return
end

function test_variable_basis_status_zero()
model = HiGHS.Optimizer()
x = MOI.add_variable(model)
MOI.optimize!(model)
@test MOI.get(model, MOI.VariableBasisStatus(), x) == MOI.NONBASIC
return
end

end # module

TestMOIHighs.runtests()

0 comments on commit 5459398

Please sign in to comment.