Skip to content

Commit f86c541

Browse files
committed
Update
1 parent fd41d53 commit f86c541

File tree

5 files changed

+91
-16
lines changed

5 files changed

+91
-16
lines changed

src/indextypes.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ end
9393

9494
function Base.showerror(io::IO, err::InvalidIndex)
9595
return print(
96+
io,
9697
"The index $(err.index) is invalid. Note that an index becomes invalid after it has been deleted.",
9798
)
9899
end

src/instantiate.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ struct OptimizerWithAttributes
2424
end
2525

2626
_to_param(param::Pair{<:AbstractOptimizerAttribute}) = param
27+
2728
function _to_param(param::Pair{String})
2829
return RawOptimizerAttribute(param.first) => param.second
2930
end

test/attributes.jl

Lines changed: 55 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ import MathOptInterface as MOI
1111

1212
include("dummy.jl")
1313

14+
function runtests()
15+
for name in names(@__MODULE__; all = true)
16+
if startswith("$name", "test_")
17+
@testset "$(name)" begin
18+
getfield(@__MODULE__, name)()
19+
end
20+
end
21+
end
22+
end
23+
1424
function test_attributes_is_set_by_optimize()
1525
@test MOI.is_set_by_optimize(MOI.TerminationStatus())
1626
@test !MOI.is_set_by_optimize(MOI.ConstraintSet())
@@ -333,16 +343,53 @@ function test_empty_vector_attribute()
333343
return
334344
end
335345

336-
function runtests()
337-
for name in names(@__MODULE__; all = true)
338-
if startswith("$name", "test_")
339-
@testset "$(name)" begin
340-
getfield(@__MODULE__, name)()
341-
end
342-
end
343-
end
346+
function test_broadcastable_submittable()
347+
submit = MOI.LazyConstraint(1)
348+
@test Base.broadcastable(submit) == Ref(submit)
349+
return
344350
end
345351

352+
function test_submit_not_allowed()
353+
submit = MOI.LazyConstraint(1)
354+
@test MOI.SubmitNotAllowed(submit) == MOI.SubmitNotAllowed(submit, "")
355+
err = MOI.SubmitNotAllowed(submit, "msg")
356+
contents = sprint(showerror, err)
357+
@test occursin("Submitting $submit cannot be performed: msg", contents)
358+
return
346359
end
347360

361+
struct ModelWithSupportedSubmittable <: MOI.ModelLike end
362+
363+
MOI.supports(::ModelWithSupportedSubmittable, ::MOI.LazyConstraint) = true
364+
365+
function test_submit_argument_error()
366+
model = ModelWithSupportedSubmittable()
367+
submit = MOI.LazyConstraint(1)
368+
@test MOI.supports(model, submit)
369+
@test_throws ArgumentError MOI.submit(model, submit, false)
370+
return
371+
end
372+
373+
function test_showerror_OptimizeInProgress()
374+
@test sprint(showerror, MOI.OptimizeInProgress(MOI.VariablePrimal())) ==
375+
"$err: Cannot get result as the `MOI.optimize!` has not finished."
376+
return
377+
end
378+
379+
function test_showerror_FunctionTypeMismatch()
380+
F, G = MOI.VariableIndex, MOI.VectorOfVariables
381+
contents = sprint(showerror, MOI.FunctionTypeMismatch{F,G}())
382+
@test occursin("Cannot modify functions of different types", contents)
383+
return
384+
end
385+
386+
function test_showerror_SetTypeMismatch()
387+
F, G = MOI.ZeroOne, MOI.Integer
388+
contents = sprint(showerror, MOI.SetTypeMismatch{F,G}())
389+
@test occursin("Cannot modify sets of different types", contents)
390+
return
391+
end
392+
393+
end # module
394+
348395
TestAttributes.runtests()

test/errors.jl

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ import MathOptInterface as MOI
1111

1212
include("dummy.jl")
1313

14+
function runtests()
15+
for name in names(@__MODULE__; all = true)
16+
if startswith("$name", "test_")
17+
@testset "$(name)" begin
18+
getfield(@__MODULE__, name)()
19+
end
20+
end
21+
end
22+
end
23+
1424
function test_errors_fallback_AddVariableNotAllowed()
1525
model = DummyModel()
1626
@test_throws MOI.AddVariableNotAllowed MOI.add_variable(model)
@@ -370,16 +380,22 @@ function test_ScalarFunctionConstantNotZero_equality()
370380
return
371381
end
372382

373-
function runtests()
374-
for name in names(@__MODULE__; all = true)
375-
if startswith("$name", "test_")
376-
@testset "$(name)" begin
377-
getfield(@__MODULE__, name)()
378-
end
379-
end
380-
end
383+
function test_showerror_InvalidIndex()
384+
x = MOI.VariableIndex(1)
385+
@test sprint(showerror, InvalidIndex(x)) ==
386+
"The index $x is invalid. Note that an index becomes invalid after it has been deleted."
387+
return
381388
end
382389

390+
struct ModelWithNoIsValid <: MOI.ModelLike end
391+
392+
function test_isvalid_fallback()
393+
model = ModelWithNoIsValid()
394+
x = MOI.VariableIndex(1)
395+
@test !MOI.is_valid(model, x)
396+
return
383397
end
384398

399+
end # module
400+
385401
TestErrors.runtests()

test/instantiate.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,16 @@ function test_instantiate_with_cache_type()
166166
return
167167
end
168168

169+
function test_to_param_OptimizerWithAttributes()
170+
@test_throws(
171+
ErrorException(
172+
"Expected an optimizer attribute or a string, got `1` which is a `$(Int)`.",
173+
),
174+
MOI.OptimizerWithAttributes(MOI.Utilities.Model{Float64}, 1 => 2),
175+
)
176+
return
177+
end
178+
169179
end
170180

171181
TestInstantiate.runtests()

0 commit comments

Comments
 (0)