@@ -220,39 +220,35 @@ end
220
220
"""
221
221
runtests(
222
222
Bridge::Type{<:AbstractBridge},
223
- input::String ,
224
- output::String ;
223
+ input_fn::Function ,
224
+ output_fn::Function ;
225
225
variable_start = 1.2,
226
226
constraint_start = 1.2,
227
227
eltype = Float64,
228
228
)
229
229
230
230
Run a series of tests that check the correctness of `Bridge`.
231
231
232
- `input ` and `output ` are models in the style of
233
- [`MOI.Utilities.loadfromstring!`](@ref) .
232
+ `input_fn ` and `output_fn ` are functions such that `input_fn(model)`
233
+ and `output_fn(model)` load the corresponding model into `model` .
234
234
235
235
## Example
236
236
237
237
```jldoctest; setup=:(import MathOptInterface as MOI)
238
238
julia> MOI.Bridges.runtests(
239
239
MOI.Bridges.Constraint.ZeroOneBridge,
240
- \"\"\"
241
- variables: x
242
- x in ZeroOne()
243
- \"\"\" ,
244
- \"\"\"
245
- variables: x
246
- x in Integer()
247
- 1.0 * x in Interval(0.0, 1.0)
248
- \"\"\" ,
240
+ model -> MOI.add_constrained_variable(model, MOI.ZeroOne()),
241
+ model -> begin
242
+ x, _ = MOI.add_constrained_variable(model, MOI.Integer())
243
+ MOI.add_constraint(model, 1.0 * x, MOI.Interval(0.0, 1.0))
244
+ end,
249
245
)
250
246
```
251
247
"""
252
248
function runtests (
253
249
Bridge:: Type{<:AbstractBridge} ,
254
- input :: String ,
255
- output :: String ;
250
+ input_fn :: Function ,
251
+ output_fn :: Function ;
256
252
variable_start = 1.2 ,
257
253
constraint_start = 1.2 ,
258
254
eltype = Float64,
@@ -261,7 +257,7 @@ function runtests(
261
257
# Load model and bridge it
262
258
inner = MOI. Utilities. UniversalFallback (MOI. Utilities. Model {eltype} ())
263
259
model = _bridged_model (Bridge{eltype}, inner)
264
- MOI . Utilities . loadfromstring! (model, input )
260
+ input_fn (model)
265
261
final_touch (model)
266
262
# Should be able to call final_touch multiple times.
267
263
final_touch (model)
@@ -270,11 +266,11 @@ function runtests(
270
266
end
271
267
# Load a non-bridged input model, and check that getters are the same.
272
268
test = MOI. Utilities. UniversalFallback (MOI. Utilities. Model {eltype} ())
273
- MOI . Utilities . loadfromstring! (test, input )
269
+ input_fn (test)
274
270
_test_structural_identical (test, model)
275
271
# Load a bridged target model, and check that getters are the same.
276
272
target = MOI. Utilities. UniversalFallback (MOI. Utilities. Model {eltype} ())
277
- MOI . Utilities . loadfromstring! (target, output )
273
+ output_fn (target)
278
274
_test_structural_identical (target, inner)
279
275
# Test VariablePrimalStart
280
276
attr = MOI. VariablePrimalStart ()
@@ -318,6 +314,53 @@ function runtests(
318
314
return
319
315
end
320
316
317
+ """
318
+ runtests(
319
+ Bridge::Type{<:AbstractBridge},
320
+ input::String,
321
+ output::String;
322
+ variable_start = 1.2,
323
+ constraint_start = 1.2,
324
+ eltype = Float64,
325
+ )
326
+
327
+ Run a series of tests that check the correctness of `Bridge`.
328
+
329
+ `input` and `output` are models in the style of
330
+ [`MOI.Utilities.loadfromstring!`](@ref).
331
+
332
+ ## Example
333
+
334
+ ```jldoctest; setup=:(import MathOptInterface as MOI)
335
+ julia> MOI.Bridges.runtests(
336
+ MOI.Bridges.Constraint.ZeroOneBridge,
337
+ \"\"\"
338
+ variables: x
339
+ x in ZeroOne()
340
+ \"\"\" ,
341
+ \"\"\"
342
+ variables: x
343
+ x in Integer()
344
+ 1.0 * x in Interval(0.0, 1.0)
345
+ \"\"\" ,
346
+ )
347
+ ```
348
+ """
349
+ function runtests (
350
+ Bridge:: Type{<:AbstractBridge} ,
351
+ input:: String ,
352
+ output:: String ;
353
+ kwargs... ,
354
+ )
355
+ runtests (
356
+ Bridge,
357
+ model -> MOI. Utilities. loadfromstring! (model, input),
358
+ model -> MOI. Utilities. loadfromstring! (model, output);
359
+ kwargs... ,
360
+ )
361
+ return
362
+ end
363
+
321
364
_test_delete (:: Type{<:Variable.AbstractBridge} , model, inner) = nothing
322
365
323
366
function _test_delete (Bridge, model, inner)
0 commit comments