1 /* Test Polyhedron::add_generator().
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   Variable B(1);
32 
33   Generator_System gs;
34   gs.insert(point());
35   gs.insert(ray(A));
36   gs.insert(line(B));
37   NNC_Polyhedron ph1(gs);
38 
39   print_generators(ph1, "*** ph1 ***");
40 
41   C_Polyhedron ph2(2, EMPTY);
42   ph2.add_generator(point(-A));
43 
44   print_generators(ph2, "*** ph2 ***");
45 
46   const Generator_System& gs1 = ph1.minimized_generators();
47   for (Generator_System::const_iterator i = gs1.begin(),
48          gs1_end = gs1.end(); i != gs1_end; ++i)
49     ph2.add_generator(*i);
50 
51   C_Polyhedron known_result(2);
52   known_result.add_constraint(A >= -1);
53 
54   bool ok = (ph2 == known_result);
55 
56   print_generators(ph2, "*** after ph2add_generator(*i) ***");
57 
58   return ok;
59 }
60 
61 bool
test02()62 test02() {
63   Variable A(0);
64   Variable B(1);
65 
66   Generator_System gs;
67   gs.insert(point(A + B));
68   NNC_Polyhedron ph1(gs);
69 
70   print_generators(ph1, "*** ph1 ***");
71 
72   C_Polyhedron ph2(2, EMPTY);
73 
74   print_generators(ph2, "*** ph2 ***");
75 
76   const Generator_System& gs1 = ph1.minimized_generators();
77   for (Generator_System::const_iterator i = gs1.begin(),
78          gs1_end = gs1.end(); i != gs1_end; ++i)
79     ph2.add_generator(*i);
80 
81   C_Polyhedron known_result(2);
82   known_result.add_constraint(A == 1);
83   known_result.add_constraint(B == 1);
84 
85   bool ok = (ph2 == known_result);
86 
87   print_generators(ph2, "*** after ph2.add_generator(*i) ***");
88 
89   return ok;
90 }
91 
92 bool
test03()93 test03() {
94   Variable A(0);
95   Variable B(1);
96 
97   Generator_System gs;
98   gs.insert(closure_point(3*A, 2));
99   gs.insert(point(7*A, 4));
100   gs.insert(ray(A - B));
101 
102   print_generators(gs, "*** gs ***");
103 
104   C_Polyhedron ph(2, EMPTY);
105 
106   for (Generator_System::const_iterator i = gs.begin(),
107          gs_end = gs.end(); i != gs_end; ++i)
108     if (!(*i).is_closure_point())
109       ph.add_generator(*i);
110 
111   Generator_System gs_known;
112   gs_known.insert(point(7*A + 0*B, 4));
113   gs_known.insert(ray(A - B));
114   C_Polyhedron known_result(gs_known);
115 
116   bool ok = (ph == known_result);
117 
118   print_generators(gs, "*** gs ***");
119   print_generators(ph, "*** ph ***");
120 
121   return ok;
122 }
123 
124 } // namespace
125 
126 BEGIN_MAIN
127   DO_TEST(test01);
128   DO_TEST(test02);
129   DO_TEST(test03);
130 END_MAIN
131