X-Git-Url: https://svn.cri.ensmp.fr/git/linpy.git/blobdiff_plain/50f0fde4dca3f10e535314b1c9d325cd9283735b..ce8dda550018a59520e2d632f10d3fe5650e9d0d:/linpy/tests/test_domains.py?ds=inline diff --git a/linpy/tests/test_domains.py b/linpy/tests/test_domains.py index 9e9f6fa..2d30b8b 100644 --- a/linpy/tests/test_domains.py +++ b/linpy/tests/test_domains.py @@ -17,9 +17,9 @@ import unittest -from ..domains import * +from ..domains import And, Or from ..linexprs import Symbol, symbols -from ..polyhedra import * +from ..polyhedra import Empty, Eq, Ge, Polyhedron class TestDomain(unittest.TestCase): @@ -27,23 +27,33 @@ class TestDomain(unittest.TestCase): def setUp(self): x, y = symbols('x y') self.square1 = Polyhedron(inequalities=[x, 2 - x, y, 2 - y]) - self.square2 = Polyhedron(inequalities=[x - 1, 3 - x , y - 1, 3 - y]) #correct representation + self.square2 = Polyhedron(inequalities=[x - 1, 3 - x, y - 1, 3 - y]) self.square3 = Polyhedron(inequalities=[x, 3 - x, y, 3 - y]) self.square4 = Polyhedron(inequalities=[x - 1, 2 - x, y - 1, 2 - y]) - self.square5 = Polyhedron(inequalities=[x - 3, 6 - x, y - 3, 6 -y]) - self.square6 = Polyhedron(equalities=[3 - y], inequalities=[x - 1, 3 - x, y - 1]) + self.square5 = Polyhedron(inequalities=[x - 3, 6 - x, y - 3, 6 - y]) + self.square6 = Polyhedron(equalities=[3 - y], + inequalities=[x - 1, 3 - x, y - 1]) self.unbound_poly = Polyhedron(inequalities=[x, 3 - x, y]) self.universe = Polyhedron([]) self.empty = Empty self.disjoint = And(Ge(x, 0), Ge(-x + 2, 0), Ge(y, 0), Ge(-y + 2, 0)) - self.complement = Or(Ge(-x - 1, 0), Ge(x - 3, 0), And(Ge(x, 0), Ge(-x + 2, 0), Ge(-y - 1, 0)), And(Ge(x, 0), Ge(-x + 2, 0), Ge(y - 3, 0))) + self.complement = Or(Ge(-x - 1, 0), Ge(x - 3, 0), + And(Ge(x, 0), Ge(-x + 2, 0), Ge(-y - 1, 0)), + And(Ge(x, 0), Ge(-x + 2, 0), Ge(y - 3, 0))) self.hull = And(Ge(x, 0), Ge(-x + 2, 0), Ge(y, 0), Ge(-y + 2, 0)) self.dropped = And(Ge(y, 0), Ge(-y + 2, 0)) - self.intersection = And(Ge(x - 1, 0), Ge(-x + 2, 0), Ge(y - 1, 0), Ge(-y + 2, 0)) - self.union = Or(And(Ge(x, 0), Ge(-x + 2, 0), Ge(y, 0), Ge(-y + 2, 0)), And(Ge(x - 1, 0), Ge(-x + 3, 0), Ge(y - 1, 0), Ge(-y + 3, 0))) - self.sum1 = Or(And(Ge(x, 0), Ge(-x + 2, 0), Ge(y, 0), Ge(-y + 2, 0)), And(Ge(x - 1, 0), Ge(-x + 3, 0), Ge(y - 1, 0), Ge(-y + 3, 0))) - self.sum2 =And(Ge(x, 0), Ge(y, 0), Ge(-y + 3, 0), Ge(-x + 3, 0), Ge(x - y + 2, 0), Ge(-x + y + 2, 0)) - self.difference1 = Or(And(Eq(x - 3, 0), Ge(y - 1, 0), Ge(-y + 3, 0)), And(Eq(y - 3, 0), Ge(x - 1, 0), Ge(-x + 2, 0))) + self.intersection = And(Ge(x - 1, 0), Ge(-x + 2, 0), Ge(y - 1, 0), + Ge(-y + 2, 0)) + self.union = Or(And(Ge(x, 0), Ge(-x + 2, 0), Ge(y, 0), Ge(-y + 2, 0)), + And(Ge(x - 1, 0), Ge(-x + 3, 0), Ge(y - 1, 0), + Ge(-y + 3, 0))) + self.sum1 = Or(And(Ge(x, 0), Ge(-x + 2, 0), Ge(y, 0), Ge(-y + 2, 0)), + And(Ge(x - 1, 0), Ge(-x + 3, 0), Ge(y - 1, 0), + Ge(-y + 3, 0))) + self.sum2 = And(Ge(x, 0), Ge(y, 0), Ge(-y + 3, 0), Ge(-x + 3, 0), + Ge(x - y + 2, 0), Ge(-x + y + 2, 0)) + self.difference1 = Or(And(Eq(x - 3, 0), Ge(y - 1, 0), Ge(-y + 3, 0)), + And(Eq(y - 3, 0), Ge(x - 1, 0), Ge(-x + 2, 0))) self.difference2 = And(Ge(x + y - 4, 0), Ge(-x + 3, 0), Ge(-y + 3, 0)) self.lexmin = And(Eq(y, 0), Eq(x, 0)) self.lexmax = And(Eq(y - 2, 0), Eq(x - 2, 0)) @@ -53,9 +63,9 @@ class TestDomain(unittest.TestCase): Polyhedron(1) def test_disjoint(self): - self.assertEqual(self.square1.disjoint(), self.disjoint) - self.assertEqual(self.empty.disjoint(), Empty) - self.assertEqual(self.universe.disjoint(), self.universe) + self.assertEqual(self.square1.make_disjoint(), self.disjoint) + self.assertEqual(self.empty.make_disjoint(), Empty) + self.assertEqual(self.universe.make_disjoint(), self.universe) def test_isempty(self): self.assertFalse(self.square1.isempty()) @@ -116,13 +126,15 @@ class TestDomain(unittest.TestCase): self.assertEqual(self.empty.project([]), Empty) def test_sample(self): - self.assertEqual(self.square6.sample(), {Symbol('x'): 1, Symbol('y'): 3}) + self.assertEqual(self.square6.sample(), + {Symbol('x'): 1, Symbol('y'): 3}) with self.assertRaises(ValueError): self.empty.sample() self.assertEqual(self.universe.sample(), {}) def test_intersection(self): - self.assertEqual(self.square1.intersection(self.square2), self.intersection) + self.assertEqual(self.square1.intersection(self.square2), + self.intersection) def test_and(self): self.assertEqual(self.square2 & self.square1, self.intersection) @@ -151,7 +163,8 @@ class TestDomain(unittest.TestCase): def test_difference(self): self.assertEqual(self.square2 - self.square1, self.difference1) - self.assertEqual(Polyhedron(self.square2 - self.square1), self.difference2) + self.assertEqual(Polyhedron(self.square2 - self.square1), + self.difference2) self.assertEqual(self.square2 - self.square2, Empty) self.assertEqual(self.universe - self.universe, Empty)