1 /* Test Polyhedron::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 Variable A(0);
31
32 C_Polyhedron ph1(2);
33 ph1.add_constraint(0*A == 1);
34
35 print_constraints(ph1, "*** ph1 constraints ***");
36
37 C_Polyhedron known_result = ph1;
38
39 Constraint_System cs = ph1.constraints();
40 C_Polyhedron ph2(cs);
41
42 bool ok = (ph2 == known_result);
43
44 print_constraints(cs, "*** cs ***");
45
46 return ok;
47 }
48
49 bool
test02()50 test02() {
51 C_Polyhedron ph1(3, EMPTY);
52
53 print_constraints(ph1, "*** ph1 ***");
54
55 C_Polyhedron known_result = ph1;
56
57 Constraint_System cs = ph1.constraints();
58 C_Polyhedron ph2(cs);
59
60 bool ok = (ph2 == known_result);
61
62 print_constraints(cs, "*** cs ***");
63
64 return ok;
65 }
66
67 bool
test03()68 test03() {
69 C_Polyhedron ph1(0);
70 ph1.add_constraint(Linear_Expression::zero() == 1);
71 C_Polyhedron known_result(ph1);
72
73 const Constraint_System cs = ph1.constraints();
74
75 C_Polyhedron ph2(cs);
76
77 bool ok = (ph2 == known_result);
78
79 print_constraints(ph2, "*** ph2 ***");
80
81 return ok;
82 }
83
84 bool
test04()85 test04() {
86 Variable A(0);
87 Variable B(1);
88
89 C_Polyhedron ph1(2);
90 ph1.generators();
91 ph1.add_constraint(A >= 0);
92 ph1.add_constraint(B >= 0);
93
94 C_Polyhedron known_result(ph1);
95
96 Constraint_System cs = ph1.constraints();
97 C_Polyhedron ph2(cs);
98
99 bool ok = (ph2 == known_result);
100
101 print_constraints(ph1, "*** ph1 ***");
102 print_constraints(ph2, "*** ph2 ***");
103 print_constraints(cs, "*** cs ***");
104
105 return ok;
106 }
107
108 bool
test05()109 test05() {
110 Variable A(0);
111 Variable B(1);
112
113 C_Polyhedron ph1(2, EMPTY);
114 ph1.add_generator(point());
115 ph1.constraints();
116 ph1.add_generator(ray(A));
117 ph1.add_generator(ray(B));
118
119 C_Polyhedron known_result(ph1);
120
121 Constraint_System cs = ph1.constraints();
122 C_Polyhedron ph2(cs);
123
124 bool ok = (ph2 == known_result);
125
126 print_constraints(ph1, "*** ph1 ***");
127 print_constraints(ph2, "*** ph2 ***");
128 print_constraints(cs, "*** cs ***");
129
130 return ok;
131 }
132
133 bool
test06()134 test06() {
135 Variable A(0);
136 Variable B(1);
137
138 C_Polyhedron ph(2);
139 ph.add_constraint(A >= 0);
140 ph.add_constraint(B >= 0);
141
142 print_constraints(ph, "*** ph ***");
143
144 Constraint_System cs = ph.constraints();
145 cs.insert(A >= B);
146
147 print_constraints(cs, "*** cs ***");
148
149 C_Polyhedron known_result(2);
150 known_result.add_constraint(A >= 0);
151 known_result.add_constraint(B >= 0);
152 known_result.add_constraint(A >= B);
153
154 return C_Polyhedron(cs) == known_result;
155 }
156
157 } // namespace
158
159 BEGIN_MAIN
160 DO_TEST(test01);
161 DO_TEST(test02);
162 DO_TEST(test03);
163 DO_TEST(test04);
164 DO_TEST(test05);
165 DO_TEST(test06);
166 END_MAIN
167