File: CCuddDDFacadeTest.cc

package info (click to toggle)
brial 1.2.12-1.1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 11,404 kB
  • sloc: cpp: 219,610; ansic: 43,783; python: 4,172; makefile: 336; sh: 5
file content (635 lines) | stat: -rw-r--r-- 21,722 bytes parent folder | download | duplicates (3)
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
// -*- c++ -*-
//*****************************************************************************
/** @file CCuddDDFacadeTest.cc
 *
 * @author Ket Kalda, Alexander Dreyer
 * @date 2010-11-09
 *
 * boost/test-driven unit test
 * 
 * @par Copyright:
 *   (c) 2010 by The PolyBoRi Team
 *
 **/
//*****************************************************************************

#include <boost/test/unit_test.hpp>
#include <boost/version.hpp>
#if BOOST_VERSION < 107100
#include <boost/test/output_test_stream.hpp>
#else
#include <boost/test/tools/output_test_stream.hpp>
#endif

using boost::test_tools::output_test_stream;

#include <polybori/pbori_defs.h>
#include <polybori/BooleVariable.h>
#include <polybori/BooleMonomial.h>
#include <polybori/BoolePolynomial.h>
#include <polybori/BooleExponent.h>
#include <polybori/BoolePolyRing.h>
#include <polybori/orderings/pbori_order.h>
#include <vector>

BEGIN_NAMESPACE_PBORI
typedef CCuddDDFacade<BoolePolyRing, BooleSet> test_dd_type;
// Testing environment needs correct stream operator
inline std::ostream&
operator<<(std::ostream& os, const  test_dd_type& diagram) {
  return diagram.printIntern(os);
}
END_NAMESPACE_PBORI

USING_NAMESPACE_PBORI

struct Fdd {
  typedef BooleSet set_type;
  typedef test_dd_type dd_type;
  Fdd(const BoolePolyRing& input_ring = BoolePolyRing(5)): 
    ring(input_ring),
    x(0, input_ring), y(1, input_ring), z(2, input_ring),
    v(3, input_ring), w(4, input_ring), poly(input_ring) {

    BOOST_TEST_MESSAGE( "setup fixture" );
    ring.setVariableName(0, "x");
    ring.setVariableName(1, "y");
    ring.setVariableName(2, "z");
    ring.setVariableName(3, "v");
    ring.setVariableName(4, "w");
    poly = x*y*z + v*z - x*v + y + 1;
  }

  ~Fdd() { BOOST_TEST_MESSAGE( "teardown fixture" ); }

  BoolePolyRing ring;
  BooleVariable x, y, z, v, w;
  BoolePolynomial poly;
};




BOOST_FIXTURE_TEST_SUITE(CCuddDDFacadeTestSuite, Fdd )

BOOST_AUTO_TEST_CASE(test_constructors) {

  dd_type diagram(poly.set());

  BOOST_TEST_MESSAGE( "constructors" );

  BOOST_CHECK_EQUAL(set_type(diagram), poly.set());
  BOOST_CHECK(set_type(diagram) == poly.set());

  BoolePolynomial poly1 = y*z + v;
  BoolePolynomial poly2 = v*z + y + 1;
  dd_type diagram1(poly1.set());
  dd_type diagram2(poly2.set());
  output_test_stream output;
  diagram = dd_type(0,diagram1,diagram2);
  output << set_type(diagram);
  BOOST_CHECK(output.is_equal("{{x,y,z}, {x,v}, {y}, {z,v}, {}}"));
  BOOST_CHECK_THROW(dd_type(1,diagram1,diagram2), PBoRiGenericError<CTypes::invalid_ite>);
  BOOST_CHECK_THROW(dd_type(2,diagram1,diagram2), PBoRiGenericError<CTypes::invalid_ite>);

  BOOST_CHECK_THROW(dd_type(-1,diagram1,diagram2), std::exception);
  poly1 = 0;
  poly2 = y*z + v;
  diagram1 = dd_type(poly1.set());
  diagram2 = dd_type(poly2.set());
  diagram = dd_type(0,diagram1,diagram2);
  output << set_type(diagram);
  BOOST_CHECK(output.is_equal("{{y,z}, {v}}"));
  poly1 = 1;
  poly2 = y*z + v;
  diagram1 = dd_type(poly1.set());
  diagram2 = dd_type(poly2.set());
  diagram = dd_type(0,diagram1,diagram2);
  output << set_type(diagram);
  BOOST_CHECK(output.is_equal("{{x}, {y,z}, {v}}"));
  poly1 = 1;
  poly2 = 0;
  diagram1 = dd_type(poly1.set());
  diagram2 = dd_type(poly2.set());
  diagram = dd_type(4,diagram1,diagram2);
  output << set_type(diagram);
  BOOST_CHECK(output.is_equal("{{w}}"));
  diagram = dd_type(5,diagram1,diagram2);
  output << set_type(diagram);
  BOOST_CHECK(output.is_equal("{{UNDEF}}"));/// Wanted behaviour?
  BOOST_CHECK_THROW(dd_type(ring, NULL), std::runtime_error);
}

