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