689602b99e1e1c0d4e9475d593472e1daacd55fa
4 from ..linexprs
import symbols
5 from ..polyhedra
import *
6 from .libhelper
import requires_sympy
9 class TestPolyhedron(unittest
.TestCase
):
13 self
.square
= Polyhedron(inequalities
=[x
, 1 - x
, y
, 1 - y
])
15 def test_symbols(self
):
16 self
.assertTupleEqual(self
.square
.symbols
, symbols('x y'))
18 def test_dimension(self
):
19 self
.assertEqual(self
.square
.dimension
, 2)
22 self
.assertEqual(str(self
.square
),
23 'And(0 <= x, 0 <= -x + 1, 0 <= y, 0 <= -y + 1)')
26 self
.assertEqual(repr(self
.square
),
27 "And(0 <= x, 0 <= -x + 1, 0 <= y, 0 <= -y + 1)")
29 def test_fromstring(self
):
30 self
.assertEqual(Polyhedron
.fromstring('{x >= 0, -x + 1 >= 0, '
31 'y >= 0, -y + 1 >= 0}'), self
.square
)
33 def test_isempty(self
):
34 self
.assertFalse(self
.square
.isempty())
36 def test_isuniverse(self
):
37 self
.assertFalse(self
.square
.isuniverse())
40 def test_fromsympy(self
):
42 sp_x
, sp_y
= sympy
.symbols('x y')
43 self
.assertEqual(Polyhedron
.fromsympy((sp_x
>= 0) & (sp_x
<= 1) &
44 (sp_y
>= 0) & (sp_y
<= 1)), self
.square
)
47 def test_tosympy(self
):
49 sp_x
, sp_y
= sympy
.symbols('x y')
50 self
.assertEqual(self
.square
.tosympy(),
51 sympy
.And(-sp_x
+ 1 >= 0, -sp_y
+ 1 >= 0, sp_x
>= 0, sp_y
>= 0))
57 self
.assertEqual(repr(Empty
), 'Empty')
59 def test_isempty(self
):
60 self
.assertTrue(Empty
.isempty())
62 def test_isuniverse(self
):
63 self
.assertFalse(Empty
.isuniverse())
69 self
.assertEqual(repr(Universe
), 'Universe')
71 def test_isempty(self
):
72 self
.assertTrue(Universe
.isempty())
74 def test_isuniverse(self
):
75 self
.assertTrue(Universe
.isuniverse())