BOOST_AUTO_TEST_CASE(test_properties) {

  dd_type diagram(poly.set());
  set_type empty_set(poly.ring());
  set_type one_set = empty_set.add(BooleMonomial(ring));
  dd_type one(one_set);

  BOOST_TEST_MESSAGE( "isZero, isOne, isConstant" );
  BOOST_CHECK(!diagram.isZero());
  BOOST_CHECK(!one.isZero());
  BOOST_CHECK(!diagram.isOne());
  BOOST_CHECK(one.isOne());
  BOOST_CHECK(!diagram.isConstant());
  BOOST_CHECK(one.isConstant());
}

BOOST_AUTO_TEST_CASE(test_indices) {

  dd_type diagram(poly.set());
  set_type one_set(poly.ring());
  one_set = one_set.add(BooleMonomial(ring));
  dd_type one(one_set);
  output_test_stream output;

  BOOST_TEST_MESSAGE( "firstBegin, firstEnd, lastBegin, lastEnd" );
  BOOST_CHECK_EQUAL(*diagram.firstBegin(), 0);
  dd_type::first_iterator start = diagram.firstBegin();
  dd_type::first_iterator finish = diagram.firstEnd();
  while (start != finish) {
    output<<  *start <<", ";
    ++start;
  }
  BOOST_CHECK(output.is_equal("0, 1, 2, "));

  diagram = BoolePolynomial(x*y*z + x*y).set();
  dd_type::last_iterator last_start = diagram.lastBegin();
  dd_type::last_iterator last_finish = diagram.lastEnd();
  while (last_start != last_finish) {
    output << *last_start <<", ";
    ++last_start;
  }
  BOOST_CHECK(output.is_equal("0, 1, "));
  last_start = diagram.lastBegin();
  last_finish = diagram.lastEnd();
  while (last_start != last_finish) {
    output << *last_start <<", ";
    last_start++;
  }
  BOOST_CHECK(output.is_equal("0, 1, "));
  last_start = one.lastBegin();
  last_finish = one.lastEnd();
  while (last_start != last_finish) {
    output << *last_start <<", ";
    last_start++;
  }
  BOOST_CHECK(output.is_equal(""));

}

