1 /* Test Grid::is_disjoint_from().
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 // Grid of points and empty grid.
31 bool
test01()32 test01() {
33   Variable A(0);
34 
35   Grid_Generator_System gs;
36   gs.insert(grid_point(A));
37 
38   Grid gr1(gs);
39 
40   Grid gr2(1, EMPTY);
41 
42   bool ok = (gr1.is_disjoint_from(gr2));
43   print_congruences(gr1, "*** gr1 ***");
44   print_congruences(gr2, "*** gr2 ***");
45 
46   return ok;
47 }
48 
49 // Empty grid and grid of points.
50 bool
test02()51 test02() {
52   Variable B(1);
53 
54   Grid gr1(2, EMPTY);
55 
56   Grid_Generator_System gs;
57   gs.insert(grid_point());
58   gs.insert(grid_point(B));
59 
60   Grid gr2(gs);
61 
62   bool ok = (gr1.is_disjoint_from(gr2));
63   print_congruences(gr1, "*** gr1 ***");
64   print_congruences(gr2, "*** gr2 ***");
65 
66   return ok;
67 }
68 
69 // Both empty.
70 bool
test03()71 test03() {
72   Grid gr1(4, EMPTY);
73 
74   Grid gr2(4, EMPTY);
75 
76   bool ok = (gr1.is_disjoint_from(gr2));
77   print_congruences(gr1, "*** gr1 ***");
78   print_congruences(gr2, "*** gr2 ***");
79 
80   return ok;
81 }
82 
83 // Zero dimension universes.
84 bool
test04()85 test04() {
86   Grid gr1(0);
87 
88   Grid gr2(0);
89 
90   bool ok = (!gr1.is_disjoint_from(gr2));
91   print_congruences(gr1, "*** gr1 ***");
92   print_congruences(gr2, "*** gr2 ***");
93 
94   return ok;
95 }
96 
97 // Grid and itself.
98 bool
test05()99 test05() {
100   Variable A(0);
101   Variable B(1);
102   Variable C(2);
103 
104   Grid gr(3);
105   gr.add_congruence(A - B %= 0);
106   gr.add_congruence(C %= 0);
107 
108   bool ok = (!gr.is_disjoint_from(gr));
109   print_congruences(gr, "*** gr ***");
110 
111   return ok;
112 }
113 
114 // Two grids which alternate AB planes along C.
115 bool
test06()116 test06() {
117   Variable A(0);
118   Variable B(1);
119   Variable C(2);
120 
121   Grid gr1(3);
122   gr1.add_congruence(A - B %= 0);
123   gr1.add_congruence((C %= 0) / 2);
124 
125   Grid gr2(3, EMPTY);
126   gr2.add_grid_generator(grid_point(C));
127   gr2.add_grid_generator(grid_line(A + B));
128   gr2.add_grid_generator(grid_point(C + B));
129   gr2.add_grid_generator(grid_point(3*C));
130 
131   bool ok = (gr1.is_disjoint_from(gr2));
132   print_congruences(gr1, "*** gr1 ***");
133   print_congruences(gr2, "*** gr2 ***");
134 
135   return ok;
136 }
137 
138 // A sequence of points and a plane.
139 bool
test07()140 test07() {
141   Variable A(0);
142   Variable B(1);
143   Variable C(2);
144 
145   Grid gr1(3, EMPTY);
146   gr1.add_grid_generator(grid_point(A + B + C));
147   gr1.add_grid_generator(grid_point(3*A + 3*B + 3*C));
148 
149   Grid gr2(3);
150   gr2.add_congruence(A - B %= 0);
151   gr2.add_constraint(C == 0);
152 
153   bool ok = (gr1.is_disjoint_from(gr2));
154   print_congruences(gr1, "*** gr1 ***");
155   print_congruences(gr2, "*** gr2 ***");
156 
157   return ok;
158 }
159 
160 // A line and a plane.
161 bool
test08()162 test08() {
163   Variable A(0);
164   Variable B(1);
165   Variable C(2);
166 
167   Grid gr1(3, EMPTY);
168   gr1.add_grid_generator(grid_point(A + B + C));
169   gr1.add_grid_generator(grid_line(3*A + 3*B + 3*C));
170 
171   Grid gr2(3);
172   gr2.add_congruence(A - B %= 0);
173   gr2.add_constraint(C == 0);
174 
175   bool ok = (!gr1.is_disjoint_from(gr2));
176   print_congruences(gr1, "*** gr1 ***");
177   print_congruences(gr2, "*** gr2 ***");
178 
179   return ok;
180 }
181 
182 // CHINA contains example that showed an error in cgs::is_included_in.
183 bool
test09()184 test09() {
185   Variable A(0);
186 
187   Grid gr1(1, EMPTY);
188   gr1.add_grid_generator(grid_point());
189   gr1.minimized_grid_generators();
190 
191   Grid gr2(1, EMPTY);
192   gr2.add_grid_generator(grid_point(A));
193   gr2.minimized_grid_generators();
194 
195   bool ok = (gr1.is_disjoint_from(gr2));
196   print_congruences(gr2, "*** gr2 ***");
197   print_congruences(gr1, "*** gr1.is_disjoint_from(gr2) ***");
198 
199   return ok;
200 }
201 
202 // Space dimension exception.
203 bool
test10()204 test10() {
205   Grid gr1(1, EMPTY);
206   gr1.add_grid_generator(grid_point());
207 
208   Grid gr2(19, EMPTY);
209 
210   try {
211     gr1.is_disjoint_from(gr2);
212   }
213   catch (const std::invalid_argument& e) {
214     nout << "invalid_argument: " << e.what() << endl;
215     return true;
216   }
217   catch (...) {
218   }
219   return false;
220 }
221 
222 // Both empty and both not in minimal form.
223 bool
test11()224 test11() {
225   Variable A(0);
226   Grid gr1(1);
227   gr1.add_congruence((A %= 1) / 2);
228   gr1.add_congruence((A %= 0) / 2);
229 
230   Grid gr2(1);
231   gr2.add_congruence((A %= 1) / 2);
232   gr2.add_congruence((A %= 0) / 2);
233 
234   bool ok = (gr1.is_disjoint_from(gr2));
235   print_congruences(gr1, "*** gr1 ***");
236   print_congruences(gr2, "*** gr2 ***");
237 
238   return ok;
239 }
240 
241 } // namespace
242 
243 BEGIN_MAIN
244   DO_TEST(test01);
245   DO_TEST(test02);
246   DO_TEST(test03);
247   DO_TEST(test04);
248   DO_TEST(test05);
249   DO_TEST(test06);
250   DO_TEST(test07);
251   DO_TEST(test08);
252   DO_TEST(test09);
253   DO_TEST(test10);
254   DO_TEST(test11);
255 END_MAIN
256