1 /* Test Box<T>::minimized_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   Variable B(1);
32 
33   TBox box(2);
34   box.add_constraint(A >= 1);
35   box.add_constraint(B >= 0);
36   box.add_constraint(B <= 3);
37   box.add_constraint(A >= -3);
38   box.add_constraint(A <= 1);
39 
40   print_constraints(box, "*** box ***");
41 
42   const Constraint_System cs = box.minimized_constraints();
43 
44   using namespace IO_Operators;
45   nout << "*** box.minimized_constraints() ***" << endl;
46 
47   dimension_type num_constraints = 0;
48   for (Constraint_System::const_iterator i = cs.begin(),
49          iend = cs.end(); i != iend; ++i) {
50     nout << *i << endl;
51     ++num_constraints;
52   }
53 
54   nout << "num_constraints == " << num_constraints << endl;
55 
56   C_Polyhedron ph_box(cs);
57   C_Polyhedron known_result(2);
58   known_result.add_constraint(A == 1);
59   known_result.add_constraint(B >= 0);
60   known_result.add_constraint(B <= 3);
61 
62   bool ok = (num_constraints == 3 && known_result == ph_box);
63 
64   return ok;
65 }
66 
67 bool
test02()68 test02() {
69   TBox box(0, UNIVERSE);
70 
71   print_constraints(box, "*** box ***");
72 
73   const Constraint_System cs = box.minimized_constraints();
74 
75   using namespace IO_Operators;
76   nout << "*** box.minimized_constraints() ***" << endl;
77 
78   dimension_type num_constraints = 0;
79   for (Constraint_System::const_iterator i = cs.begin(),
80          iend = cs.end(); i != iend; ++i) {
81     nout << *i << endl;
82     ++num_constraints;
83   }
84 
85   nout << "num_constraints == " << num_constraints << endl;
86 
87   return num_constraints == 0;
88 }
89 
90 } // namespace
91 
92 BEGIN_MAIN
93   DO_TEST(test01);
94   DO_TEST(test02);
95 END_MAIN
96