27d9014484cd1064f996c9bf551872867d7380d9
4 #from ..domains import *
5 #from ..linexprs import symbols
6 #from ..polyhedra import *
9 class TestDomain(unittest
.TestCase
):
13 self
.square1
= Polyhedron(inequalities
=[x
, 2 - x
, y
, 2 - y
])
14 self
.square2
= Polyhedron(inequalities
=[x
- 1, 3 - x
, y
- 1, 3 - y
]) #correct representation
15 self
.square3
= Polyhedron(inequalities
=[x
, 3 - x
, y
, 3 - y
])
16 self
.square4
= Polyhedron(inequalities
=[x
- 1, 2 - x
, y
- 1, 2 - y
])
17 self
.square5
= Polyhedron(inequalities
=[x
, 3 - x
, y
])
18 self
.square6
= Polyhedron(inequalities
=[x
- 3, 6 - x
, y
- 3, 6 -y
])
19 self
.universe
= Polyhedron([])
20 self
.disjoint
= And(Ge(x
, 0), Ge(-x
+ 2, 0), Ge(y
, 0), Ge(-y
+ 2, 0))
21 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)))
22 self
.hull
= And(Ge(x
, 0), Ge(-x
+ 2, 0), Ge(y
, 0), Ge(-y
+ 2, 0))
23 self
.intersection
= And(Ge(x
- 1, 0), Ge(-x
+ 2, 0), Ge(y
- 1, 0), Ge(-y
+ 2, 0))
24 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)))
25 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)))
26 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))
27 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)))
28 self
.difference2
= And(Ge(x
+ y
- 4, 0), Ge(-x
+ 3, 0), Ge(-y
+ 3, 0))
29 self
.lexmin
= And(Eq(y
, 0), Eq(x
, 0))
30 self
.lexmax
= And(Eq(y
- 2, 0), Eq(x
- 2, 0))
33 with self
.assertRaises(TypeError):
36 def test_disjoint(self
):
37 self
.assertEqual(self
.square1
.disjoint(), self
.disjoint
)
39 def test_isempty(self
):
40 self
.assertFalse(self
.square1
.isempty())
42 def test_isuniverse(self
):
43 self
.assertFalse(self
.square1
.isuniverse())
44 self
.assertTrue(self
.universe
.isuniverse())
46 def test_isbounded(self
):
47 self
.assertTrue(self
.square1
.isbounded())
48 self
.assertFalse(self
.square5
.isbounded())
51 self
.assertTrue(self
.square1
.__eq__(self
.square1
))
52 self
.assertFalse(self
.square1
.__eq__(self
.square2
))
54 def test_isdisjoint(self
):
55 self
.assertFalse(self
.square1
.isdisjoint(self
.square2
))
56 self
.assertTrue(self
.square1
.isdisjoint(self
.square6
))
58 def test_issubset(self
):
59 self
.assertTrue(self
.square4
.issubset(self
.square5
))
60 self
.assertFalse(self
.square1
.issubset(self
.square2
))
63 self
.assertTrue(self
.square4
.__lt__(self
.square3
))
66 self
.assertTrue(self
.square4
.__le__(self
.square3
))
68 def test_compliment(self
):
69 self
.assertEqual(~self
.square1
, self
.compliment
)
71 def test_simplify(self
):
72 #maybe wont need this method
75 def test_polyhedral_hull(self
):
76 self
.assertEqual(self
.square1
.polyhedral_hull(), self
.hull
)
78 def test_project(self
):
79 #maybe wont need this method
82 def test_sample(self
):
85 def test_intersection(self
):
86 self
.assertEqual(self
.square1
.intersection(self
.square2
), self
.intersection
)
89 self
.assertEqual(self
.square2
& self
.square1
, self
.intersection
)
92 self
.assertEqual(self
.square1
.union(self
.square2
), self
.union
)
95 self
.assertEqual(self
.square1
.__or__(self
.square2
), self
.union
)
98 self
.assertEqual(self
.square2
.__add__(self
.square1
), self
.sum1
)
99 self
.assertEqual(Polyhedron(self
.square1
+ self
.square2
), self
.sum2
)
101 def test_difference(self
):
102 self
.assertEqual(self
.square2
- self
.square1
, self
.difference1
)
103 self
.assertEqual(Polyhedron(self
.square2
- self
.square1
), self
.difference2
)
105 def test_lexmin(self
):
106 self
.assertEqual(self
.square1
.lexmin(), self
.lexmin
)
108 def test_lexmax(self
):
109 self
.assertEqual(self
.square1
.lexmax(), self
.lexmax
)