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