1 /* Test BD_Shape::constraints().
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 bool
test01()29 test01() {
30 TBD_Shape bds1(0, EMPTY);
31
32 BD_Shape<mpq_class> known_result(bds1);
33
34 Constraint_System cs = bds1.constraints();
35 TBD_Shape bds2(cs);
36
37 bool ok = check_result(bds2, known_result);
38
39 print_constraints(bds1, "*** bds1 ***");
40 print_constraints(bds2, "*** bds2 ***");
41 print_constraints(cs, "*** cs ***");
42
43 return ok;
44 }
45
46 bool
test02()47 test02() {
48 TBD_Shape bds1(0, UNIVERSE);
49
50 BD_Shape<mpq_class> known_result(bds1);
51
52 Constraint_System cs = bds1.constraints();
53 TBD_Shape bds2(cs);
54
55 bool ok = check_result(bds2, known_result);
56
57 print_constraints(bds1, "*** bds1 ***");
58 print_constraints(bds2, "*** bds2 ***");
59 print_constraints(cs, "*** cs ***");
60
61 return ok;
62 }
63
64 bool
test03()65 test03() {
66 Variable A(0);
67 Variable B(1);
68 Variable C(2);
69
70 TBD_Shape bds1(3);
71 bds1.add_constraint(A >= 0);
72 bds1.add_constraint(B >= 0);
73 bds1.add_constraint(B - C >= 1);
74 bds1.add_constraint(C - A <= 9);
75
76 BD_Shape<mpq_class> known_result(bds1);
77
78 bds1.contains(bds1);
79
80 Constraint_System cs = bds1.constraints();
81 TBD_Shape bds2(cs);
82
83 bool ok = check_result(bds2, known_result);
84
85 print_constraints(bds1, "*** bds1 ***");
86 print_constraints(bds2, "*** bds2 ***");
87 print_constraints(cs, "*** cs ***");
88
89 return ok;
90 }
91
92 bool
test04()93 test04() {
94 Variable A(0);
95 Variable B(1);
96 Variable C(2);
97
98 TBD_Shape bds1(3);
99 bds1.add_constraint(A >= 0);
100 bds1.add_constraint(B >= 0);
101 bds1.add_constraint(B - C == 1);
102 bds1.add_constraint(C - A <= 9);
103
104 Constraint_System cs = bds1.constraints();
105 TBD_Shape bds2(cs);
106
107 print_constraints(bds1, "*** bds1 ***");
108 print_constraints(bds2, "*** bds2 ***");
109 print_constraints(cs, "*** cs ***");
110
111 BD_Shape<mpq_class> known_result(bds1);
112
113 bool ok = check_result(bds2, known_result);
114
115 return ok;
116 }
117
118 bool
test05()119 test05() {
120
121 TBD_Shape bds1(0);
122 bds1.add_constraint(Linear_Expression(1) == 0);
123
124 TBD_Shape bds2(0, EMPTY);
125
126 print_constraints(bds1, "*** bds1 ***");
127 print_constraints(bds2, "*** bds2 ***");
128
129 BD_Shape<mpq_class> known_result(bds2);
130
131 bool ok = check_result(bds1, known_result);
132
133 return ok;
134 }
135
136 bool
test06()137 test06() {
138 Variable A(0);
139 Variable B(1);
140 Variable C(2);
141 Variable D(3);
142
143 TBD_Shape bds(4);
144 bds.refine_with_constraint(A > 0);
145 bds.refine_with_constraint(B < 0);
146 bds.refine_with_constraint(2*B - 2*C < 1);
147 bds.refine_with_constraint(A - C > 2);
148 bds.refine_with_constraint(A + 2*D >= 5);
149
150 BD_Shape<mpq_class> known_result(4);
151 known_result.add_constraint(A >= 0);
152 known_result.add_constraint(B <= 0);
153 known_result.add_constraint(2*B - 2*C <= 1);
154 known_result.add_constraint(A - C >= 2);
155
156 bool ok = check_result(bds, known_result);
157
158 print_constraints(bds, "*** bds ***");
159
160 return ok;
161 }
162
163 bool
test07()164 test07() {
165 Variable A(0);
166 Variable B(1);
167 Variable C(2);
168
169 Constraint_System cs(A > 0);
170 cs.insert(2*B - 2*C <= 1);
171 cs.insert(A - 5*C > 4);
172
173 TBD_Shape bds(3);
174 bds.refine_with_constraints(cs);
175
176 BD_Shape<mpq_class> known_result(3);
177 known_result.add_constraint(A >= 0);
178 known_result.add_constraint(2*B - 2*C <= 1);
179
180 bool ok = check_result(bds, known_result);
181
182 print_constraints(bds, "*** bds ***");
183
184 return ok;
185 }
186
187 } // namespace
188
189 BEGIN_MAIN
190 DO_TEST(test01);
191 DO_TEST(test02);
192 DO_TEST(test03);
193 DO_TEST(test04);
194 DO_TEST(test05);
195 DO_TEST(test06);
196 DO_TEST(test07);
197 END_MAIN
198