Remove backup files
[linpy.git] / pypol / tests / test_polyhedra.py
1 import functools
2 import unittest
3
4 from ..linexprs import symbols
5 from ..polyhedra import *
6 from .libhelper import requires_sympy
7
8
9 class TestPolyhedron(unittest.TestCase):
10
11 def setUp(self):
12 x, y = symbols('x y')
13 self.square = Polyhedron(inequalities=[x, 1 - x, y, 1 - y])
14
15 def test_symbols(self):
16 self.assertTupleEqual(self.square.symbols, symbols('x y'))
17
18 def test_dimension(self):
19 self.assertEqual(self.square.dimension, 2)
20
21 def test_str(self):
22 self.assertEqual(str(self.square),
23 'And(Ge(x, 0), Ge(-x + 1, 0), Ge(y, 0), Ge(-y + 1, 0))')
24
25 def test_repr(self):
26 self.assertEqual(repr(self.square),
27 "And(Ge(x, 0), Ge(-x + 1, 0), Ge(y, 0), Ge(-y + 1, 0))")
28
29 def test_fromstring(self):
30 self.assertEqual(Polyhedron.fromstring('{x >= 0, -x + 1 >= 0, '
31 'y >= 0, -y + 1 >= 0}'), self.square)
32
33 def test_isempty(self):
34 self.assertFalse(self.square.isempty())
35
36 def test_isuniverse(self):
37 self.assertFalse(self.square.isuniverse())
38
39 @requires_sympy
40 def test_fromsympy(self):
41 import sympy
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)
45
46 @requires_sympy
47 def test_tosympy(self):
48 import sympy
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))
52
53
54 class TestEmpty:
55
56 def test_repr(self):
57 self.assertEqual(repr(Empty), 'Empty')
58
59 def test_isempty(self):
60 self.assertTrue(Empty.isempty())
61
62 def test_isuniverse(self):
63 self.assertFalse(Empty.isuniverse())
64
65
66 class TestUniverse:
67
68 def test_repr(self):
69 self.assertEqual(repr(Universe), 'Universe')
70
71 def test_isempty(self):
72 self.assertTrue(Universe.isempty())
73
74 def test_isuniverse(self):
75 self.assertTrue(Universe.isuniverse())