Skip to content

Commit fe19bbf

Browse files
authored
[Test] various fixes to MOI.Test (#1428)
* [Test] various fixes to MOI.Test * Fix formatting
1 parent 263f6b6 commit fe19bbf

File tree

9 files changed

+32
-115
lines changed

9 files changed

+32
-115
lines changed

src/Test/test_constraint.jl

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,6 @@ function test_constraint_ScalarAffineFunction_duplicate(
282282
model::MOI.ModelLike,
283283
config::Config,
284284
)
285-
MOI.empty!(model)
286285
x = MOI.add_variable(model)
287286
objective_function =
288287
MOI.ScalarAffineFunction([MOI.ScalarAffineTerm(1.0, x)], 0.0)
@@ -337,7 +336,6 @@ function test_constraint_VectorAffineFunction_duplicate(
337336
model::MOI.ModelLike,
338337
config::Config,
339338
)
340-
MOI.empty!(model)
341339
x = MOI.add_variable(model)
342340
objective_function =
343341
MOI.ScalarAffineFunction([MOI.ScalarAffineTerm(1.0, x)], 0.0)
@@ -398,7 +396,6 @@ function test_constraint_qcp_duplicate_diagonal(
398396
MOI.ScalarQuadraticFunction{Float64},
399397
MOI.LessThan{Float64},
400398
)
401-
MOI.empty!(model)
402399
x = MOI.add_variables(model, 2)
403400
MOI.set(model, MOI.ObjectiveSense(), MOI.MAX_SENSE)
404401
MOI.set(
@@ -471,7 +468,6 @@ function test_constraint_qcp_duplicate_off_diagonal(
471468
MOI.ScalarQuadraticFunction{Float64},
472469
MOI.LessThan{Float64},
473470
)
474-
MOI.empty!(model)
475471
x = MOI.add_variables(model, 2)
476472
MOI.set(model, MOI.ObjectiveSense(), MOI.MAX_SENSE)
477473
MOI.set(
@@ -536,7 +532,6 @@ Test a problem with a bounded ZeroOne variable.
536532
"""
537533
function test_constraint_ZeroOne_bounds(model::MOI.ModelLike, config::Config)
538534
@requires MOI.supports_constraint(model, MOI.SingleVariable, MOI.ZeroOne)
539-
MOI.empty!(model)
540535
MOIU.loadfromstring!(
541536
model,
542537
"""
@@ -577,7 +572,6 @@ Test a problem with a ZeroOne and binding fractional upper bound.
577572
"""
578573
function test_constraint_ZeroOne_bounds_2(model::MOI.ModelLike, config::Config)
579574
@requires MOI.supports_constraint(model, MOI.SingleVariable, MOI.ZeroOne)
580-
MOI.empty!(model)
581575
MOIU.loadfromstring!(
582576
model,
583577
"""
@@ -619,7 +613,6 @@ Test a problem with a ZeroOne and infeasible fractional bounds.
619613
function test_constraint_ZeroOne_bounds_3(model::MOI.ModelLike, config::Config)
620614
@requires MOI.supports_constraint(model, MOI.SingleVariable, MOI.ZeroOne)
621615
@requires _supports(config, MOI.optimize!)
622-
MOI.empty!(model)
623616
MOIU.loadfromstring!(
624617
model,
625618
"""
@@ -668,7 +661,6 @@ function test_constraint_PrimalStart_DualStart_SecondOrderCone(
668661
MOI.SecondOrderCone,
669662
)
670663
@requires _supports(config, MOI.optimize!)
671-
MOI.empty!(model)
672664
x = MOI.add_variable(model)
673665
fx = MOI.SingleVariable(x)
674666
o = one(T)

src/Test/test_linear.jl

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ function test_linear_integration(
3838
MOI.SingleVariable,
3939
MOI.GreaterThan{T},
4040
)
41-
MOI.empty!(model)
42-
@test MOI.is_empty(model)
4341
v = MOI.add_variables(model, 2)
4442
@test MOI.get(model, MOI.NumberOfVariables()) == 2
4543
cf = MOI.ScalarAffineFunction{T}(
@@ -573,8 +571,6 @@ function test_linear_integration_2(
573571
MOI.SingleVariable,
574572
MOI.GreaterThan{T},
575573
)
576-
MOI.empty!(model)
577-
@test MOI.is_empty(model)
578574
x = MOI.add_variable(model)
579575
y = MOI.add_variable(model)
580576
@test MOI.get(model, MOI.NumberOfVariables()) == 2
@@ -715,8 +711,6 @@ function test_linear_inactive_bounds(
715711
MOI.SingleVariable,
716712
MOI.LessThan{T},
717713
)
718-
MOI.empty!(model)
719-
@test MOI.is_empty(model)
720714
x = MOI.add_variable(model)
721715
@test MOI.get(model, MOI.NumberOfVariables()) == 1
722716
vc = MOI.add_constraint(
@@ -869,8 +863,6 @@ function test_linear_LessThan_and_GreaterThan(
869863
MOI.SingleVariable,
870864
MOI.LessThan{T},
871865
)
872-
MOI.empty!(model)
873-
@test MOI.is_empty(model)
874866
x = MOI.add_variable(model)
875867
y = MOI.add_variable(model)
876868
# Min x - y
@@ -994,8 +986,6 @@ function test_linear_integration_modification(
994986
MOI.ScalarAffineFunction{T},
995987
MOI.LessThan{T},
996988
)
997-
MOI.empty!(model)
998-
@test MOI.is_empty(model)
999989
x = MOI.add_variable(model)
1000990
y = MOI.add_variable(model)
1001991
@test MOI.get(model, MOI.NumberOfVariables()) == 2
@@ -1159,8 +1149,6 @@ function test_linear_modify_GreaterThan_and_LessThan_constraints(
11591149
MOI.ScalarAffineFunction{T},
11601150
MOI.LessThan{T},
11611151
)
1162-
MOI.empty!(model)
1163-
@test MOI.is_empty(model)
11641152
x = MOI.add_variable(model)
11651153
y = MOI.add_variable(model)
11661154
# Min x - y
@@ -1302,8 +1290,6 @@ function test_linear_VectorAffineFunction(
13021290
MOI.VectorAffineFunction{T},
13031291
MOI.Nonpositives,
13041292
)
1305-
MOI.empty!(model)
1306-
@test MOI.is_empty(model)
13071293
x = MOI.add_variable(model)
13081294
y = MOI.add_variable(model)
13091295
# Min x - y
@@ -1459,8 +1445,6 @@ function test_linear_INFEASIBLE(
14591445
MOI.SingleVariable,
14601446
MOI.GreaterThan{T},
14611447
)
1462-
MOI.empty!(model)
1463-
@test MOI.is_empty(model)
14641448
x = MOI.add_variable(model)
14651449
y = MOI.add_variable(model)
14661450
c = MOI.add_constraint(
@@ -1567,8 +1551,6 @@ function test_linear_DUAL_INFEASIBLE(
15671551
MOI.SingleVariable,
15681552
MOI.GreaterThan{T},
15691553
)
1570-
MOI.empty!(model)
1571-
@test MOI.is_empty(model)
15721554
x = MOI.add_variable(model)
15731555
y = MOI.add_variable(model)
15741556
MOI.add_constraint(
@@ -1662,8 +1644,6 @@ function test_linear_DUAL_INFEASIBLE_2(
16621644
MOI.SingleVariable,
16631645
MOI.GreaterThan{T},
16641646
)
1665-
MOI.empty!(model)
1666-
@test MOI.is_empty(model)
16671647
x = MOI.add_variable(model)
16681648
y = MOI.add_variable(model)
16691649
MOI.add_constraint(
@@ -1772,8 +1752,6 @@ function test_linear_add_constraints(
17721752
MOI.SingleVariable,
17731753
MOI.GreaterThan{T},
17741754
)
1775-
MOI.empty!(model)
1776-
@test MOI.is_empty(model)
17771755
x = MOI.add_variable(model)
17781756
y = MOI.add_variable(model)
17791757
vc12 = MOI.add_constraints(
@@ -1895,8 +1873,6 @@ function test_linear_integration_Interval(
18951873
MOI.SingleVariable,
18961874
MOI.GreaterThan{T},
18971875
)
1898-
MOI.empty!(model)
1899-
@test MOI.is_empty(model)
19001876
x = MOI.add_variable(model)
19011877
y = MOI.add_variable(model)
19021878
vc = MOI.add_constraints(
@@ -2141,8 +2117,6 @@ function test_linear_Interval_inactive(
21412117
MOI.SingleVariable,
21422118
MOI.GreaterThan{T},
21432119
)
2144-
MOI.empty!(model)
2145-
@test MOI.is_empty(model)
21462120
x = MOI.add_variable(model)
21472121
y = MOI.add_variable(model)
21482122
vc = MOI.add_constraints(
@@ -2284,8 +2258,6 @@ function test_linear_transform(
22842258
MOI.ScalarAffineFunction{T},
22852259
MOI.LessThan{T},
22862260
)
2287-
MOI.empty!(model)
2288-
@test MOI.is_empty(model)
22892261
v = MOI.add_variables(model, 2)
22902262
c1 = MOI.add_constraint(
22912263
model,
@@ -2387,8 +2359,6 @@ function test_linear_INFEASIBLE_2(
23872359
MOI.SingleVariable,
23882360
MOI.GreaterThan{T},
23892361
)
2390-
MOI.empty!(model)
2391-
@test MOI.is_empty(model)
23922362
x = MOI.add_variable(model)
23932363
y = MOI.add_variable(model)
23942364
c1 = MOI.add_constraint(
@@ -2501,8 +2471,6 @@ function test_linear_FEASIBILITY_SENSE(
25012471
MOI.ScalarAffineFunction{T},
25022472
MOI.GreaterThan{T},
25032473
)
2504-
MOI.empty!(model)
2505-
@test MOI.is_empty(model)
25062474
x = MOI.add_variable(model)
25072475
y = MOI.add_variable(model)
25082476
c1 = MOI.add_constraint(
@@ -2607,8 +2575,6 @@ function test_linear_integration_delete_variables(
26072575
MOI.SingleVariable,
26082576
MOI.LessThan{T},
26092577
)
2610-
MOI.empty!(model)
2611-
@test MOI.is_empty(model)
26122578
x, y, z = MOI.add_variables(model, 3)
26132579
c = MOI.add_constraint(
26142580
model,
@@ -2792,8 +2758,6 @@ function test_linear_VectorAffineFunction_empty_row(
27922758
MOI.VectorAffineFunction{T},
27932759
MOI.Zeros,
27942760
)
2795-
MOI.empty!(model)
2796-
@test MOI.is_empty(model)
27972761
x = MOI.add_variables(model, 1)
27982762
# Create a VectorAffineFunction with two rows, but only one term, belonging
27992763
# to the second row. The first row, which is empty, is essentially a
@@ -2875,8 +2839,6 @@ function test_linear_VariablePrimalStart_partial(
28752839
) where {T}
28762840
atol = config.atol
28772841
rtol = config.rtol
2878-
MOI.empty!(model)
2879-
@test MOI.is_empty(model)
28802842
x = MOI.add_variable(model)
28812843
y = MOI.add_variable(model)
28822844
MOI.set(model, MOI.VariablePrimalStart(), x, one(T))

src/Test/test_model.jl

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ end
138138
Test that the default ObjectiveSense is FEASIBILITY_SENSE.
139139
"""
140140
function test_model_default_ObjectiveSense(model::MOI.ModelLike, ::Config)
141-
@test MOI.is_empty(model)
142141
MOI.get(model, MOI.ObjectiveSense()) == MOI.FEASIBILITY_SENSE
143142
return
144143
end
@@ -149,7 +148,6 @@ end
149148
Test that the default TerminationStatus is OPTIMIZE_NOT_CALLED.
150149
"""
151150
function test_model_default_TerminationStatus(model::MOI.ModelLike, ::Config)
152-
@test MOI.is_empty(model)
153151
MOI.get(model, MOI.TerminationStatus()) == MOI.OPTIMIZE_NOT_CALLED
154152
return
155153
end
@@ -160,7 +158,6 @@ end
160158
Test that the default PrimalStatus is NO_SOLUTION.
161159
"""
162160
function test_model_default_PrimalStatus(model::MOI.ModelLike, ::Config)
163-
@test MOI.is_empty(model)
164161
MOI.get(model, MOI.PrimalStatus()) == MOI.NO_SOLUTION
165162
return
166163
end
@@ -171,7 +168,6 @@ end
171168
Test that the default DualStatus is NO_SOLUTION.
172169
"""
173170
function test_model_default_DualStatus(model::MOI.ModelLike, ::Config)
174-
@test MOI.is_empty(model)
175171
MOI.get(model, MOI.DualStatus()) == MOI.NO_SOLUTION
176172
return
177173
end
@@ -285,7 +281,6 @@ function test_model_Name_VariableName_ConstraintName(
285281
MOI.LessThan{Float64},
286282
}(),
287283
) == 0
288-
@test MOI.supports(model, MOI.VariableName(), MOI.VariableIndex)
289284
v = MOI.add_variables(model, 2)
290285
@test MOI.get(model, MOI.VariableName(), v[1]) == ""
291286
x, cx = MOI.add_constrained_variable(model, MOI.GreaterThan(0.0))
@@ -321,7 +316,7 @@ function test_model_Name_VariableName_ConstraintName(
321316
@test MOI.get(model, MOI.VariableName(), v) == vynames[1:2]
322317
@test MOI.get(model, MOI.VariableName(), y) == vynames[3:6]
323318
@test MOI.get(model, MOI.VariableName(), [v; y]) == vynames
324-
@test MOI.supports_constraint(
319+
@requires MOI.supports_constraint(
325320
model,
326321
MOI.ScalarAffineFunction{Float64},
327322
MOI.LessThan{Float64},
@@ -331,7 +326,7 @@ function test_model_Name_VariableName_ConstraintName(
331326
MOI.ScalarAffineFunction(MOI.ScalarAffineTerm.([1.0, 1.0], v), 0.0),
332327
MOI.LessThan(1.0),
333328
)
334-
@test MOI.supports_constraint(
329+
@requires MOI.supports_constraint(
335330
model,
336331
MOI.ScalarAffineFunction{Float64},
337332
MOI.EqualTo{Float64},
@@ -344,11 +339,11 @@ function test_model_Name_VariableName_ConstraintName(
344339
@test MOI.get(model, MOI.ConstraintName(), c) == ""
345340
@test MOI.get(model, MOI.ConstraintName(), c2) == ""
346341
@test MOI.get(model, MOI.ConstraintName(), cy) == ""
347-
@test MOI.supports(model, MOI.ConstraintName(), typeof(c))
342+
@requires MOI.supports(model, MOI.ConstraintName(), typeof(c))
348343
MOI.set(model, MOI.ConstraintName(), c, "")
349-
@test MOI.supports(model, MOI.ConstraintName(), typeof(c2))
344+
@requires MOI.supports(model, MOI.ConstraintName(), typeof(c2))
350345
MOI.set(model, MOI.ConstraintName(), c2, "") # Shouldn't error with duplicate empty name
351-
@test MOI.supports(model, MOI.ConstraintName(), typeof(cy))
346+
@requires MOI.supports(model, MOI.ConstraintName(), typeof(cy))
352347
MOI.set(model, MOI.ConstraintName(), cy, "")
353348
MOI.set(model, MOI.ConstraintName(), c, "Con0")
354349
@test MOI.get(model, MOI.ConstraintName(), c) == "Con0"
@@ -519,7 +514,7 @@ function test_model_is_valid(model::MOI.ModelLike, config::Config)
519514
@test !MOI.is_valid(model, x)
520515
end
521516
cf = MOI.ScalarAffineFunction(MOI.ScalarAffineTerm.([1.0, 1.0], v), 0.0)
522-
@test MOI.supports_constraint(model, typeof(cf), MOI.LessThan{Float64})
517+
@requires MOI.supports_constraint(model, typeof(cf), MOI.LessThan{Float64})
523518
c = MOI.add_constraint(model, cf, MOI.LessThan(1.0))
524519
@test MOI.is_valid(model, c)
525520
@test !MOI.is_valid(
@@ -694,7 +689,6 @@ sorted by creation time.
694689
"""
695690
function test_model_ordered_indices(model::MOI.ModelLike, ::Config)
696691
@requires MOI.supports_incremental_interface(model, false)
697-
MOI.empty!(model)
698692
v1 = MOI.add_variable(model)
699693
@test MOI.get(model, MOI.ListOfVariableIndices()) == [v1]
700694
v2 = MOI.add_variable(model)
@@ -840,12 +834,14 @@ function test_model_UpperBoundAlreadySet(
840834
model::MOI.ModelLike,
841835
::Config{T},
842836
) where {T}
843-
MOI.empty!(model)
844-
@test MOI.is_empty(model)
845837
x = MOI.add_variable(model)
846838
f = MOI.SingleVariable(x)
847839
ub = zero(T)
848-
@test MOI.supports_constraint(model, MOI.SingleVariable, MOI.LessThan{T})
840+
@requires MOI.supports_constraint(
841+
model,
842+
MOI.SingleVariable,
843+
MOI.LessThan{T},
844+
)
849845
sets = [
850846
MOI.EqualTo(ub),
851847
MOI.Interval(ub, ub),

src/Test/test_modification.jl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -781,8 +781,6 @@ function test_modification_delete_variables_in_a_batch(
781781
model::MOI.ModelLike,
782782
config::Config,
783783
)
784-
MOI.empty!(model)
785-
@test MOI.is_empty(model)
786784
MOIU.loadfromstring!(
787785
model,
788786
"""
@@ -849,7 +847,6 @@ function test_modification_affine_deletion_edge_cases(
849847
model::MOI.ModelLike,
850848
config::Config,
851849
)
852-
MOI.empty!(model)
853850
x = MOI.add_variable(model)
854851
# helpers. The function 1.0x + 0.0
855852
saf = MOI.ScalarAffineFunction([MOI.ScalarAffineTerm(1.0, x)], 0.0)

src/Test/test_nonlinear.jl

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,6 @@ function _test_HS071(model::MOI.ModelLike, config::Config, evaluator::HS071)
281281
MOI.GreaterThan{Float64},
282282
)
283283
@requires MOI.supports(model, MOI.VariablePrimalStart(), MOI.VariableIndex)
284-
MOI.empty!(model)
285-
@test MOI.is_empty(model)
286284
lb = [25.0, 40.0]
287285
ub = [Inf, 40.0]
288286
block_data = MOI.NLPBlockData(MOI.NLPBoundsPair.(lb, ub), evaluator, true)
@@ -458,8 +456,6 @@ function test_nonlinear_objective_and_moi_objective_test(
458456
)
459457
@requires MOI.supports(model, MOI.NLPBlock())
460458
@requires MOI.supports(model, MOI.VariablePrimalStart(), MOI.VariableIndex)
461-
MOI.empty!(model)
462-
@test MOI.is_empty(model)
463459
lb = [1.0]
464460
ub = [2.0]
465461
block_data = MOI.NLPBlockData(
@@ -521,7 +517,6 @@ function test_nonlinear_mixed_complementarity(
521517
MOI.VectorAffineFunction{Float64},
522518
MOI.Complements,
523519
)
524-
MOI.empty!(model)
525520
x = MOI.add_variables(model, 4)
526521
MOI.add_constraint.(model, MOI.SingleVariable.(x), MOI.Interval(0.0, 10.0))
527522
MOI.set.(model, MOI.VariablePrimalStart(), x, 0.0)
@@ -614,7 +609,6 @@ function test_nonlinear_qp_complementarity_constraint(
614609
MOI.VectorOfVariables,
615610
MOI.Complements,
616611
)
617-
MOI.empty!(model)
618612
x = MOI.add_variables(model, 8)
619613
MOI.set.(model, MOI.VariablePrimalStart(), x, 0.0)
620614
MOI.add_constraint.(model, MOI.SingleVariable.(x), MOI.GreaterThan(0.0))

0 commit comments

Comments
 (0)