c74e25f794d06f54c75aa3ba8b4b2b89d2fd9220
4 from ..linexprs
import symbols
5 from ..polyhedra
import *
10 def _requires_sympy(func
):
11 @functools.wraps(func
)
16 def _requires_sympy(func
):
17 @functools.wraps(func
)
19 raise unittest
.SkipTest('SymPy is not available')
23 class TestPolyhedron(unittest
.TestCase
):
27 self
.square
= Polyhedron(inequalities
=[x
, 1 - x
, y
, 1 - y
])
29 def test_symbols(self
):
30 self
.assertCountEqual(self
.square
.symbols
, ['x', 'y'])
32 def test_dimension(self
):
33 self
.assertEqual(self
.square
.dimension
, 2)
36 self
.assertEqual(str(self
.square
),
37 'And(Ge(x, 0), Ge(-x + 1, 0), Ge(y, 0), Ge(-y + 1, 0))')
40 self
.assertEqual(repr(self
.square
),
41 "And(Ge(x, 0), Ge(-x + 1, 0), Ge(y, 0), Ge(-y + 1, 0))")
43 def test_fromstring(self
):
44 self
.assertEqual(Polyhedron
.fromstring('{x >= 0, -x + 1 >= 0, '
45 'y >= 0, -y + 1 >= 0}'), self
.square
)
47 def test_isempty(self
):
48 self
.assertFalse(self
.square
.isempty())
50 def test_isuniverse(self
):
51 self
.assertFalse(self
.square
.isuniverse())
54 def test_fromsympy(self
):
55 sp_x
, sp_y
= sympy
.symbols('x y')
56 self
.assertEqual(Polyhedron
.fromsympy((sp_x
>= 0) & (sp_x
<= 1) &
57 (sp_y
>= 0) & (sp_y
<= 1)), self
.square
)
60 def test_tosympy(self
):
61 sp_x
, sp_y
= sympy
.symbols('x y')
62 self
.assertEqual(self
.square
.tosympy(),
63 sympy
.And(-sp_x
+ 1 >= 0, -sp_y
+ 1 >= 0, sp_x
>= 0, sp_y
>= 0))
69 self
.assertEqual(repr(Empty
), 'Empty')
71 def test_isempty(self
):
72 self
.assertTrue(Empty
.isempty())
74 def test_isuniverse(self
):
75 self
.assertFalse(Empty
.isuniverse())
81 self
.assertEqual(repr(Universe
), 'Universe')
83 def test_isempty(self
):
84 self
.assertTrue(Universe
.isempty())
86 def test_isuniverse(self
):
87 self
.assertTrue(Universe
.isuniverse())