X-Git-Url: https://scm.cri.ensmp.fr/git/linpy.git/blobdiff_plain/7b93cea1daf2889e9ee10ca9c22a1b5124404937..d585b06ccf67b2837519f4b48c6800dcdb924d9d:/linpy/tests/test_domains.py diff --git a/linpy/tests/test_domains.py b/linpy/tests/test_domains.py index 4b8c5ea..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()) @@ -115,18 +125,16 @@ class TestDomain(unittest.TestCase): self.assertEqual(self.universe.project([]), self.universe) self.assertEqual(self.empty.project([]), Empty) - def test_simplify(self): - self.assertEqual(self.universe.simplify(), self.universe) - self.assertEqual(self.empty.simplify(), 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) @@ -155,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) @@ -168,8 +177,3 @@ class TestDomain(unittest.TestCase): self.assertEqual(self.square1.lexmax(), self.lexmax) self.assertEqual(self.universe.lexmax(), self.universe) self.assertEqual(self.empty.lexmax(), Empty) - - def test_involves_vars(self): - self.assertTrue(self.square1.involves_vars(symbols('x y'))) - self.assertFalse(self.empty.involves_vars(symbols('x'))) - self.assertFalse(self.universe.involves_vars(symbols('x')))