Skip to content

Commit 4aebdf3

Browse files
authored
Skip unit tests when problem not supported (#1244)
1 parent baa1cfe commit 4aebdf3

3 files changed

Lines changed: 17 additions & 5 deletions

File tree

src/Test/UnitTests/constraints.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,13 @@ with a ScalarQuadraticFunction-in-Set constraint.
281281
If `config.solve=true` confirm that it solves correctly.
282282
"""
283283
function solve_qcp_edge_cases(model::MOI.ModelLike, config::TestConfig)
284+
if !MOI.supports_constraint(
285+
model,
286+
MOI.ScalarQuadraticFunction{Float64},
287+
MOI.LessThan{Float64}
288+
)
289+
return
290+
end
284291
@testset "Duplicate on-diagonal" begin
285292
# max x + 2y | y + x^2 + x^2 <= 1, x >= 0.5, y >= 0.5
286293
MOI.empty!(model)

src/Test/UnitTests/objectives.jl

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,8 @@ objective function).
215215
If `config.solve=true` confirm that it solves correctly.
216216
"""
217217
function solve_qp_edge_cases(model::MOI.ModelLike, config::TestConfig)
218+
obj_attr = MOI.ObjectiveFunction{MOI.ScalarQuadraticFunction{Float64}}()
219+
MOI.supports(model, obj_attr) || return
218220
MOI.empty!(model)
219221
x = MOI.add_variables(model, 2)
220222
MOI.set(model, MOI.ObjectiveSense(), MOI.MIN_SENSE)
@@ -235,7 +237,7 @@ function solve_qp_edge_cases(model::MOI.ModelLike, config::TestConfig)
235237
# min x^2 + y^2 | x>=1, y>=2
236238
MOI.set(
237239
model,
238-
MOI.ObjectiveFunction{MOI.ScalarQuadraticFunction{Float64}}(),
240+
obj_attr,
239241
MOI.ScalarQuadraticFunction(
240242
MOI.ScalarAffineTerm{Float64}[], # affine terms
241243
MOI.ScalarQuadraticTerm.([2.0, 2.0], x, x), # quad
@@ -253,7 +255,7 @@ function solve_qp_edge_cases(model::MOI.ModelLike, config::TestConfig)
253255
# min x + x + x^2 + y^2 | x>=1, y>=2
254256
MOI.set(
255257
model,
256-
MOI.ObjectiveFunction{MOI.ScalarQuadraticFunction{Float64}}(),
258+
obj_attr,
257259
MOI.ScalarQuadraticFunction(
258260
MOI.ScalarAffineTerm.([1.0, 1.0], [x[1], x[1]]), # affine terms
259261
MOI.ScalarQuadraticTerm.([2.0, 2.0], x, x), # quad
@@ -271,7 +273,7 @@ function solve_qp_edge_cases(model::MOI.ModelLike, config::TestConfig)
271273
# min x^2 + x^2 | x>=1, y>=2
272274
MOI.set(
273275
model,
274-
MOI.ObjectiveFunction{MOI.ScalarQuadraticFunction{Float64}}(),
276+
obj_attr,
275277
MOI.ScalarQuadraticFunction(
276278
MOI.ScalarAffineTerm{Float64}[], # affine terms
277279
MOI.ScalarQuadraticTerm.(
@@ -293,7 +295,7 @@ function solve_qp_edge_cases(model::MOI.ModelLike, config::TestConfig)
293295
# min x^2 + 0.25x*y + 0.25y*x + 0.5x*y + y^2 | x>=1, y>=2
294296
MOI.set(
295297
model,
296-
MOI.ObjectiveFunction{MOI.ScalarQuadraticFunction{Float64}}(),
298+
obj_attr,
297299
MOI.ScalarQuadraticFunction(
298300
MOI.ScalarAffineTerm{Float64}[], # affine terms
299301
MOI.ScalarQuadraticTerm.(
@@ -322,6 +324,8 @@ Test quadratic program with a zero off-diagonal term.
322324
If `config.solve=true` confirm that it solves correctly.
323325
"""
324326
function solve_qp_zero_offdiag(model::MOI.ModelLike, config::TestConfig)
327+
obj_attr = MOI.ObjectiveFunction{MOI.ScalarQuadraticFunction{Float64}}()
328+
MOI.supports(model, obj_attr) || return
325329
MOI.empty!(model)
326330
x = MOI.add_variables(model, 2)
327331
MOI.set(model, MOI.ObjectiveSense(), MOI.MIN_SENSE)
@@ -339,7 +343,7 @@ function solve_qp_zero_offdiag(model::MOI.ModelLike, config::TestConfig)
339343
@test vc2.value == x[2].value
340344
MOI.set(
341345
model,
342-
MOI.ObjectiveFunction{MOI.ScalarQuadraticFunction{Float64}}(),
346+
obj_attr,
343347
MOI.ScalarQuadraticFunction(
344348
MOI.ScalarAffineTerm{Float64}[], # affine terms
345349
MOI.ScalarQuadraticTerm.(

src/Test/UnitTests/variables.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ unittests["update_dimension_nonnegative_variables"] =
155155
Test adding, and then deleting, second-order cone variables.
156156
"""
157157
function delete_soc_variables(model::MOI.ModelLike, config::TestConfig)
158+
MOI.supports_add_constrained_variables(model, MOI.SecondOrderCone) || return
158159
MOI.empty!(model)
159160
@test MOI.is_empty(model)
160161
@test MOI.get(model, MOI.NumberOfVariables()) == 0

0 commit comments

Comments
 (0)