BOOST_AUTO_TEST_CASE(test_divide) {
  BoolePolynomial poly_large = x*y*z + v*z - x*v + y + 1;
  BoolePolynomial poly_small = x;
  dd_type diagram_large(poly_large.set());
  dd_type diagram_small(poly_small.set());
  set_type one_set(poly.ring());
  one_set = one_set.add(BooleMonomial(ring));
  dd_type one(one_set);
  output_test_stream output;

  BOOST_TEST_MESSAGE( "divideFirst" );
  output << diagram_large.divideFirst(diagram_small);
  BOOST_CHECK(output.is_equal("{{y,z}, {v}}"));
  poly_small = y;
  diagram_small =dd_type(poly_small.set());
  output << diagram_large.divideFirst(diagram_small);
  BOOST_CHECK(output.is_equal("{{x,z}, {}}"));
  poly_small = z;
  diagram_small =dd_type(poly_small.set());
  output << diagram_large.divideFirst(diagram_small);
  BOOST_CHECK(output.is_equal("{{x,y}, {v}}"));
  poly_small = v;
  diagram_small =dd_type(poly_small.set());
  output << diagram_large.divideFirst(diagram_small);
  BOOST_CHECK(output.is_equal("{{x}, {z}}"));
  poly_small = x*y;
  diagram_small =dd_type(poly_small.set());
  output << diagram_large.divideFirst(diagram_small);
  BOOST_CHECK(output.is_equal("{{z}}"));
  poly_small = x*v;
  diagram_small =dd_type(poly_small.set());
  output << diagram_large.divideFirst(diagram_small);
  BOOST_CHECK(output.is_equal("{{}}"));
  poly_small = z*v;
  diagram_small =dd_type(poly_small.set());
  output << diagram_large.divideFirst(diagram_small);
  BOOST_CHECK(output.is_equal("{{}}"));
  poly_small = x*z;
  diagram_small =dd_type(poly_small.set());
  output << diagram_large.divideFirst(diagram_small);
  BOOST_CHECK(output.is_equal("{{y}}"));
  poly_small = y*z;
  diagram_small =dd_type(poly_small.set());
  output << diagram_large.divideFirst(diagram_small);
  BOOST_CHECK(output.is_equal("{{x}}"));
  poly_small = z*y*x;
  diagram_small =dd_type(poly_small.set());
  output << diagram_large.divideFirst(diagram_small);
  BOOST_CHECK(output.is_equal("{{}}"));
  poly_small = 1;
  diagram_small =dd_type(poly_small.set());
  output << diagram_large.divideFirst(diagram_small);
  BOOST_CHECK(output.is_equal("{{x,y,z}, {x,v}, {y}, {z,v}, {}}"));

  poly_small = 0; // Assuming rhs to be monomial, so this is not a valid input.
                  // Anyway, the result must be sane, be behaving like 1 is fine
  diagram_small = dd_type(poly_small.set());
  BOOST_CHECK_EQUAL(diagram_large.divideFirst(diagram_small), diagram_large);
  output << diagram_large.divideFirst(diagram_small);
  BOOST_CHECK(output.is_equal("{{x,y,z}, {x,v}, {y}, {z,v}, {}}"));

  poly_small = w;// nonexisting variable in poly_large
  diagram_small =dd_type(poly_small.set());
  output << diagram_large.divideFirst(diagram_small);
  BOOST_CHECK(output.is_equal("{}"));

  poly_small = x*w;// nonexisting variable combination in poly_large
  diagram_small =dd_type(poly_small.set());
  output << diagram_large.divideFirst(diagram_small);
  BOOST_CHECK(output.is_equal("{}"));

  poly_small = y*v;// nonexisting combination in poly_large
  diagram_small =dd_type(poly_small.set());
  output << diagram_large.divideFirst(diagram_small);
  BOOST_CHECK(output.is_equal("{}"));

  BOOST_TEST_MESSAGE( "firstDivisors" );
  output << diagram_large.firstDivisors();
  BOOST_CHECK(output.is_equal("{{x,y,z}, {x,y}, {x,z}, {x}, {y,z}, {y}, {z}, {}}"));
  poly_small = x*z + x*y;
  diagram_small =dd_type(poly_small.set());
  output << diagram_small.firstDivisors();
  BOOST_CHECK(output.is_equal("{{x,y}, {x}, {y}, {}}"));
  poly_small = z + x -1;
  diagram_small =dd_type(poly_small.set());
  output << diagram_small.firstDivisors();
  BOOST_CHECK(output.is_equal("{{x}, {}}"));
  poly_small = -1;
  diagram_small =dd_type(poly_small.set());
  output << diagram_small.firstDivisors();
  BOOST_CHECK(output.is_equal("{{}}"));
  poly_small = 0;
  diagram_small =dd_type(poly_small.set());
  output << diagram_small.firstDivisors();
  BOOST_CHECK(output.is_equal("{{}}"));// one is always a divisor
}

