Implementation of Symbol.sortkey()
[linpy.git] / pypol / tests / test_domains.py
index f0f241f..e9dd1cd 100644 (file)
@@ -1,7 +1,7 @@
 import unittest
 
 from ..domains import *
 import unittest
 
 from ..domains import *
-from ..linexprs import symbols
+from ..linexprs import Symbol, symbols
 from ..polyhedra import *
 
 
 from ..polyhedra import *
 
 
@@ -19,8 +19,9 @@ class TestDomain(unittest.TestCase):
         self.universe = Polyhedron([])
         self.empty = Empty
         self.disjoint = And(Ge(x, 0), Ge(-x + 2, 0), Ge(y, 0), Ge(-y + 2, 0))
         self.universe = Polyhedron([])
         self.empty = Empty
         self.disjoint = And(Ge(x, 0), Ge(-x + 2, 0), Ge(y, 0), Ge(-y + 2, 0))
-        self.compliment = 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.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.sample = And(Eq(y - 3, 0), Eq(x - 1, 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.sample = And(Eq(y - 3, 0), Eq(x - 1, 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)))
@@ -51,8 +52,8 @@ class TestDomain(unittest.TestCase):
         self.assertFalse(self.unbound_poly.isbounded())
 
     def test_eq(self):
         self.assertFalse(self.unbound_poly.isbounded())
 
     def test_eq(self):
-        self.assertTrue(self.square1.__eq__(self.square1))
-        self.assertFalse(self.square1.__eq__(self.square2))
+        self.assertTrue(self.square1 == self.square1)
+        self.assertFalse(self.square1 == self.square2)
 
     def test_isdisjoint(self):
         self.assertFalse(self.square1.isdisjoint(self.square2))
 
     def test_isdisjoint(self):
         self.assertFalse(self.square1.isdisjoint(self.square2))
@@ -63,20 +64,25 @@ class TestDomain(unittest.TestCase):
         self.assertFalse(self.square1.issubset(self.square2))
 
     def test_le(self):
         self.assertFalse(self.square1.issubset(self.square2))
 
     def test_le(self):
-        self.assertTrue(self.square4.__le__(self.square3))
-        self.assertFalse(self.square3.__le__(self.square4))
+        self.assertTrue(self.square4 <= self.square3)
+        self.assertFalse(self.square3 <= self.square4)
 
     def test_lt(self):
 
     def test_lt(self):
-        self.assertTrue(self.square4.__lt__(self.square3))
-        self.assertFalse(self.square3.__lt__(self.square4))
+        self.assertTrue(self.square4 < self.square3)
+        self.assertFalse(self.square3 < self.square4)
 
 
-    def test_compliment(self):
-        self.assertEqual(~self.square1, self.compliment)
+    def test_complement(self):
+        self.assertEqual(~self.square1, self.complement)
 
     def test_polyhedral_hull(self):
         self.assertEqual(self.square1.polyhedral_hull(), self.hull)
 
 
     def test_polyhedral_hull(self):
         self.assertEqual(self.square1.polyhedral_hull(), self.hull)
 
-    @unittest.expectedFailure
+    def test_project_out(self):
+        self.assertEqual(self.square1.project_out(symbols('x')), self.dropped)
+        self.assertEqual(self.square1.project_out(symbols('x y')), self.universe)
+        self.assertEqual(self.universe.project_out([]), self.universe)
+        self.assertEqual(self.empty.project_out([]), Empty)
+
     def test_simplify(self):
         self.assertEqual(self.universe.simplify(), self.universe)
         self.assertEqual(self.empty.simplify(), Empty)
     def test_simplify(self):
         self.assertEqual(self.universe.simplify(), self.universe)
         self.assertEqual(self.empty.simplify(), Empty)
@@ -96,10 +102,10 @@ class TestDomain(unittest.TestCase):
         self.assertEqual(self.square1.union(self.square2), self.union)
 
     def test_or(self):
         self.assertEqual(self.square1.union(self.square2), self.union)
 
     def test_or(self):
-        self.assertEqual(self.square1.__or__(self.square2), self.union)
+        self.assertEqual(self.square1 | self.square2, self.union)
 
     def test_add(self):
 
     def test_add(self):
-        self.assertEqual(self.square2.__add__(self.square1), self.sum1)
+        self.assertEqual(self.square2 + self.square1, self.sum1)
         self.assertEqual(Polyhedron(self.square1 + self.square2), self.sum2)
 
     def test_difference(self):
         self.assertEqual(Polyhedron(self.square1 + self.square2), self.sum2)
 
     def test_difference(self):