Skip to content

Commit 6efbcd2

Browse files
committed
Add test
1 parent fc5fe5b commit 6efbcd2

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

test/MOI_wrapper.jl

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,41 @@ function test_scalar_nonlinear_function()
108108
return
109109
end
110110

111+
function test_not_dcp_constraint()
112+
inner = Convex.Optimizer(ECOS.Optimizer)
113+
model = MOI.Utilities.CachingOptimizer(
114+
MOI.Utilities.UniversalFallback(MOI.Utilities.Model{Float64}()),
115+
MOI.Bridges.full_bridge_optimizer(inner, Float64),
116+
)
117+
x = MOI.add_variable(model)
118+
f = MOI.ScalarNonlinearFunction(:^, Any[x, 2])
119+
MOI.add_constraint(model, f, MOI.GreaterThan(1.0))
120+
F, S = MOI.VectorNonlinearFunction, MOI.Nonnegatives
121+
@test_throws(
122+
MOI.AddConstraintNotAllowed{F,S},
123+
MOI.Utilities.attach_optimizer(model),
124+
)
125+
return
126+
end
127+
128+
function test_not_dcp_objective()
129+
inner = Convex.Optimizer(ECOS.Optimizer)
130+
model = MOI.Utilities.CachingOptimizer(
131+
MOI.Utilities.UniversalFallback(MOI.Utilities.Model{Float64}()),
132+
MOI.Bridges.full_bridge_optimizer(inner, Float64),
133+
)
134+
x = MOI.add_variable(model)
135+
f = MOI.ScalarNonlinearFunction(:^, Any[x, 2])
136+
MOI.set(model, MOI.ObjectiveSense(), MOI.MAX_SENSE)
137+
attr = MOI.ObjectiveFunction{typeof(f)}()
138+
MOI.set(model, attr, f)
139+
@test_throws(
140+
MOI.SetAttributeNotAllowed{typeof(attr)},
141+
MOI.Utilities.attach_optimizer(model),
142+
)
143+
return
144+
end
145+
111146
end # TestMOIWrapper
112147

113148
TestMOIWrapper.runtests()

0 commit comments

Comments
 (0)