1 /* Test Grid::relation_with(g).
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 // Empty grid and point.
29 bool
test01()30 test01() {
31   Variable A(0);
32 
33   Grid gr(2, EMPTY);
34   print_congruences(gr, "*** gr ***");
35 
36   bool ok = (gr.relation_with(grid_point(A)) == Poly_Gen_Relation::nothing());
37 
38   return ok;
39 }
40 
41 // Universe and point.
42 bool
test02()43 test02() {
44   Variable A(0);
45 
46   Grid gr(2);
47   print_congruences(gr, "*** gr ***");
48 
49   bool ok = (gr.relation_with(grid_point(A)) == Poly_Gen_Relation::subsumes());
50 
51   return ok;
52 }
53 
54 // Lined grid and point.
55 bool
test03()56 test03() {
57   Variable A(0);
58   Variable B(1);
59 
60   Grid_Generator_System gs;
61   gs.insert(grid_point());
62   gs.insert(grid_point(B));
63   gs.insert(grid_line(A));
64 
65   Grid gr(gs);
66   print_congruences(gr, "*** gr ***");
67 
68   bool ok
69     = (gr.relation_with(grid_point(A + B)) == Poly_Gen_Relation::subsumes());
70 
71   return ok;
72 }
73 
74 // Equality and point.
75 bool
test04()76 test04() {
77   Variable A(0);
78 
79   Grid gr(2);
80   gr.add_constraint(A == 0);
81   print_congruences(gr, "*** gr ***");
82 
83   bool ok
84     = (gr.relation_with(grid_point(2*A)) == Poly_Gen_Relation::nothing());
85 
86   return ok;
87 }
88 
89 // Congruences and points.
90 bool
test05()91 test05() {
92   Variable A(0);
93   Variable B(1);
94 
95   Grid gr(2);
96   gr.add_congruence((A - B %= 1) / 2);
97   gr.add_congruence((A %= 1) / 3);
98   print_congruences(gr, "*** gr ***");
99 
100   bool ok = (gr.relation_with(grid_point()) == Poly_Gen_Relation::nothing()
101              && gr.relation_with(grid_point(-B)) == Poly_Gen_Relation::nothing());
102 
103   return ok;
104 }
105 
106 // Congruence and parameter.
107 bool
test06()108 test06() {
109   Variable A(0);
110 
111   Grid gr(2);
112   gr.add_congruence(2*A %= 0);
113   print_congruences(gr, "*** gr ***");
114 
115   bool ok
116     = (gr.relation_with(parameter(A, 2)) == Poly_Gen_Relation::subsumes());
117 
118   return ok;
119 }
120 
121 // Congruence and line.
122 bool
test07()123 test07() {
124   Variable A(0);
125 
126   Grid gr(2);
127   gr.add_congruence(2*A %= 0);
128   print_congruences(gr, "*** gr ***");
129 
130   bool ok = (gr.relation_with(grid_line(A)) == Poly_Gen_Relation::nothing());
131 
132   return ok;
133 }
134 
135 // Space dimension exception.
136 bool
test08()137 test08() {
138   Variable A(0);
139   Variable C(2);
140 
141   Grid gr(2);
142 
143   try {
144     gr.relation_with(grid_line(A + C));
145   }
146   catch (const std::invalid_argument& e) {
147     nout << "invalid_argument: " << e.what() << endl;
148     return true;
149   }
150   catch (...) {
151   }
152   return false;
153 }
154 
155 // Zero dimension universe grid.
156 bool
test09()157 test09() {
158   Grid gr(0);
159 
160   bool ok = (gr.relation_with(grid_point()) == Poly_Gen_Relation::subsumes());
161 
162   return ok;
163 }
164 
165 // Empty grid and point.
166 bool
test10()167 test10() {
168   Variable A(0);
169 
170   Grid gr(2, EMPTY);
171   print_congruences(gr, "*** gr ***");
172 
173   bool ok = (gr.relation_with(point(A)) == Poly_Gen_Relation::nothing());
174 
175   return ok;
176 }
177 
178 // Universe and point.
179 bool
test11()180 test11() {
181   Variable A(0);
182 
183   Grid gr(2);
184   print_congruences(gr, "*** gr ***");
185 
186   bool ok = (gr.relation_with(point(A)) == Poly_Gen_Relation::subsumes());
187 
188   return ok;
189 }
190 
191 // Lined grid and point.
192 bool
test12()193 test12() {
194   Variable A(0);
195   Variable B(1);
196 
197   Grid_Generator_System gs;
198   gs.insert(grid_point());
199   gs.insert(grid_point(B));
200   gs.insert(grid_line(A));
201 
202   Grid gr(gs);
203   print_congruences(gr, "*** gr ***");
204 
205   bool ok
206     = (gr.relation_with(point(A + B)) == Poly_Gen_Relation::subsumes());
207 
208   return ok;
209 }
210 
211 // Equality and point.
212 bool
test13()213 test13() {
214   Variable A(0);
215 
216   Grid gr(2);
217   gr.add_constraint(A == 0);
218   print_congruences(gr, "*** gr ***");
219 
220   bool ok
221     = (gr.relation_with(point(2*A)) == Poly_Gen_Relation::nothing());
222 
223   return ok;
224 }
225 
226 // Congruences and points.
227 bool
test14()228 test14() {
229   Variable A(0);
230   Variable B(1);
231 
232   Grid gr(2);
233   gr.add_congruence((A - B %= 1) / 2);
234   gr.add_congruence((A %= 1) / 3);
235   print_congruences(gr, "*** gr ***");
236 
237   bool ok = (gr.relation_with(point()) == Poly_Gen_Relation::nothing()
238              && gr.relation_with(point(-B)) == Poly_Gen_Relation::nothing());
239 
240   return ok;
241 }
242 
243 // Congruence and parameter.
244 bool
test15()245 test15() {
246   Variable A(0);
247 
248   Grid gr(2);
249   gr.add_congruence(2*A %= 0);
250   print_congruences(gr, "*** gr ***");
251 
252   bool ok
253     = (gr.relation_with(ray(A)) == Poly_Gen_Relation::nothing());
254 
255   return ok;
256 }
257 
258 // Congruence and line.
259 bool
test16()260 test16() {
261   Variable A(0);
262 
263   Grid gr(2);
264   gr.add_congruence(2*A %= 0);
265   print_congruences(gr, "*** gr ***");
266 
267   bool ok = (gr.relation_with(line(A)) == Poly_Gen_Relation::nothing());
268 
269   return ok;
270 }
271 
272 // Space dimension exception.
273 bool
test17()274 test17() {
275   Variable A(0);
276   Variable C(2);
277 
278   Grid gr(2);
279 
280   try {
281     gr.relation_with(line(A + C));
282   }
283   catch (const std::invalid_argument& e) {
284     nout << "invalid_argument: " << e.what() << endl;
285     return true;
286   }
287   catch (...) {
288   }
289   return false;
290 }
291 
292 // Zero dimension universe grid.
293 bool
test18()294 test18() {
295   Grid gr(0);
296 
297   bool ok = (gr.relation_with(point()) == Poly_Gen_Relation::subsumes());
298 
299   return ok;
300 }
301 
302 // Lined grid and line.
303 bool
test19()304 test19() {
305   Variable A(0);
306   Variable B(1);
307 
308   Grid_Generator_System gs;
309   gs.insert(grid_point());
310   gs.insert(grid_point(B));
311   gs.insert(grid_line(A));
312 
313   Grid gr(gs);
314   print_congruences(gr, "*** gr ***");
315 
316   bool ok
317     = (gr.relation_with(line(A + B)) == Poly_Gen_Relation::nothing()
318        && gr.relation_with(line(A)) == Poly_Gen_Relation::subsumes());
319 
320   return ok;
321 }
322 
323 // Lined grid and line.
324 bool
test20()325 test20() {
326   Variable A(0);
327   Variable B(1);
328 
329   Grid_Generator_System gs;
330   gs.insert(grid_point());
331   gs.insert(grid_point(B));
332   gs.insert(grid_line(A));
333 
334   Grid gr(gs);
335   print_congruences(gr, "*** gr ***");
336 
337   bool ok
338     = (gr.relation_with(closure_point(A + B)) == Poly_Gen_Relation::subsumes()
339        && gr.relation_with(closure_point(A)) == Poly_Gen_Relation::subsumes());
340 
341   return ok;
342 }
343 
344 } // namespace
345 
346 BEGIN_MAIN
347   DO_TEST(test01);
348   DO_TEST(test02);
349   DO_TEST(test03);
350   DO_TEST(test04);
351   DO_TEST(test05);
352   DO_TEST(test06);
353   DO_TEST(test07);
354   DO_TEST(test08);
355   DO_TEST(test09);
356   DO_TEST(test10);
357   DO_TEST(test11);
358   DO_TEST(test12);
359   DO_TEST(test13);
360   DO_TEST(test14);
361   DO_TEST(test15);
362   DO_TEST(test16);
363   DO_TEST(test17);
364   DO_TEST(test18);
365   DO_TEST(test19);
366   DO_TEST(test20);
367 END_MAIN
368