1 /* Test Pointset_Powerset<Grid>.
2 Copyright (C) 2001-2010 Roberto Bagnara <bagnara@cs.unipr.it>
3 Copyright (C) 2010-2016 BUGSENG srl (http://bugseng.com)
4
5 This file is part of the Parma Polyhedra Library (PPL).
6
7 The PPL is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11
12 The PPL is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software Foundation,
19 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA.
20
21 For the most up-to-date information see the Parma Polyhedra Library
22 site: http://bugseng.com/products/ppl/ . */
23
24 #include "ppl_test.hh"
25
26
27 bool
test01()28 test01() {
29 Variable x(0);
30 Variable y(1);
31
32 Grid p(2);
33 p.add_congruence(x %= 0);
34 p.add_congruence(y %= 0);
35
36 Pointset_Powerset<Grid> ps(2, EMPTY);
37 ps.add_disjunct(p);
38
39 Grid q(2);
40 q.add_congruence((x %= 1) / 3);
41 q.add_congruence((y %= 1) / 2);
42
43 Pointset_Powerset<Grid> qs(2, EMPTY);
44 qs.add_disjunct(q);
45
46 print_congruences(ps, "*** ps ***");
47 print_congruences(qs, "*** qs ***");
48
49 ps.difference_assign(qs);
50
51 Grid known_gr1(2);
52 known_gr1.add_congruence((x %= 0) / 1);
53 known_gr1.add_congruence((y %= 0) / 2);
54
55 Grid known_gr2(2);
56 known_gr2.add_congruence((x %= 2) / 3);
57 known_gr2.add_congruence((y %= 1) / 2);
58
59 Grid known_gr3(2);
60 known_gr3.add_congruence((x %= 0) / 3);
61 known_gr3.add_congruence((y %= 1) / 2);
62
63 Pointset_Powerset<Grid> known_qs(2, EMPTY);
64 known_qs.add_disjunct(known_gr1);
65 known_qs.add_disjunct(known_gr2);
66 known_qs.add_disjunct(known_gr3);
67
68 bool ok = (ps == known_qs);
69 print_congruences(ps, "*** ps.difference(qs) ***");
70
71 return ok;
72 }
73
74 bool
test02()75 test02() {
76 Variable x(0);
77 Variable y(1);
78
79 Grid p(2);
80 p.add_congruence(x %= 0);
81
82 Pointset_Powerset<Grid> ps(2, EMPTY);
83 ps.add_disjunct(p);
84
85 Grid q(2);
86 q.add_constraint(x == 1);
87
88 Pointset_Powerset<Grid> qs(2, EMPTY);
89 qs.add_disjunct(q);
90
91 print_congruences(ps, "*** ps ***");
92 print_congruences(qs, "*** qs ***");
93
94 ps.difference_assign(qs);
95 print_congruences(ps, "*** ps.difference(qs) ***");
96
97 Grid known_gr(2);
98 known_gr.add_congruence((x %= 0) / 1);
99
100 Pointset_Powerset<Grid>::iterator i = ps.begin();
101 return i->pointset() == known_gr;
102 }
103
104 bool
test03()105 test03() {
106 Variable x(0);
107 Variable y(1);
108
109 Grid p(2);
110 p.add_constraint(x == 0);
111
112 Pointset_Powerset<Grid> ps(2, EMPTY);
113 ps.add_disjunct(p);
114
115 Grid q(2);
116 q.add_congruence(x %= 1);
117
118 Pointset_Powerset<Grid> qs(2, EMPTY);
119 qs.add_disjunct(q);
120
121 print_congruences(ps, "*** ps ***");
122 print_congruences(qs, "*** qs ***");
123
124 ps.difference_assign(qs);
125 print_congruences(ps, "*** ps.difference(qs) ***");
126
127 return ps.begin() == ps.end();
128 }
129
130 bool
test04()131 test04() {
132 Variable x(0);
133 Variable y(1);
134
135 Grid p(2);
136 p.add_congruence(x %= 0);
137
138 Pointset_Powerset<Grid> ps(2, EMPTY);
139 ps.add_disjunct(p);
140
141 Grid q(2);
142 q.add_congruence(y %= 0);
143
144 Pointset_Powerset<Grid> qs(2, EMPTY);
145 qs.add_disjunct(q);
146
147 print_congruences(ps, "*** ps ***");
148 print_congruences(qs, "*** qs ***");
149
150 ps.difference_assign(qs);
151 print_congruences(ps, "*** ps.difference(qs) ***");
152
153 Grid known_gr(2);
154 known_gr.add_congruence((x %= 0) / 1);
155
156 Pointset_Powerset<Grid>::iterator i = ps.begin();
157 return i->pointset() == known_gr;
158 }
159
160 bool
test05()161 test05() {
162 Variable x(0);
163 Variable y(1);
164
165 Pointset_Powerset<Grid> ps(2, EMPTY);
166
167 Grid q(2);
168 q.add_congruence(y %= 0);
169
170 Pointset_Powerset<Grid> qs(2, EMPTY);
171 qs.add_disjunct(q);
172
173 print_congruences(ps, "*** ps ***");
174 print_congruences(qs, "*** qs ***");
175
176 ps.difference_assign(qs);
177 print_congruences(ps, "*** ps.difference(qs) ***");
178
179 return ps.begin() == ps.end();
180 }
181
182 bool
test06()183 test06() {
184 Variable x(0);
185 Variable y(1);
186
187 Grid p(2);
188 p.add_congruence(y %= 0);
189
190 Pointset_Powerset<Grid> ps(2, EMPTY);
191 ps.add_disjunct(p);
192
193 Pointset_Powerset<Grid> qs(2, EMPTY);
194
195 print_congruences(ps, "*** ps ***");
196 print_congruences(qs, "*** qs ***");
197
198 ps.difference_assign(qs);
199 print_congruences(ps, "*** ps.difference(qs) ***");
200
201 Grid known_gr(p);
202
203 Pointset_Powerset<Grid>::iterator i = ps.begin();
204 return i->pointset() == known_gr;
205 }
206
207 bool
test07()208 test07() {
209 Variable x(0);
210 Variable y(1);
211
212 Grid p(2);
213 p.add_congruence(y %= 0);
214
215 Pointset_Powerset<Grid> ps(2, EMPTY);
216 ps.add_disjunct(p);
217
218 Pointset_Powerset<Grid> qs(2, EMPTY);
219
220 print_congruences(ps, "*** ps ***");
221 print_congruences(qs, "*** qs ***");
222
223 ps.difference_assign(qs);
224 print_congruences(ps, "*** ps.difference(qs) ***");
225
226 Grid known_gr(p);
227
228 Pointset_Powerset<Grid>::iterator i = ps.begin();
229 return i->pointset() == known_gr;
230 }
231
232 bool
test08()233 test08() {
234 Variable x(0);
235 Variable y(1);
236
237 Grid p(2);
238 p.add_congruence(x %= 0);
239 p.add_congruence(y %= 0);
240
241 Pointset_Powerset<Grid> ps(2, EMPTY);
242 ps.add_disjunct(p);
243
244 Grid q(2);
245 q.add_congruence((x %= 1) / 3);
246 q.add_congruence((y %= 1) / 2);
247
248 Pointset_Powerset<Grid> qs(2, EMPTY);
249 qs.add_disjunct(q);
250
251 print_congruences(ps, "*** ps ***");
252 print_congruences(qs, "*** qs ***");
253
254 ps.difference_assign(qs);
255
256 Grid known_gr1(2);
257 known_gr1.add_congruence((x %= 0) / 1);
258 known_gr1.add_congruence((y %= 0) / 2);
259
260 Grid known_gr2(2);
261 known_gr2.add_congruence((x %= 2) / 3);
262 known_gr2.add_congruence((y %= 1) / 2);
263
264 Grid known_gr3(2);
265 known_gr3.add_congruence((x %= 0) / 3);
266 known_gr3.add_congruence((y %= 1) / 2);
267
268 Pointset_Powerset<Grid> known_qs(2, EMPTY);
269 known_qs.add_disjunct(known_gr1);
270 known_qs.add_disjunct(known_gr2);
271 known_qs.add_disjunct(known_gr3);
272
273 bool ok = (ps == known_qs);
274 print_congruences(ps, "*** ps.difference(qs) ***");
275
276 return ok;
277 }
278
279 bool
test09()280 test09() {
281 Variable x(0);
282 Variable y(1);
283
284 Grid p(2);
285 p.add_constraint(x == 0);
286
287 Pointset_Powerset<Grid> ps(2, EMPTY);
288 ps.add_disjunct(p);
289
290 Grid q(2);
291 q.add_congruence((x %= 0) / 0);
292
293 Pointset_Powerset<Grid> qs(2, EMPTY);
294 qs.add_disjunct(q);
295
296 print_congruences(ps, "*** ps ***");
297 print_congruences(qs, "*** qs ***");
298
299 ps.difference_assign(qs);
300 print_congruences(ps, "*** ps.difference(qs) ***");
301
302 return ps.is_empty();
303 }
304
305 BEGIN_MAIN
306 DO_TEST(test01);
307 DO_TEST(test02);
308 DO_TEST(test03);
309 DO_TEST(test04);
310 DO_TEST(test05);
311 DO_TEST(test06);
312 DO_TEST(test07);
313 DO_TEST(test08);
314 DO_TEST(test09);
315 END_MAIN
316