File tree 1 file changed +50
-0
lines changed
1 file changed +50
-0
lines changed Original file line number Diff line number Diff line change
1
+ from typing import cast
2
+
3
+ import pytest
4
+
5
+ from lpmodeler .model import LPModel , LPStatus , LPVar
6
+
7
+
8
+ def test_sequential_solve () -> None :
9
+ x = LPVar ("x" , lower_bound = 0 )
10
+
11
+ model = LPModel ()
12
+
13
+ model .set_objective (x )
14
+
15
+ model .solve ()
16
+
17
+ assert model .status == LPStatus .OPTIMAL
18
+ assert x .value () == pytest .approx (0.0 )
19
+ assert model .objective .value () == pytest .approx (0.0 )
20
+
21
+ model .add_constraint (x >= 1 )
22
+
23
+ model .solve ()
24
+
25
+ assert model .status == LPStatus .OPTIMAL
26
+ assert x .value () == pytest .approx (1.0 )
27
+ assert model .objective .value () == pytest .approx (1.0 )
28
+
29
+
30
+ def test_sequential_solve_no_solution () -> None :
31
+ x = LPVar ("x" , lower_bound = 0 )
32
+
33
+ model = LPModel ()
34
+
35
+ model .set_objective (x )
36
+
37
+ model .solve ()
38
+
39
+ assert model .status == LPStatus .OPTIMAL
40
+ assert x .value () == pytest .approx (0.0 )
41
+ assert model .objective .value () == pytest .approx (0.0 )
42
+
43
+ model .add_constraint (x <= - 1 )
44
+
45
+ model .solve ()
46
+
47
+ status2 = cast (LPStatus , model .status )
48
+ assert status2 == LPStatus .INFEASIBLE
49
+ assert x .value () is None
50
+ assert model .objective .value () is None
You can’t perform that action at this time.
0 commit comments