Skip to content

Commit b6e9719

Browse files
authored
[Test] simplify check for supported conflict status (#2649)
1 parent 875387a commit b6e9719

File tree

1 file changed

+18
-59
lines changed

1 file changed

+18
-59
lines changed

src/Test/test_solve.jl

Lines changed: 18 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -885,16 +885,11 @@ function test_solve_conflict_bound_bound(
885885
) where {T}
886886
@requires _supports(config, MOI.compute_conflict!)
887887
@requires _supports(config, MOI.optimize!)
888-
try
889-
MOI.get(model, MOI.ConflictStatus())
890-
catch
891-
return # If this fails, skip the test.
892-
end
893888
x = MOI.add_variable(model)
894889
c1 = MOI.add_constraint(model, x, MOI.GreaterThan(T(2)))
895890
c2 = MOI.add_constraint(model, x, MOI.LessThan(T(1)))
896-
@test MOI.get(model, MOI.ConflictStatus()) ==
897-
MOI.COMPUTE_CONFLICT_NOT_CALLED
891+
status = MOI.get(model, MOI.ConflictStatus())
892+
@test status == MOI.COMPUTE_CONFLICT_NOT_CALLED
898893
MOI.optimize!(model)
899894
@test MOI.get(model, MOI.TerminationStatus()) == config.infeasible_status
900895
MOI.compute_conflict!(model)
@@ -941,11 +936,6 @@ function test_solve_conflict_two_affine(
941936
) where {T}
942937
@requires _supports(config, MOI.compute_conflict!)
943938
@requires _supports(config, MOI.optimize!)
944-
try
945-
MOI.get(model, MOI.ConflictStatus())
946-
catch
947-
return # If this fails, skip the test.
948-
end
949939
x = MOI.add_variable(model)
950940
c1 = MOI.add_constraint(
951941
model,
@@ -957,8 +947,8 @@ function test_solve_conflict_two_affine(
957947
MOI.ScalarAffineFunction(MOI.ScalarAffineTerm.(T(1), [x]), T(0)),
958948
MOI.LessThan(T(1)),
959949
)
960-
@test MOI.get(model, MOI.ConflictStatus()) ==
961-
MOI.COMPUTE_CONFLICT_NOT_CALLED
950+
status = MOI.get(model, MOI.ConflictStatus())
951+
@test status == MOI.COMPUTE_CONFLICT_NOT_CALLED
962952
MOI.optimize!(model)
963953
@test MOI.get(model, MOI.TerminationStatus()) == config.infeasible_status
964954
MOI.compute_conflict!(model)
@@ -1005,15 +995,10 @@ function test_solve_conflict_invalid_interval(
1005995
) where {T}
1006996
@requires _supports(config, MOI.compute_conflict!)
1007997
@requires _supports(config, MOI.optimize!)
1008-
try
1009-
MOI.get(model, MOI.ConflictStatus())
1010-
catch
1011-
return # If this fails, skip the test.
1012-
end
1013998
x = MOI.add_variable(model)
1014999
c1 = MOI.add_constraint(model, x, MOI.Interval(T(1), T(0)))
1015-
@test MOI.get(model, MOI.ConflictStatus()) ==
1016-
MOI.COMPUTE_CONFLICT_NOT_CALLED
1000+
status = MOI.get(model, MOI.ConflictStatus())
1001+
@test status == MOI.COMPUTE_CONFLICT_NOT_CALLED
10171002
MOI.optimize!(model)
10181003
@test MOI.get(model, MOI.TerminationStatus()) == config.infeasible_status
10191004
MOI.compute_conflict!(model)
@@ -1057,11 +1042,6 @@ function test_solve_conflict_affine_affine(
10571042
) where {T}
10581043
@requires _supports(config, MOI.compute_conflict!)
10591044
@requires _supports(config, MOI.optimize!)
1060-
try
1061-
MOI.get(model, MOI.ConflictStatus())
1062-
catch
1063-
return # If this fails, skip the test.
1064-
end
10651045
x = MOI.add_variable(model)
10661046
y = MOI.add_variable(model)
10671047
b1 = MOI.add_constraint(model, x, MOI.GreaterThan(T(0)))
@@ -1071,8 +1051,8 @@ function test_solve_conflict_affine_affine(
10711051
cf2 =
10721052
MOI.ScalarAffineFunction(MOI.ScalarAffineTerm.(T[1, -1], [x, y]), T(0))
10731053
c2 = MOI.add_constraint(model, cf2, MOI.GreaterThan(T(1)))
1074-
@test MOI.get(model, MOI.ConflictStatus()) ==
1075-
MOI.COMPUTE_CONFLICT_NOT_CALLED
1054+
status = MOI.get(model, MOI.ConflictStatus())
1055+
@test status == MOI.COMPUTE_CONFLICT_NOT_CALLED
10761056
MOI.optimize!(model)
10771057
@test MOI.get(model, MOI.TerminationStatus()) == config.infeasible_status
10781058
MOI.compute_conflict!(model)
@@ -1124,11 +1104,6 @@ function test_solve_conflict_EqualTo(
11241104
) where {T}
11251105
@requires _supports(config, MOI.compute_conflict!)
11261106
@requires _supports(config, MOI.optimize!)
1127-
try
1128-
MOI.get(model, MOI.ConflictStatus())
1129-
catch
1130-
return # If this fails, skip the test.
1131-
end
11321107
x = MOI.add_variable(model)
11331108
y = MOI.add_variable(model)
11341109
b1 = MOI.add_constraint(model, x, MOI.GreaterThan(T(0)))
@@ -1138,8 +1113,8 @@ function test_solve_conflict_EqualTo(
11381113
cf2 =
11391114
MOI.ScalarAffineFunction(MOI.ScalarAffineTerm.(T[1, -1], [x, y]), T(0))
11401115
c2 = MOI.add_constraint(model, cf2, MOI.GreaterThan(T(1)))
1141-
@test MOI.get(model, MOI.ConflictStatus()) ==
1142-
MOI.COMPUTE_CONFLICT_NOT_CALLED
1116+
status = MOI.get(model, MOI.ConflictStatus())
1117+
@test status == MOI.COMPUTE_CONFLICT_NOT_CALLED
11431118
MOI.optimize!(model)
11441119
@test MOI.get(model, MOI.TerminationStatus()) == config.infeasible_status
11451120
MOI.compute_conflict!(model)
@@ -1191,11 +1166,6 @@ function test_solve_conflict_NOT_IN_CONFLICT(
11911166
) where {T}
11921167
@requires _supports(config, MOI.compute_conflict!)
11931168
@requires _supports(config, MOI.optimize!)
1194-
try
1195-
MOI.get(model, MOI.ConflictStatus())
1196-
catch
1197-
return # If this fails, skip the test.
1198-
end
11991169
x = MOI.add_variable(model)
12001170
y = MOI.add_variable(model)
12011171
z = MOI.add_variable(model)
@@ -1210,8 +1180,8 @@ function test_solve_conflict_NOT_IN_CONFLICT(
12101180
T(0),
12111181
)
12121182
c2 = MOI.add_constraint(model, cf2, MOI.GreaterThan(T(1)))
1213-
@test MOI.get(model, MOI.ConflictStatus()) ==
1214-
MOI.COMPUTE_CONFLICT_NOT_CALLED
1183+
status = MOI.get(model, MOI.ConflictStatus())
1184+
@test status == MOI.COMPUTE_CONFLICT_NOT_CALLED
12151185
MOI.optimize!(model)
12161186
@test MOI.get(model, MOI.TerminationStatus()) == config.infeasible_status
12171187
MOI.compute_conflict!(model)
@@ -1268,17 +1238,12 @@ function test_solve_conflict_feasible(
12681238
) where {T}
12691239
@requires _supports(config, MOI.compute_conflict!)
12701240
@requires _supports(config, MOI.optimize!)
1271-
try
1272-
MOI.get(model, MOI.ConflictStatus())
1273-
catch
1274-
return # If this fails, skip the test.
1275-
end
12761241
x = MOI.add_variable(model)
12771242
f = MOI.ScalarAffineFunction([MOI.ScalarAffineTerm(T(1), x)], T(0))
12781243
_ = MOI.add_constraint(model, f, MOI.GreaterThan(T(1)))
12791244
_ = MOI.add_constraint(model, f, MOI.LessThan(T(2)))
1280-
@test MOI.get(model, MOI.ConflictStatus()) ==
1281-
MOI.COMPUTE_CONFLICT_NOT_CALLED
1245+
status = MOI.get(model, MOI.ConflictStatus())
1246+
@test status == MOI.COMPUTE_CONFLICT_NOT_CALLED
12821247
MOI.optimize!(model)
12831248
@test MOI.get(model, MOI.TerminationStatus()) == config.optimal_status
12841249
MOI.compute_conflict!(model)
@@ -1317,17 +1282,14 @@ function test_solve_conflict_zeroone(
13171282
) where {T}
13181283
@requires _supports(config, MOI.compute_conflict!)
13191284
@requires _supports(config, MOI.optimize!)
1320-
try
1321-
MOI.get(model, MOI.ConflictStatus())
1322-
catch
1323-
return # If this fails, skip the test.
1324-
end
13251285
x, c1 = MOI.add_constrained_variable(model, MOI.ZeroOne())
13261286
c2 = MOI.add_constraint(
13271287
model,
13281288
MOI.ScalarAffineFunction(MOI.ScalarAffineTerm.(T(1), [x]), T(0)),
13291289
MOI.GreaterThan(T(2)),
13301290
)
1291+
status = MOI.get(model, MOI.ConflictStatus())
1292+
@test status == MOI.COMPUTE_CONFLICT_NOT_CALLED
13311293
MOI.optimize!(model)
13321294
@test MOI.get(model, MOI.TerminationStatus()) == config.infeasible_status
13331295
MOI.compute_conflict!(model)
@@ -1378,17 +1340,14 @@ function test_solve_conflict_zeroone_2(
13781340
@requires (T(1) / T(2)) isa T
13791341
@requires _supports(config, MOI.compute_conflict!)
13801342
@requires _supports(config, MOI.optimize!)
1381-
try
1382-
MOI.get(model, MOI.ConflictStatus())
1383-
catch
1384-
return # If this fails, skip the test.
1385-
end
13861343
x, c1 = MOI.add_constrained_variable(model, MOI.ZeroOne())
13871344
c2 = MOI.add_constraint(
13881345
model,
13891346
MOI.ScalarAffineFunction(MOI.ScalarAffineTerm.(T(1), [x]), T(0)),
13901347
MOI.EqualTo(T(1) / T(2)),
13911348
)
1349+
status = MOI.get(model, MOI.ConflictStatus())
1350+
@test status == MOI.COMPUTE_CONFLICT_NOT_CALLED
13921351
MOI.optimize!(model)
13931352
@test MOI.get(model, MOI.TerminationStatus()) == config.infeasible_status
13941353
MOI.compute_conflict!(model)

0 commit comments

Comments
 (0)