@@ -234,10 +234,152 @@ minobjective: 1.0*x*x
234234 )
235235end
236236
237- function test_read ()
237+ function test_read_example_lo1 ()
238238 model = LP. Model ()
239- exception = ErrorException (" read! is not implemented for LP files." )
240- @test_throws exception MOI. read_from_file (model, LP_TEST_FILE)
239+ MOI. read_from_file (model, joinpath (@__DIR__ , " models" , " example_lo1.lp" ))
240+ @test MOI. get (model, MOI. NumberOfVariables ()) == 4
241+ constraints = MOI. get (model, MOI. ListOfConstraintTypesPresent ())
242+ @test (MOI. ScalarAffineFunction{Float64}, MOI. EqualTo{Float64}) in
243+ constraints
244+ @test (MOI. ScalarAffineFunction{Float64}, MOI. GreaterThan{Float64}) in
245+ constraints
246+ @test (MOI. ScalarAffineFunction{Float64}, MOI. LessThan{Float64}) in
247+ constraints
248+ @test (MOI. VariableIndex, MOI. GreaterThan{Float64}) in constraints
249+ @test (MOI. VariableIndex, MOI. Interval{Float64}) in constraints
250+ return nothing
251+ end
252+
253+ function test_read_model2 ()
254+ model = LP. Model ()
255+ MOI. read_from_file (model, joinpath (@__DIR__ , " models" , " model2.lp" ))
256+ @test MOI. get (model, MOI. NumberOfVariables ()) == 8
257+ constraints = MOI. get (model, MOI. ListOfConstraintTypesPresent ())
258+ @test (MOI. ScalarAffineFunction{Float64}, MOI. GreaterThan{Float64}) in
259+ constraints
260+ @test (MOI. ScalarAffineFunction{Float64}, MOI. LessThan{Float64}) in
261+ constraints
262+ @test (MOI. VariableIndex, MOI. GreaterThan{Float64}) in constraints
263+ @test (MOI. VariableIndex, MOI. Interval{Float64}) in constraints
264+ @test (MathOptInterface. VariableIndex, MathOptInterface. Integer) in
265+ constraints
266+ @test (MathOptInterface. VariableIndex, MathOptInterface. ZeroOne) in
267+ constraints
268+ # Adicionar testes dos bounds de V8
269+ @test MOI. get (model, MOI. VariableName (), MOI. VariableIndex (8 )) == " V8"
270+ @test model. variables. lower[8 ] == - Inf
271+ @test model. variables. upper[8 ] == - 3
272+ obj_type = MOI. get (model, MOI. ObjectiveFunctionType ())
273+ obj_func = MOI. get (model, MOI. ObjectiveFunction {obj_type} ())
274+ @test obj_func. constant == 2.5
275+ return nothing
276+ end
277+
278+ function test_read_model1_tricky ()
279+ model = LP. Model ()
280+ MOI. read_from_file (model, joinpath (@__DIR__ , " models" , " model1_tricky.lp" ))
281+ @test MOI. get (model, MOI. NumberOfVariables ()) == 8
282+ var_names = MOI. get .(model, MOI. VariableName (), MOI. VariableIndex .(1 : 8 ))
283+ @test Set (var_names) ==
284+ Set ([" Var4" , " V5" , " V1" , " V2" , " V3" , " V6" , " V7" , " V8" ])
285+ return nothing
286+ end
287+
288+ function test_read_corrupt ()
289+ model = LP. Model ()
290+ @test_throws ErrorException MOI. read_from_file (
291+ model,
292+ joinpath (@__DIR__ , " models" , " corrupt.lp" ),
293+ )
294+ return nothing
295+ end
296+
297+ function test_read_invalid_variable_name ()
298+ model = LP. Model ()
299+ @test_throws ErrorException MOI. read_from_file (
300+ model,
301+ joinpath (@__DIR__ , " models" , " invalid_variable_name.lp" ),
302+ )
303+ return nothing
304+ end
305+
306+ function test_read_invalid_affine_term_objective ()
307+ model = LP. Model ()
308+ @test_throws ErrorException MOI. read_from_file (
309+ model,
310+ joinpath (@__DIR__ , " models" , " invalid_affine_term_objective.lp" ),
311+ )
312+ return nothing
313+ end
314+
315+ function test_read_invalid_affine_term_constraint ()
316+ model = LP. Model ()
317+ @test_throws ErrorException MOI. read_from_file (
318+ model,
319+ joinpath (@__DIR__ , " models" , " invalid_affine_term_constraint.lp" ),
320+ )
321+ return nothing
322+ end
323+
324+ function test_read_invalid_sos_set ()
325+ model = LP. Model ()
326+ @test_throws ErrorException MOI. read_from_file (
327+ model,
328+ joinpath (@__DIR__ , " models" , " invalid_sos_set.lp" ),
329+ )
330+ return nothing
331+ end
332+
333+ function test_read_invalid_sos_constraint ()
334+ model = LP. Model ()
335+ @test_throws ErrorException MOI. read_from_file (
336+ model,
337+ joinpath (@__DIR__ , " models" , " invalid_sos_constraint.lp" ),
338+ )
339+ return nothing
340+ end
341+
342+ function test_read_invalid_bound ()
343+ model = LP. Model ()
344+ @test_throws ErrorException MOI. read_from_file (
345+ model,
346+ joinpath (@__DIR__ , " models" , " invalid_bound.lp" ),
347+ )
348+ return nothing
349+ end
350+
351+ function test_read_invalid_constraint ()
352+ model = LP. Model ()
353+ @test_throws ErrorException MOI. read_from_file (
354+ model,
355+ joinpath (@__DIR__ , " models" , " invalid_constraint.lp" ),
356+ )
357+ return nothing
358+ end
359+
360+ function test_read_model1 ()
361+ model = LP. Model ()
362+ MOI. read_from_file (model, joinpath (@__DIR__ , " models" , " model1.lp" ))
363+ constraints = MOI. get (model, MOI. ListOfConstraintTypesPresent ())
364+ @test (MOI. ScalarAffineFunction{Float64}, MOI. GreaterThan{Float64}) in
365+ constraints
366+ @test (MOI. ScalarAffineFunction{Float64}, MOI. LessThan{Float64}) in
367+ constraints
368+ @test (MOI. VariableIndex, MOI. GreaterThan{Float64}) in constraints
369+ @test (MOI. VariableIndex, MOI. Interval{Float64}) in constraints
370+ @test (MathOptInterface. VariableIndex, MathOptInterface. Integer) in
371+ constraints
372+ @test (MathOptInterface. VariableIndex, MathOptInterface. ZeroOne) in
373+ constraints
374+ @test (
375+ MathOptInterface. VectorOfVariables,
376+ MathOptInterface. SOS1{Float64},
377+ ) in constraints
378+ @test (
379+ MathOptInterface. VectorOfVariables,
380+ MathOptInterface. SOS2{Float64},
381+ ) in constraints
382+ return nothing
241383end
242384
243385function runtests ()
0 commit comments