1 /* Test Box::Box(const Generator_System&).
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 Generator_System gs;
31 TBox box(gs);
32
33 Rational_Box known_result(0, EMPTY);
34
35 bool ok = check_result(box, known_result);
36
37 print_constraints(box, "*** box ***");
38
39 return ok;
40 }
41
42 bool
test02()43 test02() {
44 Variable V(10);
45
46 Generator_System gs;
47 gs.insert(closure_point(V));
48
49 try {
50 // It is illegal to build a Box starting from a non-empty
51 // generator system having no points.
52 TBox box(gs);
53 }
54 catch (std::invalid_argument& e) {
55 nout << "std::invalid_argument: " << e.what() << endl;
56 return true;
57 }
58 catch (...) {
59 }
60 return false;
61 }
62
63 bool
test03()64 test03() {
65 Variable V(10);
66
67 Generator_System gs;
68 gs.insert(ray(V));
69
70 try {
71 // It is illegal to build a Box starting from a non-empty
72 // generator system having no points.
73 TBox box(gs);
74 }
75 catch (std::invalid_argument& e) {
76 nout << "std::invalid_argument: " << e.what() << endl;
77 return true;
78 }
79 catch (...) {
80 }
81 return false;
82 }
83
84 bool
test04()85 test04() {
86 Variable A(0);
87 Variable B(1);
88 Variable C(2);
89 Variable D(3);
90
91 Generator_System gs;
92 gs.insert(ray(A + B));
93 gs.insert(point(1*A + 2*B + 3*C + 4*D));
94 gs.insert(point(2*A + 3*B + 4*C + 5*D));
95 TBox box(gs);
96
97 Rational_Box known_result(4);
98 known_result.add_constraint(A >= 1);
99 known_result.add_constraint(B >= 2);
100 known_result.add_constraint(C >= 3);
101 known_result.add_constraint(C <= 4);
102 known_result.add_constraint(D >= 4);
103 known_result.add_constraint(D <= 5);
104
105 bool ok = check_result(box, known_result);
106
107 print_constraints(box, "*** box ***");
108
109 return ok;
110 }
111
112 bool
test05()113 test05() {
114 Variable A(0);
115 Variable B(1);
116 Variable C(2);
117 Variable D(3);
118
119 C_Polyhedron ph(4);
120 ph.add_constraint(A >= B);
121 ph.add_constraint(B >= 2*C);
122 ph.add_constraint(C >= 3*D);
123 ph.add_constraint(D >= 4);
124 ph.add_constraint(A-D <= 50);
125
126 TBox box(ph.generators());
127
128 Rational_Box known_result(4);
129 known_result.add_constraint(A >= 24);
130 known_result.add_constraint(A <= 60);
131 known_result.add_constraint(B >= 24);
132 known_result.add_constraint(B <= 60);
133 known_result.add_constraint(C >= 12);
134 known_result.add_constraint(C <= 30);
135 known_result.add_constraint(D >= 4);
136 known_result.add_constraint(D <= 10);
137
138
139 bool ok = check_result(box, known_result);
140
141 print_constraints(box, "*** box ***");
142
143 return ok;
144 }
145
146 bool
test06()147 test06() {
148 Variable A(0);
149 Variable B(1);
150 Variable C(2);
151
152 NNC_Polyhedron ph(4);
153 ph.add_constraint(A == 7);
154 ph.add_constraint(B < 3);
155 ph.add_constraint(B >= 0);
156 ph.add_constraint(C < 7);
157
158 TBox box(ph.generators());
159
160 Rational_Box known_result(4);
161 known_result.add_constraint(A == 7);
162 known_result.add_constraint(B < 3);
163 known_result.add_constraint(B >= 0);
164 known_result.add_constraint(C < 7);
165
166 bool ok = check_result(box, known_result);
167
168 print_constraints(box, "*** box ***");
169
170 return ok;
171 }
172
173 } // namespace
174
175 BEGIN_MAIN
176 DO_TEST(test01);
177 DO_TEST(test02);
178 DO_TEST(test03);
179 DO_TEST(test04);
180 DO_TEST(test05);
181 DO_TEST(test06);
182 END_MAIN
183