1 /* Test operator<<(ostream&, const Octagonal_Shape&).
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 IO_Operators;
27
28 namespace {
29
30 bool
test01()31 test01() {
32 Variable x(0);
33 Variable y(1);
34
35 TOctagonal_Shape oc(3);
36 oc.add_constraint(x + y == 3);
37 oc.add_constraint(x - y == 4);
38
39 std::stringstream s;
40 s << oc;
41
42 nout << "*** s << oc ***" << endl << "`" << s.str() << "'" << endl;
43
44 return s.str() == "A - B = 4, A + B = 3";
45 }
46
47 bool
test02()48 test02() {
49 Variable x(0);
50 Variable y(1);
51
52 TOctagonal_Shape oc(3);
53 oc.add_constraint(x - y == 5);
54 oc.add_constraint(x + y == -1);
55
56 std::stringstream s;
57 s << oc;
58
59 nout << "*** s << oc ***" << endl << "`" << s.str() << "'" << endl;
60
61 return s.str() == "A - B = 5, A + B = -1";
62 }
63
64 bool
test03()65 test03() {
66 Variable x(0);
67 Variable y(1);
68
69 TOctagonal_Shape oc(3);
70 oc.add_constraint(-x - y <= 3);
71 oc.add_constraint(-x + y <= 4);
72
73 std::stringstream s;
74 s << oc;
75
76 nout << "*** s << oc ***" << endl << "`" << s.str() << "'" << endl;
77
78 return s.str() == "B - A <= 4, A + B >= -3";
79 }
80
81 bool
test04()82 test04() {
83 Variable x(0);
84 Variable y(1);
85
86 TOctagonal_Shape oc(3);
87 oc.add_constraint(x - y <= 3);
88 oc.add_constraint(x + y <= 4);
89
90 std::stringstream s;
91 s << oc;
92
93 nout << "*** s << oc ***" << endl << "`" << s.str() << "'" << endl;
94
95 return s.str() == "A - B <= 3, A + B <= 4";
96 }
97
98 bool
test05()99 test05() {
100 Variable x(0);
101 Variable y(1);
102
103 TOctagonal_Shape oc(3);
104
105 oc.add_constraint(x - y >= 4);
106 oc.add_constraint(x - y <= 4);
107
108 std::stringstream s;
109 s << oc;
110
111 nout << "*** s << oc ***" << endl << "`" << s.str() << "'" << endl;
112
113 return s.str() == "A - B = 4";
114 }
115
116 bool
test06()117 test06() {
118 Variable x(0);
119 Variable y(1);
120
121 TOctagonal_Shape oc(3);
122
123 oc.add_constraint(x + y <= 3);
124 oc.add_constraint(x + y >= 3);
125
126 std::stringstream s;
127 s << oc;
128
129 nout << "*** s << oc ***" << endl << "`" << s.str() << "'" << endl;
130
131 return s.str() == "A + B = 3";
132 }
133
134 bool
test07()135 test07() {
136 TOctagonal_Shape oc(32, UNIVERSE);
137
138 std::stringstream s;
139 s << oc;
140
141 nout << "*** s << oc ***" << endl << "`" << s.str() << "'" << endl;
142
143 return s.str() == "true";
144 }
145
146 bool
test08()147 test08() {
148 TOctagonal_Shape oc(32, EMPTY);
149
150 std::stringstream s;
151 s << oc;
152
153 nout << "*** s << oc ***" << endl << "`" << s.str() << "'" << endl;
154
155 return s.str() == "false";
156 }
157
158 bool
test09()159 test09() {
160 Variable x(0);
161 Variable y(1);
162
163 Octagonal_Shape<mpz_class> oc(2);
164
165 oc.add_constraint(x + y == 2);
166 oc.add_constraint(x - y == 1);
167
168 (void) oc.is_empty();
169
170 std::stringstream s;
171 s << oc;
172
173 nout << "*** s << oc ***" << endl << "`" << s.str() << "'" << endl;
174
175 return s.str() == "2*A = 3, 2*B = 1, A - B = 1, A + B = 2";
176 }
177
178 bool
test10()179 test10() {
180 Variable x(0);
181 Variable y(1);
182
183 Octagonal_Shape<mpq_class> oc(2);
184
185 oc.add_constraint(x + y == 2);
186 oc.add_constraint(x - y == 1);
187
188 (void) oc.is_empty();
189
190 std::stringstream s;
191 s << oc;
192
193 nout << "*** s << oc ***" << endl << "`" << s.str() << "'" << endl;
194
195 return s.str() == "A = 3/2, B = 1/2, A - B = 1, A + B = 2";
196 }
197
198 } // namespace
199
200 BEGIN_MAIN
201 DO_TEST(test01);
202 DO_TEST(test02);
203 DO_TEST(test03);
204 DO_TEST(test04);
205 DO_TEST(test05);
206 DO_TEST(test06);
207 DO_TEST(test07);
208 DO_TEST(test08);
209 DO_TEST(test09);
210 DO_TEST(test10);
211 END_MAIN
212