Skip to content

Commit 9586122

Browse files
committed
Update
1 parent 78ca70d commit 9586122

File tree

6 files changed

+74
-2
lines changed

6 files changed

+74
-2
lines changed

test/Utilities/functions.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2238,6 +2238,24 @@ function test_filter_variables_variable_index()
22382238
return
22392239
end
22402240

2241+
function test_mult_bool()
2242+
f = 1.0 * MOI.VariableIndex(1) + 2.0
2243+
@test *(f, false) zero(MOI.ScalarAffineFunction{Float64})
2244+
return
2245+
end
2246+
2247+
function test_is_complex()
2248+
@test !MOI.Utilities.is_complex(MOI.ScalarAffineFunction{Float64})
2249+
@test !MOI.Utilities.is_complex(MOI.ScalarQuadraticFunction{Float64})
2250+
@test !MOI.Utilities.is_complex(MOI.VectorAffineFunction{Float64})
2251+
@test !MOI.Utilities.is_complex(MOI.VectorQuadraticFunction{Float64})
2252+
@test MOI.Utilities.is_complex(MOI.ScalarAffineFunction{ComplexF64})
2253+
@test MOI.Utilities.is_complex(MOI.ScalarQuadraticFunction{ComplexF64})
2254+
@test MOI.Utilities.is_complex(MOI.VectorAffineFunction{ComplexF64})
2255+
@test MOI.Utilities.is_complex(MOI.VectorQuadraticFunction{ComplexF64})
2256+
return
2257+
end
2258+
22412259
end # module
22422260

22432261
TestUtilitiesFunctions.runtests()

test/Utilities/matrix_of_constraints.jl

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,31 @@ function test_modify_set_constants()
689689
return
690690
end
691691

692+
function test_unsupported_constraint()
693+
model = _new_ScalarSets()
694+
x = MOI.VariableIndex(1)
695+
@test_throws(
696+
MOI.UnsupportedConstraint{MOI.VariableIndex,MOI.ZeroOne}(),
697+
MOI.add_constraint(model.constraints, x, MOI.ZeroOne()),
698+
)
699+
src = MOI.Utilities.Model{Float64}()
700+
index_map = MOI.Utilities.IndexMap()
701+
@test_throws(
702+
MOI.UnsupportedConstraint{MOI.VariableIndex,MOI.ZeroOne}(),
703+
MOI.Utilities._allocate_constraints(
704+
model.constraints,
705+
src,
706+
index_map,
707+
MOI.VariableIndex,
708+
MOI.ZeroOne,
709+
),
710+
)
711+
MOI.Utilities.final_touch(model, index_map)
712+
@test_throws AssertionError MOI.Utilities.final_touch(model, index_map)
713+
MOI.Utilities.final_touch(model, nothing)
714+
return
715+
end
716+
692717
end
693718

694719
TestMatrixOfConstraints.runtests()

test/Utilities/model.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,14 @@ function test_indicator_constraints()
562562
return
563563
end
564564

565+
function test_set_unsupported_objective()
566+
model = MOI.Utilities.Model{Float64}()
567+
f = FunctionNotSupportedBySolvers(MOI.VariableIndex(1))
568+
attr = MOI.ObjectiveFunction{typeof(f)}()
569+
@test_throws(MOI.UnsupportedAttribute(attr), MOI.set(model, attr, f))
570+
return
571+
end
572+
565573
end # module
566574

567575
TestModel.runtests()

test/Utilities/parser.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,15 @@ function test_parse_scope()
435435
return
436436
end
437437

438+
function test_parse_unrecognized_expression()
439+
model = MOI.Utilities.Model{Float64}()
440+
@test_throws(
441+
ErrorException("Unrecognized expression []"),
442+
MOI.Utilities.loadfromstring!(model, "[]"),
443+
)
444+
return
445+
end
446+
438447
end # module
439448

440449
TestParser.runtests()

test/Utilities/test_operate!.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,14 @@ function test_operate_3b_scalarnonlinearfunction_specialcase()
340340
return
341341
end
342342

343+
function test_operate_3c()
344+
x = MOI.VariableIndex(1)
345+
f = 1.0 * x + 2.0
346+
g = MOI.Utilities.operate(*, Float64, f, x)
347+
@test g 1.0 * x * x + 2.0 * x
348+
return
349+
end
350+
343351
function test_operate_4a()
344352
T = Float64
345353
for (f, g) in (
@@ -387,6 +395,7 @@ function test_operate_5a()
387395
args = (_test_function(f), _test_function(g))
388396
@test MOI.Utilities.operate!(vcat, T, args...) _test_function(h)
389397
end
398+
@test MOI.Utilities.operate(vcat, T) == T[]
390399
return
391400
end
392401

test/attributes.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,9 @@ end
345345

346346
function test_broadcastable_submittable()
347347
submit = MOI.LazyConstraint(1)
348-
@test Base.broadcastable(submit) == Ref(submit)
348+
b = Base.broadcastable(submit)
349+
@test b isa Base.RefValue
350+
@test b[] == submit
349351
return
350352
end
351353

@@ -371,7 +373,8 @@ function test_submit_argument_error()
371373
end
372374

373375
function test_showerror_OptimizeInProgress()
374-
@test sprint(showerror, MOI.OptimizeInProgress(MOI.VariablePrimal())) ==
376+
err = MOI.OptimizeInProgress(MOI.VariablePrimal())
377+
@test sprint(showerror, err) ==
375378
"$err: Cannot get result as the `MOI.optimize!` has not finished."
376379
return
377380
end

0 commit comments

Comments
 (0)