1 /* Test Grid::is_universe().
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 // One dimension.
29 bool
test01()30 test01() {
31 Grid gr(1);
32
33 bool ok = (gr.is_universe());
34
35 print_congruences(gr, "*** gr ***");
36
37 return ok;
38 }
39
40 // Many dimensions.
41
42 bool
test02()43 test02() {
44 Grid gr(6);
45
46 bool ok = (gr.is_universe());
47
48 print_congruences(gr, "*** gr ***");
49
50 return ok;
51 }
52
53 // Zero dimension universe.
54
55 bool
test03()56 test03() {
57 Grid gr(0);
58
59 bool ok = (gr.is_universe());
60
61 print_congruences(gr, "*** gr ***");
62
63 return ok;
64 }
65
66 // Zero dimension empty.
67
68 bool
test04()69 test04() {
70 Grid gr(0, EMPTY);
71
72 bool ok = (!gr.is_universe());
73
74 print_congruences(gr, "*** gr ***");
75
76 return ok;
77 }
78
79 // Empty grid.
80
81 bool
test05()82 test05() {
83 Grid gr(2, EMPTY);
84
85 bool ok = (!gr.is_universe());
86
87 print_congruences(gr, "*** gr ***");
88
89 return ok;
90 }
91
92 // Grid of congruences.
93
94 bool
test06()95 test06() {
96 Variable A(0);
97 Variable B(1);
98 Variable C(2);
99
100 Congruence_System cgs;
101 cgs.insert((A + B + C %= 0) / 3);
102
103 Grid gr(cgs);
104
105 bool ok = (!gr.is_universe());
106
107 print_congruences(gr, "*** gr ***");
108
109 return ok;
110 }
111
112 // Universe grid of congruences.
113
114 bool
test07()115 test07() {
116 Variable C(2);
117
118 Congruence_System cgs;
119 cgs.insert((0*C %= 6) / 3);
120
121 Grid gr(cgs);
122
123 bool ok = (gr.is_universe());
124
125 print_congruences(gr, "*** gr ***");
126
127 return ok;
128 }
129
130 // Grid of generators.
131
132 bool
test08()133 test08() {
134 Variable A(0);
135 Variable E(4);
136
137 Grid_Generator_System gs;
138 gs.insert(grid_point(A + 3*E));
139
140 Grid gr(gs);
141
142 bool ok = (!gr.is_universe());
143
144 print_congruences(gr, "*** gr ***");
145
146 return ok;
147 }
148
149 // Universe grid of generators.
150 bool
test09()151 test09() {
152 Variable A(0);
153 Variable B(1);
154 Variable C(2);
155 Variable D(3);
156 Variable E(4);
157
158 Grid_Generator_System gs;
159 gs.insert(grid_point(A + 3*E));
160 gs.insert(grid_line(A));
161 gs.insert(grid_line(B));
162 gs.insert(grid_line(C));
163 gs.insert(grid_line(D));
164 gs.insert(grid_line(E));
165
166 Grid gr(gs);
167
168 bool ok = (gr.is_universe());
169
170 print_congruences(gr, "*** gr ***");
171
172 return ok;
173 }
174
175 // Minimized congruences.
176 bool
test10()177 test10() {
178 Variable A(0);
179 Variable B(1);
180 Variable C(2);
181
182 Congruence_System cgs;
183 cgs.insert((A + B + C %= 0) / 3);
184
185 Grid gr(cgs);
186
187 // Minimize the congruences.
188 gr.minimized_congruences();
189
190 bool ok = (!gr.is_universe());
191
192 print_congruences(gr, "*** gr ***");
193
194 return ok;
195 }
196
197 // Minimized universe congruences.
198 bool
test11()199 test11() {
200 Variable C(2);
201
202 Congruence_System cgs;
203 cgs.insert((0*C %= 3) / 3);
204
205 Grid gr(cgs);
206
207 // Minimize the congruences.
208 gr.minimized_congruences();
209
210 bool ok = (gr.is_universe());
211
212 print_congruences(gr, "*** gr ***");
213
214 return ok;
215 }
216
217 // Minimized universe congruences.
218 bool
test12()219 test12() {
220 Variable C(2);
221
222 Congruence_System cgs;
223 cgs.insert((0*C %= 4) / 2);
224
225 Grid gr(cgs);
226
227 // Minimize the congruences.
228 gr.minimized_congruences();
229
230 bool ok = (gr.is_universe());
231
232 print_congruences(gr, "*** gr ***");
233
234 return ok;
235 }
236
237 // Universe after remove_space_dimensions.
238
239 bool
test13()240 test13() {
241 Variable A(0);
242 Variable C(2);
243
244 Congruence_System cgs;
245 cgs.insert((A + 0*C %= 4) / 2);
246
247 Grid gr(cgs);
248
249 Variables_Set vars;
250 vars.insert(A);
251
252 gr.remove_space_dimensions(vars);
253
254 // Minimize the congruences.
255 gr.minimized_congruences();
256
257 bool ok = (gr.is_universe());
258
259 print_congruences(gr, "*** gr ***");
260
261 return ok;
262 }
263
264 // Empty from a simple constraint.
265
266 bool
test14()267 test14() {
268 Variable C(2);
269
270 Congruence_System cgs;
271 cgs.insert(0*C == 0);
272
273 Grid gr(cgs);
274
275 // Minimize the congruences.
276 gr.minimized_congruences();
277
278 bool ok = (gr.is_universe());
279
280 print_congruences(gr, "*** gr ***");
281
282 return ok;
283 }
284
285 // Congruences before minimization, where a point is required to
286 // determine that the grid is a strict subset of the universe.
287
288 bool
test15()289 test15() {
290 Variable A(0);
291
292 Congruence_System cgs;
293 cgs.insert(A == 3);
294
295 Grid gr(cgs);
296
297 bool ok = (!gr.is_universe());
298
299 print_congruences(gr, "*** gr ***");
300
301 return ok;
302 }
303
304 } // namespace
305
306 BEGIN_MAIN
307 DO_TEST(test01);
308 DO_TEST(test02);
309 DO_TEST(test03);
310 DO_TEST(test04);
311 DO_TEST(test05);
312 DO_TEST(test06);
313 DO_TEST(test07);
314 DO_TEST(test08);
315 DO_TEST(test09);
316 DO_TEST(test10);
317 DO_TEST(test11);
318 DO_TEST(test12);
319 DO_TEST(test13);
320 DO_TEST(test14);
321 DO_TEST(test15);
322 END_MAIN
323