Skip to content

Commit 3659bf0

Browse files
authored
Add tests to improve code coverage (#199)
1 parent 5ebde24 commit 3659bf0

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

test/runtests.jl

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,19 @@ function test_node_count()
646646
return
647647
end
648648

649+
function test_objective_bound_relative_gap()
650+
model = MosekOptimizerWithFallback()
651+
@test isnan(MOI.get(model, MOI.ObjectiveBound()))
652+
_solve_knapsack_model(model, 100)
653+
@test isapprox(
654+
MOI.get(model, MOI.ObjectiveBound()),
655+
MOI.get(model, MOI.ObjectiveValue());
656+
rtol = 1e-6,
657+
)
658+
@test MOI.get(model, MOI.RelativeGap()) < 1e-6
659+
return
660+
end
661+
649662
function test_variable_primal_start()
650663
model = MosekOptimizerWithFallback()
651664
set = MOI.PositiveSemidefiniteConeTriangle(2)
@@ -740,6 +753,38 @@ function test_write_to_file()
740753
return
741754
end
742755

756+
function test_basis_status_code()
757+
attr = MOI.VariableBasisStatus()
758+
@test_throws(
759+
MOI.GetAttributeNotAllowed{typeof(attr)},
760+
MosekTools._basis_status_code(Mosek.MSK_SK_UNK, attr),
761+
)
762+
return
763+
end
764+
765+
function test_objective_modify_psd()
766+
model = Mosek.Optimizer()
767+
set = MOI.PositiveSemidefiniteConeTriangle(2)
768+
x, _ = MOI.add_constrained_variables(model, set)
769+
@test_throws(
770+
MOI.ModifyObjectiveNotAllowed,
771+
MOI.modify(
772+
model,
773+
MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}}(),
774+
MOI.ScalarCoefficientChange(x[1], 1.0),
775+
),
776+
)
777+
return
778+
end
779+
780+
function test_is_scalar()
781+
model = Mosek.Optimizer()
782+
x = MOI.add_variable(model)
783+
MOI.delete(model, x)
784+
@test_throws MOI.InvalidIndex MosekTools.is_scalar(model, x)
785+
return
786+
end
787+
743788
end # module
744789

745790
TestMosekTools.runtests()

0 commit comments

Comments
 (0)