summaryrefslogtreecommitdiff
path: root/tests/Powerset/powerset1.cc
blob: 58db48acaf36c517ab10ca6821b74240c7024ae0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/* Test Powerset<D>.
   Copyright (C) 2001-2010 Roberto Bagnara <bagnara@cs.unipr.it>
   Copyright (C) 2010-2011 BUGSENG srl (http://bugseng.com)

This file is part of the Parma Polyhedra Library (PPL).

The PPL is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 3 of the License, or (at your
option) any later version.

The PPL is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA.

For the most up-to-date information see the Parma Polyhedra Library
site: http://www.cs.unipr.it/ppl/ . */

#include "ppl_test.hh"

namespace {

// Uses every public Powerset method.
bool
test01() {
  typedef Powerset<FCAIBVP> PSET;

  Variable A(0);

  PSET ps1;
  ps1.add_disjunct(FCAIBVP(A));

  PSET ps2 = ps1;

  if (ps2 != ps1 || !(ps2 == ps1))
    return false;

  using IO_Operators::operator<<;
  nout << "ps1:" << endl << ps1 << endl;

  FCAIBVP d(A);
  PSET ps3(d);

  if (!ps1.definitely_entails(ps3))
    return false;

  if (ps3.is_top())
    return false;

  if (ps1.is_bottom())
    return false;

  nout << "Total memory: " << ps3.total_memory_in_bytes() << endl
       << "External memory: " << ps3.external_memory_in_bytes() << endl;

  ps3.omega_reduce();

  if (ps3.size() == 0)
    return false;

  if (ps3.empty())
    return false;

  // Iterator.
  dimension_type count = 0;
  for (PSET::iterator i = ps3.begin(); i != ps3.end(); ++i)
    ++count;
  if (count != 1)
    return false;

  // Constant iterator.
  count = 0;
  for (PSET::const_iterator i = ps3.begin(); i != ps3.end(); ++i)
    ++count;
  if (count != 1)
    return false;

  // Reverse iterator.
  count = 0;
  for (PSET::reverse_iterator i = ps3.rbegin(); i != ps3.rend(); ++i)
    ++count;
  if (count != 1)
    return false;

  // Constant reverse iterator.
  count = 0;
  for (PSET::const_reverse_iterator i = ps3.rbegin(),
	 ps3_rend = ps3.rend(); i != ps3_rend; ++i)
    ++count;
  if (count != 1)
    return false;

  ps2 = ps3;
  PSET ps_empty;
  ps2.drop_disjunct(ps2.begin());
  if (ps2 != ps_empty)
    return false;

  ps2 = ps3;
  ps2.drop_disjuncts(ps2.begin(),ps2.end());
  if (ps2 != ps_empty)
    return false;

  ps2 = ps3;
  ps2.clear();
  if (ps2 != ps_empty)
    return false;

  ps3.swap(ps2);
  ps3.swap(ps2);
  if (ps3 != ps1 || ps2 != ps_empty)
    return false;

  ps2 = ps_empty;
  ps2.least_upper_bound_assign(ps3);
  if (ps2 != ps3)
    return false;

  ps2 = ps_empty;
  ps2.upper_bound_assign(ps3);
  if (ps2 != ps3)
    return false;

  Variable B(1);
  ps2 = ps1;
  ps2.meet_assign(ps3);
  if (ps2 != ps3)
    return false;

  ps3.collapse();
  if (ps3.size() != 1)
    return false;

  return true;
}

bool
test02() {
  Variable X(0);
  Variable Y(1);

  FCAIBVP XY(X);
  XY.meet_assign(FCAIBVP(Y));

  Powerset<FCAIBVP> ps;

  ps.add_disjunct(FCAIBVP(X));
  ps.add_disjunct(XY);
  return ps.OK();
}

bool
test03() {
  Variable X(0);
  Variable Y(1);

  FCAIBVP XY(X);
  XY.meet_assign(FCAIBVP(Y));

  Powerset<FCAIBVP> ps;

  ps.add_disjunct(XY);
  ps.add_disjunct(FCAIBVP(X));
  return ps.OK();
}

} // namespace

BEGIN_MAIN
  DO_TEST(test01);
  DO_TEST(test02);
  DO_TEST(test03);
END_MAIN