BOOST_AUTO_TEST_CASE(test_multiples) {

  dd_type diagram(poly.set());//x*y*z + v*z - x*v + y + 1;
  output_test_stream output;

  BOOST_TEST_MESSAGE( "firstmultiples" );
  std::vector<dd_type::idx_type> multipliers(3);
  multipliers[0]= 0;
  multipliers[1]= 1;
  multipliers[2]= 2;
  output << diagram.firstMultiples(multipliers);
  BOOST_CHECK(output.is_equal("{{x,y,z}}"));
  multipliers[0]= 2;
  multipliers[1]= 1;
  multipliers[2]= 0;
  output << diagram.firstMultiples(multipliers);
  BOOST_CHECK(output.is_equal("{{x,y,z}}"));

  multipliers[0]= 2;
  multipliers[1]= 0;
  multipliers[2]= 1;
  output << diagram.firstMultiples(multipliers);
  BOOST_CHECK(output.is_equal("{{x,y,z}}"));

  multipliers = std::vector<dd_type::idx_type>(2);
  multipliers[0]= 3;
  multipliers[1]= 4;
  output << diagram.firstMultiples(multipliers);
  BOOST_CHECK(output.is_equal("{{x,y,z,v,w}, {x,y,z,v}, {x,y,z,w}, {x,y,z}}"));

  multipliers[0]= 4;
  multipliers[1]= 3;
  output << diagram.firstMultiples(multipliers);
  BOOST_CHECK(output.is_equal("{{x,y,z,v,w}, {x,y,z,v}, {x,y,z,w}, {x,y,z}}"));

  multipliers[0]= 5;
  multipliers[1]= 6;
  output << diagram.firstMultiples(multipliers); ///@todo UNDEFs - maybe should throw
  BOOST_CHECK(output.is_equal("{{x,y,z,UNDEF,UNDEF}, {x,y,z,UNDEF}, {x,y,z,UNDEF}, {x,y,z}}"));

  multipliers[0]= 3;
  multipliers[1]= 3;
  output << diagram.firstMultiples(multipliers);
  BOOST_CHECK(output.is_equal("{{x,y,z,v}, {x,y,z}}"));

  multipliers[0]= 0;
  multipliers[1]= 0;

  output << diagram.firstMultiples(multipliers);
  BOOST_CHECK(output.is_equal("{{x,y,z}}"));
  multipliers = std::vector<dd_type::idx_type>(3);
  multipliers[0]= 0;
  multipliers[1]= 0;
  multipliers[2]= 0;

  output << diagram.firstMultiples(multipliers);
  BOOST_CHECK(output.is_equal("{{x,y,z}}"));
  multipliers = std::vector<dd_type::idx_type>(0);
  output << diagram.firstMultiples(multipliers);
  BOOST_CHECK(output.is_equal("{{x,y,z}}"));
  multipliers = std::vector<dd_type::idx_type>(1);
  multipliers[0]= -1;
  output << diagram.firstMultiples(multipliers); 
  BOOST_CHECK(output.is_equal("{{x,y,z}}"));
}

