1 /* Test Box::frequency().
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 bd shape.
31 bool
test01()32 test01() {
33 Variable A(0);
34
35 TBox box1(1);
36
37 TBox box2(1, EMPTY);
38
39 Coefficient num1;
40 Coefficient den1;
41 Coefficient valn1;
42 Coefficient vald1;
43 Coefficient num2;
44 Coefficient den2;
45 Coefficient valn2;
46 Coefficient vald2;
47 bool ok = (!box1.frequency(A, num1, den1, valn1, vald1)
48 && !box2.frequency(A, num2, den2, valn2, vald2));
49 print_constraints(box1, "*** box1 ***");
50 print_constraints(box2, "*** box2 ***");
51
52 return ok;
53 }
54
55 // 0-dimension polyhedra.
56 bool
test02()57 test02() {
58 TBox box1(0);
59
60 TBox box2(0, EMPTY);
61
62 Coefficient num1;
63 Coefficient den1;
64 Coefficient valn1;
65 Coefficient vald1;
66 Coefficient num2;
67 Coefficient den2;
68 Coefficient valn2;
69 Coefficient vald2;
70 bool ok = (box1.frequency(Linear_Expression(3), num1, den1, valn1, vald1)
71 && num1 == 0 && den1 == 1 && valn1 == 3 && vald1 == 1
72 && !box2.frequency(Linear_Expression(3), num2, den2, valn2, vald2));
73 print_constraints(box1, "*** box1 ***");
74 print_constraints(box2, "*** box2 ***");
75
76 return ok;
77 }
78
79 // Non-relational test.
80 bool
test03()81 test03() {
82 Variable A(0);
83
84 TBox box(1);
85 box.add_constraint(A == 0);
86
87 Coefficient num;
88 Coefficient den;
89 Coefficient valn;
90 Coefficient vald;
91 bool ok = (box.frequency(Linear_Expression(A), num, den, valn, vald)
92 && num == 0 && den == 1 && valn == 0 && vald == 1);
93 print_constraints(box, "*** box ***");
94
95 return ok;
96 }
97
98 bool
test04()99 test04() {
100 Variable A(0);
101 Variable B(1);
102
103 TBox box(2);
104 box.add_constraint(A >= 0);
105
106 Coefficient num;
107 Coefficient den;
108 Coefficient valn;
109 Coefficient vald;
110 bool ok = (!box.frequency(Linear_Expression(A), num, den, valn, vald));
111 print_constraints(box, "*** box ***");
112
113 return ok;
114 }
115
116 bool
test05()117 test05() {
118 Variable A(0);
119 Variable B(1);
120
121 TBox box(2);
122 box.add_constraint(A <= 0);
123 box.add_constraint(B >= 5);
124
125 Coefficient num;
126 Coefficient den;
127 Coefficient valn;
128 Coefficient vald;
129 bool ok = (!box.frequency(Linear_Expression(B), num, den, valn, vald));
130 print_constraints(box, "*** box ***");
131
132 return ok;
133 }
134
135 bool
test06()136 test06() {
137 Variable A(0);
138 Variable B(1);
139
140 TBox box(2);
141 box.add_constraint(2*A == 1);
142 box.add_constraint(B == 2);
143
144 Coefficient num;
145 Coefficient den;
146 Coefficient valn;
147 Coefficient vald;
148 bool ok = (box.frequency(Linear_Expression(A + B - 3), num, den, valn, vald)
149 && num == 0 && den == 1 && valn == -1 && vald == 2);
150 print_constraints(box, "*** box ***");
151 nout << "valn " << valn << ", vald " << vald << endl;
152
153 return ok;
154 }
155
156 bool
test07()157 test07() {
158 Variable A(0);
159 Variable B(1);
160
161 TBox box(2);
162 box.add_constraint(A <= 1);
163 box.add_constraint(A >= 0);
164
165 Coefficient num;
166 Coefficient den;
167 Coefficient valn;
168 Coefficient vald;
169 bool ok = (!box.frequency(Linear_Expression(A - B), num, den, valn, vald));
170 print_constraints(box, "*** box ***");
171
172 return ok;
173 }
174
175 bool
test08()176 test08() {
177 Variable A(0);
178 Variable B(1);
179 Variable C(2);
180
181 TBox box(3);
182 box.add_constraint(A == 1);
183 box.add_constraint(2*B == -1);
184 box.add_constraint(2*C == 1);
185 box.add_constraint(B <= 4);
186
187 Coefficient num;
188 Coefficient den;
189 Coefficient valn;
190 Coefficient vald;
191 bool ok = (box.frequency(Linear_Expression(A - B + C + 1),
192 num, den, valn, vald)
193 && num == 0 && den == 1 && valn == 3 && vald == 1);
194 print_constraints(box, "*** box ***");
195 nout << "valn " << valn << ", vald " << vald << endl;
196
197 return ok;
198 }
199
200 // Non-relational test of an empty box in 1-dimension.
201 bool
test09()202 test09() {
203 Variable A(0);
204
205 TBox box(1);
206 box.add_constraint(A <= 0);
207 box.add_constraint(A >= 1);
208
209 Coefficient num;
210 Coefficient den;
211 Coefficient valn;
212 Coefficient vald;
213 bool ok = (!box.frequency(Linear_Expression(A), num, den, valn, vald));
214 print_constraints(box, "*** box ***");
215
216 return ok;
217 }
218
219 } // namespace
220
221 BEGIN_MAIN
222 DO_TEST(test01);
223 DO_TEST(test02);
224 DO_TEST(test03);
225 DO_TEST(test04);
226 DO_TEST(test05);
227 DO_TEST(test06);
228 DO_TEST(test07);
229 DO_TEST(test08);
230 DO_TEST(test09);
231 END_MAIN
232