1 # Copyright 2014 MINES ParisTech
3 # This file is part of LinPy.
5 # LinPy is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # LinPy is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with LinPy. If not, see <http://www.gnu.org/licenses/>.
20 from ..linexprs
import symbols
21 from ..polyhedra
import Empty
, Polyhedron
, Universe
22 from .libhelper
import requires_sympy
25 class TestPolyhedron(unittest
.TestCase
):
29 self
.square
= Polyhedron(inequalities
=[x
, 1 - x
, y
, 1 - y
])
31 def test_symbols(self
):
32 self
.assertTupleEqual(self
.square
.symbols
, symbols('x y'))
34 def test_dimension(self
):
35 self
.assertEqual(self
.square
.dimension
, 2)
38 self
.assertEqual(repr(self
.square
),
39 'And(0 <= x, x <= 1, 0 <= y, y <= 1)')
41 def test_fromstring(self
):
43 Polyhedron
.fromstring(
44 '{x >= 0, -x + 1 >= 0, y >= 0, -y + 1 >= 0}'),
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
):
56 sp_x
, sp_y
= sympy
.symbols('x y')
59 (sp_x
>= 0) & (sp_x
<= 1) & (sp_y
>= 0) & (sp_y
<= 1)),
63 def test_tosympy(self
):
65 sp_x
, sp_y
= sympy
.symbols('x y')
67 self
.square
.tosympy(),
68 sympy
.And(-sp_x
+ 1 >= 0, -sp_y
+ 1 >= 0, sp_x
>= 0, sp_y
>= 0))
74 self
.assertEqual(repr(Empty
), 'Empty')
76 def test_isempty(self
):
77 self
.assertTrue(Empty
.isempty())
79 def test_isuniverse(self
):
80 self
.assertFalse(Empty
.isuniverse())
86 self
.assertEqual(repr(Universe
), 'Universe')
88 def test_isempty(self
):
89 self
.assertTrue(Universe
.isempty())
91 def test_isuniverse(self
):
92 self
.assertTrue(Universe
.isuniverse())