BOOST_AUTO_TEST_CASE(test_operators) {

  dd_type diagram(poly.set());//x*y*z + v*z - x*v + y + 1;
  BoolePolynomial poly_small = x*y*z + v*z - x*v + y + 1;
  dd_type diagram_small(poly_small.set());
  output_test_stream output;

  BOOST_TEST_MESSAGE( "Xor" );
  output << diagram.Xor(diagram_small);
  BOOST_CHECK(output.is_equal("{}"));
  poly_small = x*y*z + v*z - x*v + y;
  diagram_small = dd_type(poly_small.set());
  output << diagram.Xor(diagram_small);
  BOOST_CHECK(output.is_equal("{{}}"));
  poly_small = v*z - x*v + y + 1;
  diagram_small = dd_type(poly_small.set());
  output << diagram.Xor(diagram_small);
  BOOST_CHECK(output.is_equal("{{x,y,z}}"));
  poly_small = 1;
  diagram_small = dd_type(poly_small.set());
  output << diagram.Xor(diagram_small);
  BOOST_CHECK(output.is_equal("{{x,y,z}, {x,v}, {y}, {z,v}}"));
  poly_small = 0;
  diagram_small = dd_type(poly_small.set());
  output << diagram.Xor(diagram_small);
  BOOST_CHECK(output.is_equal("{{x,y,z}, {x,v}, {y}, {z,v}, {}}"));
  poly_small = x*y;
  diagram_small = dd_type(poly_small.set());
  output << diagram.Xor(diagram_small);
  BOOST_CHECK(output.is_equal("{{x,y,z}, {x,y}, {x,v}, {y}, {z,v}, {}}"));
  poly_small = w*v;
  diagram_small = dd_type(poly_small.set());
  output << diagram.Xor(diagram_small);
  BOOST_CHECK(output.is_equal("{{x,y,z}, {x,v}, {y}, {z,v}, {v,w}, {}}"));

  BOOST_TEST_MESSAGE( "implies" );
  //diagram = x*y*z + v*z - x*v + y + 1
  poly_small = 1;
  diagram_small = dd_type( poly_small.set() );
  BOOST_CHECK(diagram_small.implies(diagram));
  poly_small = x*y*z;
  diagram_small = dd_type( poly_small.set() );
  BOOST_CHECK(diagram_small.implies(diagram));
  poly_small = x*v;
  diagram_small = dd_type( poly_small.set() );
  BOOST_CHECK(diagram_small.implies(diagram));
  poly_small = y;
  diagram_small = dd_type( poly_small.set() );
  BOOST_CHECK(diagram_small.implies(diagram));
  poly_small = z*v;
  diagram_small = dd_type( poly_small.set() );
  BOOST_CHECK(diagram_small.implies(diagram));
  poly_small = x*y*z + y;
  diagram_small = dd_type( poly_small.set() );
  BOOST_CHECK(diagram_small.implies(diagram));
  poly_small = x*y*z + v*z;
  diagram_small = dd_type( poly_small.set() );
  BOOST_CHECK(diagram_small.implies(diagram));
  poly_small = x*y*z + x*v;
  diagram_small = dd_type( poly_small.set() );
  BOOST_CHECK(diagram_small.implies(diagram));
  poly_small = x*y*z + 1;
  diagram_small = dd_type( poly_small.set() );
  BOOST_CHECK(diagram_small.implies(diagram));
  poly_small = v*z - x*v;
  diagram_small = dd_type( poly_small.set() );
  BOOST_CHECK(diagram_small.implies(diagram));
  poly_small = v*z - y;
  diagram_small = dd_type( poly_small.set() );
  BOOST_CHECK(diagram_small.implies(diagram));
  poly_small = v*z - 1;
  diagram_small = dd_type( poly_small.set() );
  BOOST_CHECK(diagram_small.implies(diagram));
  poly_small = x*v - y;
  diagram_small = dd_type( poly_small.set() );
  BOOST_CHECK(diagram_small.implies(diagram));
  poly_small = x*v - 1;
  diagram_small = dd_type( poly_small.set() );
  BOOST_CHECK(diagram_small.implies(diagram));
  poly_small = y - 1;
  diagram_small = dd_type( poly_small.set() );
  BOOST_CHECK(diagram_small.implies(diagram));
  poly_small = x*y*z + v*z - x*v;
  diagram_small = dd_type( poly_small.set() );
  BOOST_CHECK(diagram_small.implies(diagram));
  poly_small = x*y*z + v*z + y;
  diagram_small = dd_type( poly_small.set() );
  BOOST_CHECK(diagram_small.implies(diagram));
  poly_small = x*y*z + v*z + 1;
  diagram_small = dd_type( poly_small.set() );
  BOOST_CHECK(diagram_small.implies(diagram));
  poly_small = x*y*z - x*v + y;
  diagram_small = dd_type( poly_small.set() );
  BOOST_CHECK(diagram_small.implies(diagram));
  poly_small = x*y*z + x*v + 1;
  diagram_small = dd_type( poly_small.set() );
  BOOST_CHECK(diagram_small.implies(diagram));
  poly_small = x*y*z  + y + 1;
  diagram_small = dd_type( poly_small.set() );
  BOOST_CHECK(diagram_small.implies(diagram));
  poly_small = v*z - x*v + y;
  diagram_small = dd_type( poly_small.set() );
  BOOST_CHECK(diagram_small.implies(diagram));
  poly_small = v*z - x*v + 1;
  diagram_small = dd_type( poly_small.set() );
  BOOST_CHECK(diagram_small.implies(diagram));
  poly_small = v*z + y + 1;
  diagram_small = dd_type( poly_small.set() );
  BOOST_CHECK(diagram_small.implies(diagram));
  poly_small = x*v + y + 1;
  diagram_small = dd_type( poly_small.set() );
  BOOST_CHECK(diagram_small.implies(diagram));
  poly_small = x*y*z + v*z - x*v + y;
  diagram_small = dd_type( poly_small.set() );
  BOOST_CHECK(diagram_small.implies(diagram));
  poly_small = x*y*z + v*z - x*v + 1;
  diagram_small = dd_type( poly_small.set() );
  BOOST_CHECK(diagram_small.implies(diagram));
  poly_small = x*y*z + v*z + y + 1;
  diagram_small = dd_type( poly_small.set() );
  BOOST_CHECK(diagram_small.implies(diagram));
  poly_small = x*y*z - x*v + y + 1;
  diagram_small = dd_type( poly_small.set() );
  BOOST_CHECK(diagram_small.implies(diagram));
  poly_small = v*z - x*v + y + 1;
  diagram_small = dd_type( poly_small.set() );
  BOOST_CHECK(diagram_small.implies(diagram));
  BOOST_CHECK(diagram.implies(diagram));
  poly_small = 0;
  diagram_small = dd_type( poly_small.set() );
  BOOST_CHECK(diagram_small.implies(diagram));
  poly_small = x*w;
  diagram_small = dd_type( poly_small.set() );
  BOOST_CHECK(!diagram_small.implies(diagram));
  poly_small = w;
  diagram_small = dd_type( poly_small.set() );
  BOOST_CHECK(!diagram_small.implies(diagram));
  poly_small = w + x*y*z;
  diagram_small = dd_type( poly_small.set() );
  BOOST_CHECK(!diagram_small.implies(diagram));
  poly_small = x*v*z;
  diagram_small = dd_type( poly_small.set() );
  BOOST_CHECK(!diagram_small.implies(diagram));
  poly_small = v;
  diagram_small = dd_type( poly_small.set() );
  BOOST_CHECK(!diagram_small.implies(diagram));
  BoolePolynomial poly_large = x;
  dd_type diagram_large = dd_type( poly_large.set() );
  poly_small = x*y + z;
  diagram_small = dd_type( poly_small.set() );
  BOOST_CHECK(!diagram_small.implies(diagram_large));
  poly_large = 0;
  diagram_large = dd_type(poly_large.set());
  BOOST_CHECK(!diagram_small.implies(diagram_large));
  BOOST_CHECK(diagram_large.implies(diagram_large));
  poly_large = w;
  diagram_large = dd_type(poly_large.set());
  BOOST_CHECK(!diagram_small.implies(diagram_large));
  poly_large = x*y;
  diagram_large = dd_type(poly_large.set());
  BOOST_CHECK(!diagram_small.implies(diagram_large));

  BOOST_TEST_MESSAGE( "==, !=" );
  BoolePolynomial poly1(0, ring);
  BoolePolynomial poly2(0, ring);
  dd_type diag1(poly1.set());
  dd_type diag2(poly2.set());
  BOOST_CHECK(diag1 == diag2);
  BOOST_CHECK_EQUAL(diag1, diag2);
  BOOST_CHECK(!(diag1 != diag2));
  poly1 = 1;
  diag1 = dd_type(poly1.set());
  BOOST_CHECK_NE(diag1, diag2);
  BOOST_CHECK(diag1 != diag2);
  BOOST_CHECK(!(diag1 == diag2));
  poly1 = x;
  poly2 = x;
  diag1 = dd_type(poly1.set());
  diag2 = dd_type(poly2.set());
  BOOST_CHECK_EQUAL(diag1, diag2);
  BOOST_CHECK(diag1 == diag2);
  BOOST_CHECK(!(diag1 != diag2));
  poly1 = x*y;
  poly2 = y*x;
  diag1 = dd_type(poly1.set());
  diag2 = dd_type(poly2.set());
  BOOST_CHECK_EQUAL(diag1, diag2);
  BOOST_CHECK(diag1 == diag2);
  BOOST_CHECK(!(diag1 != diag2));
  poly1 = x + 1;
  poly2 = x;
  diag1 = dd_type(poly1.set());
  diag2 = dd_type(poly2.set());
  BOOST_CHECK_NE(diag1, diag2);
  BOOST_CHECK(diag1 != diag2);
  BOOST_CHECK(!(diag1 == diag2));
}

