Skip to content

Commit 617379e

Browse files
committed
Update
1 parent abf6392 commit 617379e

2 files changed

Lines changed: 58 additions & 1 deletion

File tree

src/FileFormats/MPS/read.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,9 @@ end
285285
Base.length(x::LineToItems) = x.nfields
286286

287287
function Base.getindex(x::LineToItems, i::Int)
288-
@assert 1 <= i <= x.nfields
288+
if !(1 <= i <= min(5, x.nfields))
289+
throw(BoundsError(x, i))
290+
end
289291
return SubString(x.line, x.fields[i])
290292
end
291293

test/FileFormats/MPS/test_MPS.jl

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1729,6 +1729,61 @@ function test_unsupported_objectives()
17291729
return
17301730
end
17311731

1732+
function test_LineToItems()
1733+
for line in [
1734+
"a",
1735+
" a ",
1736+
"a b",
1737+
" a b ",
1738+
"a b c",
1739+
" a b c ",
1740+
"a b c d",
1741+
" a b c d ",
1742+
"a b c d e",
1743+
" a b c d e ",
1744+
]
1745+
@test collect(MPS.LineToItems(line)) ==
1746+
split(line, ' '; keepempty = false)
1747+
end
1748+
items = MPS.LineToItems("a b c d e f g")
1749+
@test length(items) == 7
1750+
@test_throws BoundsError items[0]
1751+
@test items[1] == "a"
1752+
@test_throws BoundsError items[6]
1753+
items = MPS.LineToItems("a b")
1754+
@test length(items) == 2
1755+
@test_throws BoundsError items[3]
1756+
return
1757+
end
1758+
1759+
function test_parse_header()
1760+
for (line, header) in [
1761+
"OBJSENSE" => MPS.HEADER_OBJSENSE,
1762+
"OBJSENSE MAX" => MPS.HEADER_OBJSENSE,
1763+
"ROWS" => MPS.HEADER_ROWS,
1764+
"COLUMNS" => MPS.HEADER_COLUMNS,
1765+
"RHS" => MPS.HEADER_RHS,
1766+
"RANGES" => MPS.HEADER_RANGES,
1767+
"BOUNDS" => MPS.HEADER_BOUNDS,
1768+
"SOS" => MPS.HEADER_SOS,
1769+
"ENDATA" => MPS.HEADER_ENDATA,
1770+
"QUADOBJ" => MPS.HEADER_QUADOBJ,
1771+
"QMATRIX" => MPS.HEADER_QMATRIX,
1772+
"QCMATRIX c" => MPS.HEADER_QCMATRIX,
1773+
"QSECTION c" => MPS.HEADER_QSECTION,
1774+
"INDICATORS" => MPS.HEADER_INDICATORS,
1775+
"" => MPS.HEADER_UNKNOWN,
1776+
"Foo" => MPS.HEADER_UNKNOWN,
1777+
"rhs x" => MPS.HEADER_UNKNOWN,
1778+
]
1779+
items = MPS.LineToItems(line)
1780+
@test header == MPS.parse_header(items)
1781+
items = MPS.LineToItems(lowercase(line))
1782+
@test header == MPS.parse_header(items)
1783+
end
1784+
return
1785+
end
1786+
17321787
end # TestMPS
17331788

17341789
TestMPS.runtests()

0 commit comments

Comments
 (0)