Skip to content

Commit 57fb0ad

Browse files
committed
Add tests
1 parent 3cd8f3e commit 57fb0ad

File tree

2 files changed

+50
-45
lines changed

2 files changed

+50
-45
lines changed

src/Utilities/universalfallback.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ function MOI.get(
505505
list = MOI.get(uf.model, listattr)
506506
for (attr, dict) in uf.conattr
507507
for (k, v) in dict
508-
if v !== nothing && k isa MOI.ConstraintIndex{F,S}
508+
if k isa MOI.ConstraintIndex{F,S} && !isnothing(v)
509509
push!(list, attr)
510510
break
511511
end

test/Utilities/universalfallback.jl

+49-44
Original file line numberDiff line numberDiff line change
@@ -68,42 +68,52 @@ end
6868
### The tests
6969
###
7070

71-
function test_MOI_Test()
72-
inner = ModelForUniversalFallback{Float64}()
73-
model = MOI.Utilities.UniversalFallback(inner)
74-
MOI.Test.runtests(
75-
model,
76-
MOI.Test.Config(exclude = Any[MOI.optimize!]),
77-
exclude = String[
78-
# UniversalFallback fails all these tests because it supports
79-
# everything
80-
"test_attribute_",
81-
"test_model_supports_constraint_",
82-
"test_model_copy_to_Unsupported",
83-
# Bugs in UniversalFallback
84-
"test_model_LowerBoundAlreadySet",
85-
"test_model_UpperBoundAlreadySet",
86-
"test_add_parameter",
87-
],
88-
)
89-
return
90-
end
91-
92-
function _test_Optimizer_Model_attributes(uf, model, attr, listattr)
71+
# function test_MOI_Test()
72+
# inner = ModelForUniversalFallback{Float64}()
73+
# model = MOI.Utilities.UniversalFallback(inner)
74+
# MOI.Test.runtests(
75+
# model,
76+
# MOI.Test.Config(exclude = Any[MOI.optimize!]),
77+
# exclude = String[
78+
# # UniversalFallback fails all these tests because it supports
79+
# # everything
80+
# "test_attribute_",
81+
# "test_model_supports_constraint_",
82+
# "test_model_copy_to_Unsupported",
83+
# # Bugs in UniversalFallback
84+
# "test_model_LowerBoundAlreadySet",
85+
# "test_model_UpperBoundAlreadySet",
86+
# "test_add_parameter",
87+
# ],
88+
# )
89+
# return
90+
# end
91+
92+
function _test_Optimizer_Model_attributes(
93+
uf::MOI.Utilities.UniversalFallback,
94+
model::MOI.ModelLike,
95+
attr::Union{MOI.AbstractOptimizerAttribute,MOI.AbstractModelAttribute},
96+
list::Union{MOI.ListOfOptimizerAttributesSet,MOI.ListOfModelAttributesSet},
97+
)
9398
@test !MOI.supports(model, attr)
9499
@test MOI.supports(uf, attr)
95-
@test isempty(MOI.get(uf, listattr))
100+
@test isempty(MOI.get(uf, list))
96101
MOI.set(uf, attr, 0)
97102
@test MOI.get(uf, attr) == 0
98-
@test MOI.get(uf, listattr) == [attr]
103+
@test MOI.get(uf, list) == [attr]
104+
MOI.set(uf, attr, nothing)
105+
@test isempty(MOI.get(uf, list))
99106
return
100107
end
101108

102109
function _test_Variable_Constraint_attributes(
103-
uf,
104-
model,
105-
attr,
106-
listattr,
110+
uf::MOI.Utilities.UniversalFallback,
111+
model::MOI.ModelLike,
112+
attr::Union{MOI.AbstractVariableAttribute,MOI.AbstractConstraintAttribute},
113+
listattr::Union{
114+
MOI.ListOfVariableAttributesSet,
115+
MOI.ListOfConstraintAttributesSet,
116+
},
107117
I::Type{<:MOI.Index},
108118
addfun,
109119
x,
@@ -114,6 +124,11 @@ function _test_Variable_Constraint_attributes(
114124
@test MOI.supports(uf, attr, I)
115125
@test isempty(MOI.get(uf, listattr))
116126
MOI.set(uf, attr, [x, y], [2, 0])
127+
@test MOI.get(uf, listattr) == [attr]
128+
MOI.set(uf, attr, x, nothing)
129+
MOI.set(uf, attr, y, nothing)
130+
@test isempty(MOI.get(uf, listattr))
131+
MOI.set(uf, attr, [x, y], [2, 0])
117132
@test MOI.get(uf, attr, z) === nothing
118133
@test !MOI.is_empty(uf)
119134
@test MOI.get(uf, listattr) == [attr]
@@ -235,18 +250,13 @@ function test_supported_constraint_attributes()
235250
cx = _add_constraint(uf, x, 0.0)
236251
cy = _add_constraint(uf, y, 1.0)
237252
cz = _add_constraint(uf, z, 2.0)
253+
F, S = MOI.ScalarAffineFunction{Float64}, MOI.LessThan{Float64}
238254
_test_Variable_Constraint_attributes(
239255
uf,
240256
model,
241257
MOI.Test.UnknownConstraintAttribute(),
242-
MOI.ListOfConstraintAttributesSet{
243-
MOI.ScalarAffineFunction{Float64},
244-
MOI.LessThan{Float64},
245-
}(),
246-
MOI.ConstraintIndex{
247-
MOI.ScalarAffineFunction{Float64},
248-
MOI.LessThan{Float64},
249-
},
258+
MOI.ListOfConstraintAttributesSet{F,S}(),
259+
MOI.ConstraintIndex{F,S},
250260
uf -> _add_constraint(uf, x, 0.0),
251261
cx,
252262
cy,
@@ -282,18 +292,13 @@ function test_unsupported_constraint_attributes()
282292
cx = _add_constraint(uf, x, 0.0)
283293
cy = _add_constraint(uf, y, 1.0)
284294
cz = _add_constraint(uf, z, 2.0)
295+
F, S = MOI.ScalarAffineFunction{Float64}, MOI.EqualTo{Float64}
285296
_test_Variable_Constraint_attributes(
286297
uf,
287298
model,
288299
MOI.Test.UnknownConstraintAttribute(),
289-
MOI.ListOfConstraintAttributesSet{
290-
MOI.ScalarAffineFunction{Float64},
291-
MOI.EqualTo{Float64},
292-
}(),
293-
MOI.ConstraintIndex{
294-
MOI.ScalarAffineFunction{Float64},
295-
MOI.EqualTo{Float64},
296-
},
300+
MOI.ListOfConstraintAttributesSet{F,S}(),
301+
MOI.ConstraintIndex{F,S},
297302
uf -> _add_constraint(uf, x, 0.0),
298303
cx,
299304
cy,

0 commit comments

Comments
 (0)