BOOST_AUTO_TEST_CASE(test_refcount) {

  BoolePolynomial count1 = x*y + z - 1;
  dd_type count2(count1.set());

  BOOST_TEST_MESSAGE( "refCount" );
  BOOST_CHECK_EQUAL(count2.refCount(), 2);
  dd_type count3(count1.set());
  BOOST_CHECK_EQUAL(count2.refCount(), 3);
  BOOST_CHECK_EQUAL(count3.refCount(), 3);
  BOOST_CHECK(count2 == count3);
  BoolePolynomial count4 = count1;
  BOOST_CHECK_EQUAL(count2.refCount(), 4);
  BOOST_CHECK_EQUAL(count3.refCount(), 4);
  BoolePolynomial count5 = x*y + z - 1;
  BOOST_CHECK_EQUAL(count2.refCount(), 5);
  BOOST_CHECK_EQUAL(count3.refCount(), 5);
  count3 = count2;
  BOOST_CHECK_EQUAL(count2.refCount(), 5);
  BOOST_CHECK_EQUAL(count3.refCount(), 5);
  count1 = x*y + z;
  BOOST_CHECK_EQUAL(count2.refCount(), 4);
  BOOST_CHECK_EQUAL(count3.refCount(), 4);
  count4 = 1;
  BOOST_CHECK_EQUAL(count2.refCount(), 3);
  BOOST_CHECK_EQUAL(count3.refCount(), 3);
  count5 = z;
  BOOST_CHECK_EQUAL(count2.refCount(), 2);
  BOOST_CHECK_EQUAL(count3.refCount(), 2);
  BOOST_CHECK(count2 == count3);
  count3 = dd_type(count1.set());
  BOOST_CHECK_EQUAL(count2.refCount(), 1);
  BOOST_CHECK_EQUAL(count3.refCount(), 2);
  BOOST_CHECK(count2 != count3);
}

