X-Git-Url: https://svn.cri.ensmp.fr/git/linpy.git/blobdiff_plain/3f3ec5755dc4b96250b8bd09be9bede967d7203d..d585b06ccf67b2837519f4b48c6800dcdb924d9d:/linpy/tests/test_domains.py diff --git a/linpy/tests/test_domains.py b/linpy/tests/test_domains.py index 0955a09..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)) @@ -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)