1 /* Test Grid::relation_with(cg).
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 namespace {
27
28 // A proper congruence and a disjoint point.
29 bool
test01()30 test01() {
31 Variable A(0);
32 Variable B(1);
33
34 Grid gr(2, EMPTY);
35 gr.add_grid_generator(grid_point(A - B));
36 print_generators(gr, "*** gr ***");
37
38 bool ok
39 = gr.relation_with((A - B %= 1) / 2) == Poly_Con_Relation::is_disjoint();
40
41 return ok;
42 }
43
44 // A proper congruence and an included grid.
45 bool
test02()46 test02() {
47 Variable A(0);
48
49 Grid gr(1, EMPTY);
50 gr.add_grid_generator(grid_point());
51 gr.add_grid_generator(grid_point(4*A));
52 print_generators(gr, "*** gr ***");
53
54 bool ok
55 = (gr.relation_with((A %= 0) / 2) == Poly_Con_Relation::is_included());
56
57 return ok;
58 }
59
60 // A proper congruence and an intersected grid.
61 bool
test03()62 test03() {
63 Variable A(0);
64 Variable C(2);
65
66 Grid gr(3, EMPTY);
67 gr.add_grid_generator(grid_point());
68 gr.add_grid_generator(grid_point(2*A));
69 print_generators(gr, "*** gr ***");
70
71 bool ok
72 = (gr.relation_with((A + C %= 0) / 3)
73 == Poly_Con_Relation::strictly_intersects());
74
75 return ok;
76 }
77
78 // A line and equalities.
79 bool
test04()80 test04() {
81 Variable A(0);
82 Variable B(1);
83
84 Grid gr(2, EMPTY);
85 gr.add_grid_generator(grid_point());
86 gr.add_grid_generator(grid_line(A));
87 print_generators(gr, "*** gr ***");
88
89 bool ok
90 = (gr.relation_with((A + 0*B %= 0) / 0)
91 == Poly_Con_Relation::strictly_intersects()
92 && gr.relation_with((B + 0*B %= -2) / 0)
93 == Poly_Con_Relation::is_disjoint());
94
95 return ok;
96 }
97
98 // Inclusion of a point grid.
99 bool
test05()100 test05() {
101 Variable A(0);
102 Variable B(1);
103
104 Grid gr(2, EMPTY);
105 gr.add_grid_generator(grid_point(A + B));
106 print_generators(gr, "*** gr ***");
107
108 bool ok
109 = (gr.relation_with(A + 0*B %= 0) == Poly_Con_Relation::is_included());
110
111 return ok;
112 }
113
114 // Empty grid.
115
116 bool
test06()117 test06() {
118 Variable B(1);
119
120 Grid gr(2, EMPTY);
121 print_generators(gr, "*** gr ***");
122
123 bool ok = (gr.relation_with((B %= 0) / 2)
124 == (Poly_Con_Relation::is_included()
125 && Poly_Con_Relation::is_disjoint()
126 && Poly_Con_Relation::saturates()));
127
128 return ok;
129 }
130
131 // Zero dimension universe grid.
132 bool
test07()133 test07() {
134 Grid gr;
135 print_generators(gr, "*** gr ***");
136
137 bool ok
138 = (// Trivially false congruence.
139 gr.relation_with(Congruence::zero_dim_false())
140 == Poly_Con_Relation::is_disjoint()
141 // False congruence.
142 && gr.relation_with((Linear_Expression(5) %= 1) / 3)
143 == Poly_Con_Relation::is_disjoint()
144 // False equality.
145 && gr.relation_with((Linear_Expression(1) %= 0) / 0)
146 == Poly_Con_Relation::is_disjoint()
147 // Proper congruence.
148 && gr.relation_with(Linear_Expression(1) %= 1)
149 == (Poly_Con_Relation::is_included()
150 && Poly_Con_Relation::saturates())
151 // Proper congruence.
152 && gr.relation_with((Linear_Expression(5) %= 1) / 4)
153 == (Poly_Con_Relation::is_included()
154 && Poly_Con_Relation::saturates())
155 // Equality.
156 && gr.relation_with(Linear_Expression(1) %= 1)
157 == (Poly_Con_Relation::is_included()
158 && Poly_Con_Relation::saturates())
159 // Integrality congruence.
160 && gr.relation_with(Congruence::zero_dim_integrality())
161 == (Poly_Con_Relation::is_included()
162 && Poly_Con_Relation::saturates()));
163
164 return ok;
165 }
166
167 // A congruence and a disjoint grid.
168 bool
test08()169 test08() {
170 Variable A(0);
171 Variable B(1);
172
173 Grid gr(2, EMPTY);
174 gr.add_grid_generator(grid_point());
175 gr.add_grid_generator(grid_point(2*A + 5*B));
176 print_generators(gr, "*** gr ***");
177
178 bool ok
179 = (gr.relation_with((5*A - 2*B == 1) / 0)
180 == Poly_Con_Relation::is_disjoint());
181
182 return ok;
183 }
184
185 // A congruence and a disjoint grid.
186 bool
test09()187 test09() {
188 Variable A(0);
189 Variable D(3);
190
191 Grid gr(4);
192 print_generators(gr, "*** gr ***");
193
194 bool ok
195 = (gr.relation_with(A - 2*D %= 0)
196 == Poly_Con_Relation::strictly_intersects());
197
198 return ok;
199 }
200
201 // Point with a divisor that is greater than zero.
202 bool
test10()203 test10() {
204 Variable A(0);
205
206 Grid gr(3, EMPTY);
207 gr.add_grid_generator(grid_point(A, 2));
208 print_generators(gr, "*** gr ***");
209
210 bool ok
211 = (gr.relation_with((A %= 3) / 0)
212 == Poly_Con_Relation::is_disjoint()
213 && gr.relation_with((2*A %= 1) / 0)
214 == (Poly_Con_Relation::is_included()
215 && Poly_Con_Relation::saturates())
216 && gr.relation_with(2*A %= 1)
217 == Poly_Con_Relation::is_included());
218
219 return ok;
220 }
221
222 // Grid with a divisor that is greater than zero: separate spaces.
223 bool
test11()224 test11() {
225 Variable A(0);
226
227 Grid gr(1, EMPTY);
228 gr.add_grid_generator(grid_point());
229 gr.add_grid_generator(parameter(A, 5));
230 print_generators(gr, "*** gr ***");
231
232 bool ok = (gr.relation_with((10*A %= 1) / 0)
233 == Poly_Con_Relation::is_disjoint());
234
235 return ok;
236 }
237
238 // Grid with a divisor that is greater than zero: inclusion.
239 bool
test12()240 test12() {
241 Variable A(0);
242
243 Grid gr(1, EMPTY);
244 gr.add_grid_generator(grid_point());
245 gr.add_grid_generator(parameter(A, 5));
246 print_generators(gr, "*** gr ***");
247
248 bool ok
249 = (gr.relation_with((10*A %= 0) / 1)
250 == Poly_Con_Relation::is_included());
251
252 return ok;
253 }
254
255 // Grid with a divisor that is greater than zero: strict intersection.
256 bool
test13()257 test13() {
258 Variable A(0);
259
260 Grid gr(1, EMPTY);
261 gr.add_grid_generator(grid_point());
262 gr.add_grid_generator(parameter(A, 5));
263 print_generators(gr, "*** gr ***");
264
265 bool ok
266 = (gr.relation_with(A %= 0)
267 == Poly_Con_Relation::strictly_intersects());
268
269 return ok;
270 }
271
272 // Space dimension exception.
273 bool
test14()274 test14() {
275 Variable A(0);
276 Variable B(1);
277
278 Grid gr(1);
279 print_generators(gr, "*** gr ***");
280
281 try {
282 gr.relation_with(A + B %= 0);
283 }
284 catch (const std::invalid_argument& e) {
285 nout << "invalid_argument: " << e.what() << endl;
286 return true;
287 }
288 catch (...) {
289 }
290 return false;
291 }
292
293 // Empty grid, where updating finds the grid empty.
294 bool
test15()295 test15() {
296 Variable A(0);
297 Variable B(1);
298
299 Grid gr(2);
300 gr.add_constraint(A == 1);
301 gr.add_constraint(A == 2);
302 print_generators(gr, "*** gr ***");
303
304 bool ok
305 = (gr.relation_with((B %= 0) / 2)
306 == (Poly_Con_Relation::is_included()
307 && Poly_Con_Relation::is_disjoint()
308 && Poly_Con_Relation::saturates()));
309
310 return ok;
311 }
312
313 // Generators that require the relation_with(cg) GCD calculation.
314 bool
test16()315 test16() {
316 Variable A(0);
317
318 Grid gr(1, EMPTY);
319 gr.add_grid_generator(grid_point(A));
320 gr.add_grid_generator(grid_point(3*A));
321 print_generators(gr, "*** gr ***");
322
323 bool ok
324 = (gr.relation_with((A %= 0) / 4)
325 == Poly_Con_Relation::is_disjoint());
326
327 return ok;
328 }
329
330 // Strict intersection, where generators require the relation_with(cg)
331 // GCD calculation.
332 bool
test17()333 test17() {
334 Variable A(0);
335
336 Grid gr(1, EMPTY);
337 gr.add_grid_generator(grid_point(3*A));
338 gr.add_grid_generator(grid_point(6*A));
339 print_generators(gr, "*** gr ***");
340
341 bool ok
342 = (gr.relation_with((A %= 0) / 8)
343 == Poly_Con_Relation::strictly_intersects());
344
345 return ok;
346 }
347
348 // Strict intersection, where generators require the relation_with(cg)
349 // GCD calculation, with a parameter.
350 bool
test18()351 test18() {
352 Variable A(0);
353
354 Grid gr(1, EMPTY);
355 gr.add_grid_generator(grid_point(3*A));
356 gr.add_grid_generator(parameter(3*A));
357 print_generators(gr, "*** gr ***");
358
359 bool ok
360 = (gr.relation_with((A %= 0) / 8)
361 == Poly_Con_Relation::strictly_intersects());
362
363 return ok;
364 }
365
366 // generators are not up-to-date and the grid is empty.
367 bool
test19()368 test19() {
369 Variable A(0);
370
371 Grid gr(1);
372 gr.add_congruence((A %= 0) / 2);
373 gr.add_congruence((A %= 1) / 2);
374 print_congruences(gr, "*** gr ***");
375
376 bool ok
377 = (gr.relation_with((A %= 0) / 8)
378 == (Poly_Con_Relation::is_included()
379 && Poly_Con_Relation::is_disjoint()
380 && Poly_Con_Relation::saturates()));
381
382 return ok;
383 }
384
385 // Grid strictly intersects where the inhomogeneous term is non-zero.
386 bool
test20()387 test20() {
388 Variable A(0);
389
390 Grid gr(1);
391 gr.add_congruence((A %= 0) / 1);
392 print_congruences(gr, "*** gr ***");
393
394 bool ok
395 = (gr.relation_with((2*A %= 1) / 3)
396 == (Poly_Con_Relation::strictly_intersects()));
397
398 return ok;
399 }
400
401 } // namespace
402
403 BEGIN_MAIN
404 DO_TEST(test01);
405 DO_TEST(test02);
406 DO_TEST(test03);
407 DO_TEST(test04);
408 DO_TEST(test05);
409 DO_TEST(test06);
410 DO_TEST(test07);
411 DO_TEST(test08);
412 DO_TEST(test09);
413 DO_TEST(test10);
414 DO_TEST(test11);
415 DO_TEST(test12);
416 DO_TEST(test13);
417 DO_TEST(test14);
418 DO_TEST(test15);
419 DO_TEST(test16);
420 DO_TEST(test17);
421 DO_TEST(test18);
422 DO_TEST(test19);
423 DO_TEST(test20);
424 END_MAIN
425