d0ebe57e09b0281ed5b02d0a0c4d954915f4ff35
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/>.
21 from ..linexprs
import symbols
22 from ..polyhedra
import *
23 from .libhelper
import requires_sympy
26 class TestPolyhedron(unittest
.TestCase
):
30 self
.square
= Polyhedron(inequalities
=[x
, 1 - x
, y
, 1 - y
])
32 def test_symbols(self
):
33 self
.assertTupleEqual(self
.square
.symbols
, symbols('x y'))
35 def test_dimension(self
):
36 self
.assertEqual(self
.square
.dimension
, 2)
39 self
.assertEqual(repr(self
.square
),
40 "And(0 <= x, x <= 1, 0 <= y, y <= 1)")
42 def test_fromstring(self
):
43 self
.assertEqual(Polyhedron
.fromstring('{x >= 0, -x + 1 >= 0, '
44 'y >= 0, -y + 1 >= 0}'), self
.square
)
46 def test_isempty(self
):
47 self
.assertFalse(self
.square
.isempty())
49 def test_isuniverse(self
):
50 self
.assertFalse(self
.square
.isuniverse())
53 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
):
62 sp_x
, sp_y
= sympy
.symbols('x y')
63 self
.assertEqual(self
.square
.tosympy(),
64 sympy
.And(-sp_x
+ 1 >= 0, -sp_y
+ 1 >= 0, sp_x
>= 0, sp_y
>= 0))
70 self
.assertEqual(repr(Empty
), 'Empty')
72 def test_isempty(self
):
73 self
.assertTrue(Empty
.isempty())
75 def test_isuniverse(self
):
76 self
.assertFalse(Empty
.isuniverse())
82 self
.assertEqual(repr(Universe
), 'Universe')
84 def test_isempty(self
):
85 self
.assertTrue(Universe
.isempty())
87 def test_isuniverse(self
):
88 self
.assertTrue(Universe
.isuniverse())