BOOST_AUTO_TEST_CASE(test_getters) {

  dd_type diagram(poly.set());
  BoolePolyRing other(3, 1);
  BoolePolyRing orig = ring;
  output_test_stream output;

  BOOST_TEST_MESSAGE( "ring" );
  BOOST_CHECK_EQUAL(ring.ordering().getOrderCode(), diagram.ring().ordering().getOrderCode());
  BOOST_CHECK_EQUAL(ring.nVariables(), diagram.ring().nVariables());
  ring = other;
  BOOST_CHECK_NE(ring.ordering().getOrderCode(), diagram.ring().ordering().getOrderCode());
  BOOST_CHECK_NE(ring.nVariables(), diagram.ring().nVariables());
  ring = orig;
}

BOOST_AUTO_TEST_CASE(test_size) {

  dd_type diagram(poly.set());
  set_type one_set(poly.ring());
  one_set = one_set.add(BooleMonomial(ring));
  dd_type one(one_set);

  BOOST_TEST_MESSAGE( "count, countDouble, nNodes, rootIndex" );
  BOOST_CHECK_EQUAL(diagram.count(), 5);
  BOOST_CHECK_EQUAL(one.count(), 1);
  BOOST_CHECK_EQUAL(diagram.countDouble(), 5);
  BOOST_CHECK_EQUAL(one.countDouble(), 1);
  BOOST_CHECK_EQUAL(diagram.nNodes(), 6);
  BOOST_CHECK_EQUAL(one.nNodes(), 0);
  BOOST_CHECK_EQUAL(diagram.rootIndex(), 0);
  BOOST_CHECK_EQUAL(one.rootIndex(), CUDD_MAXINDEX);

  BoolePolynomial pol(1,ring);
  diagram = dd_type(pol.set());
  BOOST_CHECK_EQUAL(diagram.nNodes(), 0);
  pol = 0;
  diagram = dd_type(pol.set());
  BOOST_CHECK_EQUAL(diagram.nNodes(), 0);
  pol = y + 1;
  diagram = dd_type(pol.set());
  BOOST_CHECK_EQUAL(diagram.nNodes(), 1);
  pol = x;
  diagram = dd_type(pol.set());
  BOOST_CHECK_EQUAL(diagram.nNodes(), 1);
  pol = y;
  diagram = dd_type(pol.set());
  BOOST_CHECK_EQUAL(diagram.nNodes(), 1);
  pol = x*y;
  diagram = dd_type(pol.set());
  BOOST_CHECK_EQUAL(diagram.nNodes(), 2);
  pol = x*y + z;
  diagram = dd_type(pol.set());
  BOOST_CHECK_EQUAL(diagram.nNodes(), 3);
}

BOOST_AUTO_TEST_SUITE_END()