Skip to content

Commit a9013b6

Browse files
authored
Add tests to get 100% code coverage (#32)
1 parent 970b78d commit a9013b6

File tree

3 files changed

+45
-13
lines changed

3 files changed

+45
-13
lines changed

src/MOI_wrapper.jl

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
# Use of this source code is governed by an MIT-style license that can be found
44
# in the LICENSE.md file or at https://opensource.org/licenses/MIT.
55

6-
import MathOptInterface as MOI
7-
86
const MAX_MAJITER = 100_000
97
const MAX_ITER = 10_000_000
108

@@ -84,6 +82,7 @@ function MOI.supports(::Optimizer, param::MOI.RawOptimizerAttribute)
8482
return haskey(PIECES_MAP, param.name) ||
8583
hasfield(Parameters, Symbol(param.name))
8684
end
85+
8786
function MOI.set(optimizer::Optimizer, param::MOI.RawOptimizerAttribute, value)
8887
if !MOI.supports(optimizer, param)
8988
throw(MOI.UnsupportedAttribute(param))
@@ -107,6 +106,7 @@ function MOI.set(optimizer::Optimizer, param::MOI.RawOptimizerAttribute, value)
107106
end
108107
return
109108
end
109+
110110
function MOI.get(optimizer::Optimizer, param::MOI.RawOptimizerAttribute)
111111
if !MOI.supports(optimizer, param)
112112
throw(MOI.UnsupportedAttribute(param))
@@ -124,6 +124,7 @@ function MOI.get(optimizer::Optimizer, param::MOI.RawOptimizerAttribute)
124124
end
125125

126126
MOI.supports(::Optimizer, ::MOI.Silent) = true
127+
127128
function MOI.set(optimizer::Optimizer, ::MOI.Silent, value::Bool)
128129
optimizer.silent = value
129130
return
@@ -198,17 +199,6 @@ function MOI.supports_constraint(
198199
return true
199200
end
200201

201-
function _isless(t1::MOI.VectorAffineTerm, t2::MOI.VectorAffineTerm)
202-
if t1.scalar_term.variable.value == t2.scalar_term.variable.value
203-
return isless(t1.output_index, t2.output_index)
204-
else
205-
return isless(
206-
t1.scalar_term.variable.value,
207-
t2.scalar_term.variable.value,
208-
)
209-
end
210-
end
211-
212202
function _next(model::Optimizer, i)
213203
for j in (i+1):length(model.Ainfo_entptr)
214204
if !isempty(model.Ainfo_entptr[j])
@@ -354,6 +344,7 @@ function MOI.get(optimizer::Optimizer, ::MOI.RawStatusString)
354344
optimizer.pieces
355345
return "majiter = $majiter, iter = $iter, λupdate = $λupdate, CG = $CG, curr_CG = $curr_CG, totaltime = $totaltime, σ = , overallsc = $overallsc"
356346
end
347+
357348
function MOI.get(optimizer::Optimizer, ::MOI.SolveTimeSec)
358349
return MOI.get(optimizer, MOI.RawOptimizerAttribute("totaltime"))
359350
end
@@ -477,6 +468,7 @@ function MOI.get(model::Optimizer, ::MOI.ResultCount)
477468
end
478469

479470
struct Factor <: MOI.AbstractConstraintAttribute end
471+
480472
MOI.is_set_by_optimize(::Factor) = true
481473

482474
function MOI.get(

src/SDPLR.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
module SDPLR
77

8+
import MathOptInterface as MOI
89
import SDPLR_jll
910

1011
include("bounds.jl")

test/MOI_wrapper.jl

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,45 @@ function test_runtests()
5050
return
5151
end
5252

53+
function test_RawOptimizerAttribute_UnsupportedAttribute()
54+
model = SDPLR.Optimizer()
55+
attr = MOI.RawOptimizerAttribute("FooBarBaz")
56+
@test !MOI.supports(model, attr)
57+
@test_throws MOI.UnsupportedAttribute(attr) MOI.get(model, attr)
58+
@test_throws MOI.UnsupportedAttribute(attr) MOI.set(model, attr, false)
59+
return
60+
end
61+
62+
function test_RawOptimizerAttribute_PIECES_MAP_nothing()
63+
model = SDPLR.Optimizer()
64+
attr = MOI.RawOptimizerAttribute("lambdaupdate")
65+
@test MOI.supports(model, attr)
66+
@test MOI.get(model, attr) === nothing
67+
@test MOI.set(model, attr, 2.0) === nothing
68+
@test MOI.get(model, attr) === 2.0
69+
@test MOI.set(model, attr, nothing) === nothing
70+
@test MOI.get(model, attr) === nothing
71+
return
72+
end
73+
74+
function test_Ainfo_entptr_in_mixed_order()
75+
model = SDPLR.Optimizer()
76+
set = MOI.PositiveSemidefiniteConeTriangle(2)
77+
x, c = MOI.add_constrained_variables(model, set)
78+
MOI.add_constraint.(model, 1.0 .* x, MOI.EqualTo.([1.0, -1.0, 2.0]))
79+
y, _ = MOI.add_constrained_variables(model, set)
80+
MOI.add_constraint.(model, 1.0 .* y, MOI.EqualTo.([1.0, 2.0, 6.0]))
81+
MOI.set(model, MOI.ObjectiveSense(), MOI.MIN_SENSE)
82+
f = sum(1.0 * x) + sum(1.0 * y)
83+
MOI.set(model, MOI.ObjectiveFunction{typeof(f)}(), f)
84+
MOI.optimize!(model)
85+
@test MOI.get(model, MOI.TerminationStatus()) == MOI.LOCALLY_SOLVED
86+
atol = 1e-4
87+
@test (MOI.get.(model, MOI.VariablePrimal(), x), [1.0, -1.0, 2.0]; atol)
88+
@test (MOI.get.(model, MOI.VariablePrimal(), y), [1.0, 2.0, 6.0]; atol)
89+
return
90+
end
91+
5392
function runtests()
5493
for name in names(@__MODULE__; all = true)
5594
if startswith("$(name)", "test_")

0 commit comments

Comments
 (0)