Skip to content

Commit f985663

Browse files
committed
Improve code coverage
1 parent d68b3fb commit f985663

File tree

7 files changed

+131
-3
lines changed

7 files changed

+131
-3
lines changed

src/FileFormats/MPS/MPS.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,7 +1153,7 @@ function Base.read!(io::IO, model::Model)
11531153
end
11541154
data = TempMPSModel()
11551155
header = HEADER_NAME
1156-
while !eof(io)
1156+
while !eof(io) && header != HEADER_ENDATA
11571157
raw_line = readline(io)
11581158
if startswith(raw_line, '*')
11591159
continue # Lines starting with `*` are comments
@@ -1219,7 +1219,6 @@ function Base.read!(io::IO, model::Model)
12191219
parse_indicators_line(data, items)
12201220
else
12211221
@assert header == HEADER_ENDATA
1222-
break
12231222
end
12241223
end
12251224
copy_to(model, data)
@@ -1556,7 +1555,7 @@ function parse_single_rhs(
15561555
data.row_upper[row] = value
15571556
else
15581557
@assert data.sense[row] == SENSE_N
1559-
error("Cannot have RHS for objective: $(join(items, " "))")
1558+
error("Cannot have RHS for free row: $(join(items, " "))")
15601559
end
15611560
return
15621561
end

test/Benchmarks/Benchmarks.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@ function test_baseline()
4343
suite = MOI.Benchmarks.suite() do
4444
return MOI.Utilities.MockOptimizer(MOI.Utilities.Model{Float64}())
4545
end
46+
@test_throws(
47+
ErrorException("You create a baseline with `create_baseline` first."),
48+
MOI.Benchmarks.compare_against_baseline(
49+
suite,
50+
"baseline";
51+
directory = @__DIR__,
52+
samples = 1,
53+
verbose = true,
54+
),
55+
)
4656
MOI.Benchmarks.create_baseline(
4757
suite,
4858
"baseline";

test/FileFormats/FileFormats.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,19 @@ function test_generic_names()
189189
return
190190
end
191191

192+
function test_unique_names()
193+
model = MOI.Utilities.Model{Float64}()
194+
x = MOI.add_variables(model, 3)
195+
MOI.set.(model, MOI.VariableName(), x, "x")
196+
c = MOI.add_constraint.(model, 1.0 .* x, MOI.EqualTo(1.0))
197+
MOI.set.(model, MOI.ConstraintName(), c, "c")
198+
MOI.set(model, MOI.ConstraintName(), c[2], "c_1")
199+
MOI.FileFormats.create_unique_names(model)
200+
@test MOI.get.(model, MOI.VariableName(), x) == ["x", "x_1", "x_2"]
201+
@test MOI.get.(model, MOI.ConstraintName(), c) == ["c", "c_1", "c_2"]
202+
return
203+
end
204+
192205
end
193206

194207
TestFileFormats.runtests()

test/FileFormats/LP/LP.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,6 +1099,20 @@ function test_comprehensive_write()
10991099
return
11001100
end
11011101

1102+
function test_unable_to_parse_bound()
1103+
io = IOBuffer("""
1104+
minimize
1105+
obj: 1 x
1106+
subject to
1107+
bounds
1108+
x
1109+
end
1110+
""")
1111+
model = LP.Model()
1112+
@test_throws(ErrorException("Unable to parse bound: x"), read!(io, model))
1113+
return
1114+
end
1115+
11021116
end # module
11031117

11041118
TestLP.runtests()

test/FileFormats/MPS/MPS.jl

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1484,6 +1484,55 @@ function test_model_not_empty()
14841484
return
14851485
end
14861486

1487+
function test_rhs_free_row()
1488+
io = IOBuffer("""
1489+
NAME
1490+
ROWS
1491+
N OBJ
1492+
N c
1493+
COLUMNS
1494+
x OBJ 1
1495+
x c 1
1496+
RHS
1497+
rhs c 1
1498+
RANGES
1499+
BOUNDS
1500+
FR bounds x
1501+
ENDATA
1502+
""")
1503+
model = MPS.Model()
1504+
@test_throws(
1505+
ErrorException("Cannot have RHS for free row: rhs c 1"),
1506+
read!(io, model),
1507+
)
1508+
return
1509+
end
1510+
1511+
function test_malformed_indicator()
1512+
io = IOBuffer("""
1513+
NAME
1514+
ROWS
1515+
N OBJ
1516+
COLUMNS
1517+
x OBJ 1
1518+
y OBJ 1
1519+
RHS
1520+
RANGES
1521+
BOUNDS
1522+
FR bounds x
1523+
BV bounds y
1524+
INDICATORS
1525+
IF c1 y
1526+
ENDATA
1527+
""")
1528+
model = MPS.Model()
1529+
@test_throws(
1530+
ErrorException("Malformed INDICATORS line: IF c1 y"),
1531+
read!(io, model),
1532+
)
1533+
return
1534+
end
1535+
14871536
end # TestMPS
14881537

14891538
TestMPS.runtests()

test/Test/Test.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,15 @@ end
125125
@test_logs MOI.Test.runtests(model, config; exclude = exclude)
126126
end
127127

128+
@testset "test_FeasibilitySenseEvaluator" begin
129+
evaluator = MOI.Test.FeasibilitySenseEvaluator(true)
130+
@test MOI.features_available(evaluator) == [:Grad, :Jac, :Hess, :ExprGraph]
131+
@test MOI.hessian_lagrangian_structure(evaluator) == [(1, 1)]
132+
evaluator = MOI.Test.FeasibilitySenseEvaluator(false)
133+
@test MOI.features_available(evaluator) == [:Grad, :Jac, :ExprGraph]
134+
@test_throws AssertionError MOI.hessian_lagrangian_structure(evaluator)
135+
end
136+
128137
@testset "test_HS071_evaluator" begin
129138
evaluator = MOI.Test.HS071(true, true)
130139
features = [:Grad, :Jac, :JacVec, :ExprGraph, :Hess, :HessVec]

test/sets.jl

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,40 @@ function test_interval_promote()
377377
return
378378
end
379379

380+
mutable struct TestSetNoCopy <: MOI.AbstractVectorSet
381+
data::BigInt
380382
end
381383

384+
function test_set_not_isbitstype_copy()
385+
@test !isbitstype(TestSetNoCopy)
386+
@test_throws(
387+
ErrorException(
388+
"Base.copy(::TestSetNoCopy) is not implemented for this set.",
389+
),
390+
copy(TestSetNoCopy(BigInt(2))),
391+
)
392+
return
393+
end
394+
395+
function test_deprecated_PositiveSemidefiniteConeTriangle()
396+
set = MOI.Scaled(MOI.PositiveSemidefiniteConeTriangle(2))
397+
@test set.side_dimension == 2
398+
@test !hasfield(typeof(set), :side_dimension)
399+
return
400+
end
401+
402+
function test_update_dimension()
403+
@test !MOI.supports_dimension_update(MOI.ExponentialCone())
404+
for S in (MOI.Reals, MOI.Zeros, MOI.Nonnegatives, MOI.Nonpositives)
405+
@test MOI.supports_dimension_update(S)
406+
set = S(1)
407+
new_set = MOI.update_dimension(set, 2)
408+
@test MOI.dimension(set) == 1
409+
@test MOI.dimension(new_set) == 2
410+
end
411+
return
412+
end
413+
414+
end # module
415+
382416
TestSets.runtests()

0 commit comments

Comments
 (0)