1 // -*- c++ -*-
2 //*****************************************************************************
3 /** @file BlockDegRevLexAscOrderTest.cc
4 *
5 * @author Ket Shcherbakova, Alexander Dreyer
6 * @date 2010-12-14
7 *
8 * boost/test-driven unit test
9 *
10 * @par Copyright:
11 * (c) 2010 by The PolyBoRi Team
12 *
13 **/
14 //*****************************************************************************
15
16
17 #include <boost/test/unit_test.hpp>
18 #include <boost/version.hpp>
19 #if BOOST_VERSION < 107100
20 #include <boost/test/output_test_stream.hpp>
21 #else
22 #include <boost/test/tools/output_test_stream.hpp>
23 #endif
24
25 using boost::test_tools::output_test_stream;
26
27 #include <polybori/BlockDegRevLexAscOrder.h>
28 #include <polybori/DegRevLexAscOrder.h>
29
30 USING_NAMESPACE_PBORI
31
32 struct Fblockdegrevlex {
33 typedef BlockDegRevLexAscOrder order_type;
34 typedef DegRevLexAscOrder base_order_type;
FblockdegrevlexFblockdegrevlex35 Fblockdegrevlex(const BoolePolyRing& input_ring =
36 BoolePolyRing(5, COrderEnums::dlex)):
37 ring(input_ring),
38 x(0, input_ring), y(1, input_ring), z(2, input_ring),
39 v(3, input_ring), w(4, input_ring) {
40
41 BOOST_TEST_MESSAGE( "setup fixture" );
42 ring.setVariableName(0, "x");
43 ring.setVariableName(1, "y");
44 ring.setVariableName(2, "z");
45 ring.setVariableName(3, "v");
46 ring.setVariableName(4, "w");
47 }
~FblockdegrevlexFblockdegrevlex48 ~Fblockdegrevlex() { BOOST_TEST_MESSAGE( "teardown fixture" ); }
49
50 BoolePolyRing ring;
51 BooleVariable x, y, z, v, w;
52 };
53
BOOST_FIXTURE_TEST_SUITE(BlockDegRevLexOrderTestSuite,Fblockdegrevlex)54 BOOST_FIXTURE_TEST_SUITE(BlockDegRevLexOrderTestSuite, Fblockdegrevlex )
55
56 BOOST_AUTO_TEST_CASE(test_properties) {
57
58 order_type order;
59 BOOST_TEST_MESSAGE( "isLexicographical, isSymmetric, isDegreeOrder, isBlockOrder, isTotalDegreeOrder, isDegreeReverseLexicographical, ascendingVariables, descendingVariables, orderedStandardIteration" );
60 BOOST_CHECK(!order.isLexicographical());
61 BOOST_CHECK(!order.isSymmetric());
62 BOOST_CHECK(!order.isDegreeOrder());
63 BOOST_CHECK(order.isBlockOrder());
64 BOOST_CHECK(!order.isTotalDegreeOrder());
65 BOOST_CHECK(!order.isDegreeReverseLexicographical());
66 BOOST_CHECK(order.ascendingVariables());
67 BOOST_CHECK(!order.descendingVariables());
68 BOOST_CHECK(!order.orderedStandardIteration());
69 }
70
BOOST_AUTO_TEST_CASE(test_getters)71 BOOST_AUTO_TEST_CASE(test_getters) {
72
73 order_type order;
74 BOOST_TEST_MESSAGE( "getOrderCode, getBaseOrderCode" );
75 BOOST_CHECK_EQUAL(order.getOrderCode(), COrderEnums::block_dp_asc);
76 BOOST_CHECK_EQUAL(order.getBaseOrderCode(), COrderEnums::dp_asc);
77 }
78
BOOST_AUTO_TEST_CASE(test_compare)79 BOOST_AUTO_TEST_CASE(test_compare) {
80
81 order_type order;
82 base_order_type baseorder;
83 BOOST_TEST_MESSAGE( "compare" );
84 BooleMonomial monom1 = x;
85 BooleMonomial monom2 = x*x;
86 BOOST_CHECK_EQUAL(order.compare(monom1, monom2), CTypes::equality);
87 BOOST_CHECK_EQUAL(order.compare(monom1,monom2), baseorder.compare(monom1,monom2));
88 monom1 = x*y;
89 monom2 = x*z*v;
90 BOOST_CHECK_EQUAL(order.compare(monom1, monom2), CTypes::less_than);
91 BOOST_CHECK_EQUAL(order.compare(monom1,monom2), baseorder.compare(monom1,monom2));
92 monom1 = v*y;
93 monom2 = x;
94 BOOST_CHECK_EQUAL(order.compare(monom1, monom2), CTypes::greater_than);
95 BOOST_CHECK_EQUAL(order.compare(monom1,monom2), baseorder.compare(monom1,monom2));
96 monom1 = BooleMonomial(ring);
97 monom2 = w;
98 BOOST_CHECK_EQUAL(order.compare(monom1, monom2), CTypes::less_than);
99 BOOST_CHECK_EQUAL(order.compare(monom1,monom2), baseorder.compare(monom1,monom2));
100 monom1 = BooleMonomial(ring);
101 monom2 = BooleMonomial(ring);
102 BOOST_CHECK_EQUAL(order.compare(monom1, monom2), CTypes::equality);
103 BOOST_CHECK_EQUAL(order.compare(monom1,monom2), baseorder.compare(monom1,monom2));
104 BooleExponent exp1(x);
105 BooleExponent exp2(x*x);
106 BOOST_CHECK_EQUAL(order.compare(exp1, exp2), CTypes::equality);
107 BOOST_CHECK_EQUAL(order.compare(exp1,exp2), baseorder.compare(exp1,exp2));
108 exp1 = BooleExponent(w*x);
109 exp2 = BooleExponent(v*x);
110 BOOST_CHECK_EQUAL(order.compare(exp1, exp2), CTypes::greater_than);
111 BOOST_CHECK_EQUAL(order.compare(exp1,exp2), baseorder.compare(exp1,exp2));
112 exp1 = BooleExponent(x*y*z*v*w);
113 exp2 = BooleExponent(x*y*z*v);
114 BOOST_CHECK_EQUAL(order.compare(exp1, exp2), CTypes::greater_than);
115 BOOST_CHECK_EQUAL(order.compare(exp1,exp2), baseorder.compare(exp1,exp2));
116 BOOST_CHECK_EQUAL(order.compare(0,1), CTypes::less_than);
117 BOOST_CHECK_EQUAL(order.compare(0,1), baseorder.compare(0,1));
118 BOOST_CHECK_EQUAL(order.compare(2,1), CTypes::greater_than);
119 BOOST_CHECK_EQUAL(order.compare(2,1), baseorder.compare(2,1));
120 BOOST_CHECK_EQUAL(order.compare(-1,-1), CTypes::equality);
121 BOOST_CHECK_EQUAL(order.compare(-1,-1), baseorder.compare(-1,-1));
122 BOOST_CHECK_EQUAL(order.compare(1,-1), CTypes::greater_than);
123 BOOST_CHECK_EQUAL(order.compare(-1,-1), baseorder.compare(-1,-1));
124 }
125
BOOST_AUTO_TEST_CASE(test_lead)126 BOOST_AUTO_TEST_CASE(test_lead) {
127
128 BOOST_TEST_MESSAGE( "lead, leadExp, leadFirst" );
129 order_type order;
130 BoolePolynomial poly = x*y*z*w + x*x + x*y + y*z*v*w + 1;
131 BOOST_CHECK_EQUAL(order.lead(poly) , BooleMonomial(y*z*v*w));
132 BOOST_CHECK_EQUAL(order.lead(poly,1) , BooleMonomial(y*z*v*w));
133 BOOST_CHECK_EQUAL(order.lead(poly,-1), BooleMonomial(y*z*v*w));
134 BOOST_CHECK_EQUAL(order.leadExp(poly) , BooleExponent(y*z*v*w));
135 BOOST_CHECK_EQUAL(order.leadExp(poly,1) , BooleExponent(y*z*v*w));
136 BOOST_CHECK_EQUAL(order.leadExp(poly,-1), BooleExponent(y*z*v*w));
137 BOOST_CHECK_EQUAL(order.leadFirst(poly) , BoolePolynomial(y*z*v*w));
138 poly = BoolePolynomial(ring);
139 BOOST_CHECK_THROW(order.lead(poly), PBoRiGenericError<CTypes::illegal_on_zero>);
140 BOOST_CHECK_THROW(order.lead(poly,1),PBoRiGenericError<CTypes::illegal_on_zero>);
141 BOOST_CHECK_THROW(order.lead(poly),PBoRiGenericError<CTypes::illegal_on_zero>);
142 BOOST_CHECK_THROW(order.leadExp(poly,1),PBoRiGenericError<CTypes::illegal_on_zero>);
143 BOOST_CHECK_THROW(order.leadExp(poly),PBoRiGenericError<CTypes::illegal_on_zero>);
144 BOOST_CHECK_THROW(order.leadFirst(poly),PBoRiGenericError<CTypes::illegal_on_zero>);
145 poly = 1;
146 BOOST_CHECK_EQUAL(order.lead(poly, 1), BooleMonomial(ring));
147 BOOST_CHECK_EQUAL(order.lead(poly), BooleMonomial(ring));
148 BOOST_CHECK_EQUAL(order.leadExp(poly,1), BooleExponent());
149 BOOST_CHECK_EQUAL(order.leadExp(poly), BooleExponent());
150 BOOST_CHECK_EQUAL(order.leadFirst(poly), poly);
151 poly = x*w + x*z + w*v*y;
152 BOOST_CHECK_EQUAL(order.lead(poly, 0), BooleMonomial(w*v*y));
153 BOOST_CHECK_EQUAL(order.leadExp(poly, 0), BooleExponent(w*v*y));
154 }
155
BOOST_AUTO_TEST_CASE(test_blocks)156 BOOST_AUTO_TEST_CASE(test_blocks) {
157
158 BOOST_TEST_MESSAGE( "blockBegin, blockEnd, appendBlock, clearBlocks, lastBlockStart, lieInSameBlock" );
159 order_type order;
160 output_test_stream output;
161 output_test_stream output_test;
162 int intmax = CUDD_MAXINDEX;
163 BoolePolyRing::block_iterator start(order.blockBegin()),finish(order.blockEnd());
164 order.clearBlocks();
165 start = order.blockBegin();
166 finish = order.blockEnd();
167 while (start != finish) {
168 output << *start <<", ";
169 ++start;
170 }
171 output_test.str("");
172 output_test << intmax << ", ";
173 BOOST_CHECK(output.is_equal(output_test.str()));
174 // std::cout << "fin " << *finish << " fin-1 " << *(finish-1) << " fin-2 " << *(finish-2);;
175 BOOST_CHECK_THROW(order.appendBlock(-1), std::exception);
176 BOOST_CHECK_THROW(order.appendBlock(0), std::runtime_error);
177 order.appendBlock(2);
178 BOOST_CHECK_THROW(order.appendBlock(1), std::runtime_error);
179 order.appendBlock(6);
180 BOOST_CHECK_THROW(order.appendBlock(6), std::runtime_error);
181 BOOST_CHECK_THROW(order.appendBlock(intmax), std::runtime_error);
182 start = order.blockBegin();
183 finish = order.blockEnd();
184 while (start != finish) {
185 output << *start <<", ";
186 ++start;
187 }
188 output_test.str("");
189 output_test << "2, 6, " << intmax << ", ";
190 BOOST_CHECK(output.is_equal(output_test.str()));
191 BOOST_CHECK(order.lieInSameBlock(0,1));
192 BOOST_CHECK(!order.lieInSameBlock(1,2));
193 BOOST_CHECK(order.lieInSameBlock(3,2));
194 BOOST_CHECK(order.lieInSameBlock(4,3));
195 BOOST_CHECK(order.lieInSameBlock(4,5));
196 BOOST_CHECK(!order.lieInSameBlock(5,6));
197 BOOST_CHECK(order.lieInSameBlock(6,7));
198 BOOST_CHECK(!order.lieInSameBlock(7,intmax));
199 BOOST_CHECK_THROW(order.lieInSameBlock(-1,3), std::runtime_error);
200 BOOST_CHECK_THROW(order.lieInSameBlock(-1,intmax), std::runtime_error);
201 BOOST_CHECK_THROW(order.lieInSameBlock(-1,-1), std::runtime_error);
202 BOOST_CHECK_EQUAL(order.lastBlockStart(), 6);
203 }
204
BOOST_AUTO_TEST_CASE(test_compare_blocks)205 BOOST_AUTO_TEST_CASE(test_compare_blocks) {
206
207 BOOST_TEST_MESSAGE( "compare with appended blocks" );
208 order_type blockorder;//(x,y)(z,v,w)(5-intmax)
209 order_type order;
210 blockorder.appendBlock(2);
211 blockorder.appendBlock(6);
212 // Variable comparison -> variables in different blocks dont follow the ascending order
213 BooleMonomial monom1 = x;
214 BooleMonomial monom2 = y;
215 BooleExponent exp1(monom1);
216 BooleExponent exp2(monom2);
217 BOOST_CHECK_EQUAL(blockorder.compare(monom1, monom2), CTypes::less_than);
218 BOOST_CHECK_EQUAL(order.compare(monom1, monom2), blockorder.compare(monom1, monom2));
219 BOOST_CHECK_EQUAL(blockorder.compare(exp1, exp2), blockorder.compare(monom1, monom2));
220 BOOST_CHECK_EQUAL(order.compare(exp1, exp2), blockorder.compare(exp1, exp2));
221 monom1 = x;
222 monom2 = v;
223 exp1 = monom1;
224 exp2 = monom2;
225 BOOST_CHECK_EQUAL(blockorder.compare(monom1, monom2), CTypes::greater_than);
226 BOOST_CHECK_NE(order.compare(monom1, monom2), blockorder.compare(monom1, monom2));
227 BOOST_CHECK_EQUAL(blockorder.compare(exp1, exp2), blockorder.compare(monom1, monom2));
228 BOOST_CHECK_NE(order.compare(exp1, exp2), blockorder.compare(exp1, exp2));
229 monom1 = z;
230 monom2 = v;
231 exp1 = monom1;
232 exp2 = monom2;
233 BOOST_CHECK_EQUAL(blockorder.compare(monom1, monom2), CTypes::less_than);
234 BOOST_CHECK_EQUAL(order.compare(monom1, monom2), blockorder.compare(monom1, monom2));
235 BOOST_CHECK_EQUAL(blockorder.compare(exp1, exp2), blockorder.compare(monom1, monom2));
236 BOOST_CHECK_EQUAL(order.compare(exp1, exp2), blockorder.compare(exp1, exp2));
237 monom1 = x;
238 monom2 = x*x;
239 exp1 = monom1;
240 exp2 = monom2;
241 BOOST_CHECK_EQUAL(blockorder.compare(monom1, monom2), CTypes::equality);
242 BOOST_CHECK_EQUAL(order.compare(monom1, monom2), blockorder.compare(monom1, monom2));
243 BOOST_CHECK_EQUAL(blockorder.compare(exp1, exp2), blockorder.compare(monom1, monom2));
244 BOOST_CHECK_EQUAL(order.compare(exp1, exp2), blockorder.compare(exp1, exp2));
245 monom1 = z;
246 monom2 = z*z;
247 exp1 = monom1;
248 exp2 = monom2;
249 BOOST_CHECK_EQUAL(blockorder.compare(monom1, monom2), CTypes::equality);
250 BOOST_CHECK_EQUAL(order.compare(monom1, monom2), blockorder.compare(monom1, monom2));
251 BOOST_CHECK_EQUAL(blockorder.compare(exp1, exp2), blockorder.compare(monom1, monom2));
252 BOOST_CHECK_EQUAL(order.compare(exp1, exp2), blockorder.compare(exp1, exp2));
253 monom1 = x;
254 monom2 = BooleMonomial(ring);
255 exp1 = monom1;
256 exp2 = monom2;
257 BOOST_CHECK_EQUAL(blockorder.compare(monom1, monom2), CTypes::greater_than);
258 BOOST_CHECK_EQUAL(order.compare(monom1, monom2), blockorder.compare(monom1, monom2));
259 BOOST_CHECK_EQUAL(blockorder.compare(exp1, exp2), blockorder.compare(monom1, monom2));
260 BOOST_CHECK_EQUAL(order.compare(exp1, exp2), blockorder.compare(exp1, exp2));
261 monom1 = BooleMonomial(ring);
262 monom2 = BooleMonomial(ring);
263 exp1 = monom1;
264 exp2 = monom2;
265 BOOST_CHECK_EQUAL(blockorder.compare(monom1, monom2), CTypes::equality);
266 BOOST_CHECK_EQUAL(order.compare(monom1, monom2), blockorder.compare(monom1, monom2));
267 BOOST_CHECK_EQUAL(blockorder.compare(exp1, exp2), blockorder.compare(monom1, monom2));
268 BOOST_CHECK_EQUAL(order.compare(exp1, exp2), blockorder.compare(exp1, exp2));
269 // Different first blocks -> blockorder result may differ from order
270 monom1 = x*y;
271 monom2 = y*z;
272 exp1 = monom1;
273 exp2 = monom2;
274 BOOST_CHECK_EQUAL(blockorder.compare(monom1, monom2), CTypes::greater_than);
275 BOOST_CHECK_NE(order.compare(monom1, monom2), blockorder.compare(monom1, monom2));
276 BOOST_CHECK_EQUAL(blockorder.compare(exp1, exp2), blockorder.compare(monom1, monom2));
277 BOOST_CHECK_NE(order.compare(exp1, exp2), blockorder.compare(exp1, exp2));
278 monom1 = x*y;
279 monom2 = y*z*v*w;
280 exp1 = monom1;
281 exp2 = monom2;
282 BOOST_CHECK_EQUAL(blockorder.compare(monom1, monom2), CTypes::greater_than);
283 BOOST_CHECK_NE(order.compare(monom1, monom2), blockorder.compare(monom1, monom2));
284 BOOST_CHECK_EQUAL(blockorder.compare(exp1, exp2), blockorder.compare(monom1, monom2));
285 BOOST_CHECK_NE(order.compare(exp1, exp2), blockorder.compare(exp1, exp2));
286 monom1 = y*v*w;
287 monom2 = x*v*w;
288 exp1 = monom1;
289 exp2 = monom2;
290 BOOST_CHECK_EQUAL(blockorder.compare(monom1, monom2), CTypes::greater_than);
291 BOOST_CHECK_EQUAL(order.compare(monom1, monom2), blockorder.compare(monom1, monom2));
292 BOOST_CHECK_EQUAL(blockorder.compare(exp1, exp2), blockorder.compare(monom1, monom2));
293 BOOST_CHECK_EQUAL(order.compare(exp1, exp2), blockorder.compare(exp1, exp2));
294 monom1 = x*y*v*w;
295 monom2 = y*v*w;
296 exp1 = monom1;
297 exp2 = monom2;
298 BOOST_CHECK_EQUAL(blockorder.compare(monom1, monom2), CTypes::greater_than);
299 BOOST_CHECK_EQUAL(order.compare(monom1, monom2), blockorder.compare(monom1, monom2));
300 BOOST_CHECK_EQUAL(blockorder.compare(exp1, exp2), blockorder.compare(monom1, monom2));
301 BOOST_CHECK_EQUAL(order.compare(exp1, exp2), blockorder.compare(exp1, exp2));
302 monom1 = BooleMonomial(ring);
303 monom2 = y*v*w;
304 exp1 = monom1;
305 exp2 = monom2;
306 BOOST_CHECK_EQUAL(blockorder.compare(monom1, monom2), CTypes::less_than);
307 BOOST_CHECK_EQUAL(order.compare(monom1, monom2), blockorder.compare(monom1, monom2));
308 BOOST_CHECK_EQUAL(blockorder.compare(exp1, exp2), blockorder.compare(monom1, monom2));
309 BOOST_CHECK_EQUAL(order.compare(exp1, exp2), blockorder.compare(exp1, exp2));
310 // Same first blocks -> blockorder=order
311 monom1 = x*v;
312 monom2 = x*w;
313 exp1 = monom1;
314 exp2 = monom2;
315 BOOST_CHECK_EQUAL(blockorder.compare(monom1, monom2), CTypes::less_than);
316 BOOST_CHECK_EQUAL(order.compare(monom1, monom2), blockorder.compare(monom1, monom2));
317 BOOST_CHECK_EQUAL(blockorder.compare(exp1, exp2), blockorder.compare(monom1, monom2));
318 BOOST_CHECK_EQUAL(order.compare(exp1, exp2), blockorder.compare(exp1, exp2));
319 monom1 = x*z*v;
320 monom2 = x*w;
321 exp1 = monom1;
322 exp2 = monom2;
323 BOOST_CHECK_EQUAL(blockorder.compare(monom1, monom2), CTypes::greater_than);
324 BOOST_CHECK_EQUAL(order.compare(monom1, monom2), blockorder.compare(monom1, monom2));
325 BOOST_CHECK_EQUAL(blockorder.compare(exp1, exp2), blockorder.compare(monom1, monom2));
326 BOOST_CHECK_EQUAL(order.compare(exp1, exp2), blockorder.compare(exp1, exp2));
327 monom1 = y*v;
328 monom2 = y*z*v;
329 exp1 = monom1;
330 exp2 = monom2;
331 BOOST_CHECK_EQUAL(blockorder.compare(monom1, monom2), CTypes::less_than);
332 BOOST_CHECK_EQUAL(order.compare(monom1, monom2), blockorder.compare(monom1, monom2));
333 BOOST_CHECK_EQUAL(blockorder.compare(exp1, exp2), blockorder.compare(monom1, monom2));
334 BOOST_CHECK_EQUAL(order.compare(exp1, exp2), blockorder.compare(exp1, exp2));
335 monom1 = x*y*v;
336 monom2 = x*y*w;
337 exp1 = monom1;
338 exp2 = monom2;
339 BOOST_CHECK_EQUAL(blockorder.compare(monom1, monom2), CTypes::less_than);
340 BOOST_CHECK_EQUAL(order.compare(monom1, monom2), blockorder.compare(monom1, monom2));
341 BOOST_CHECK_EQUAL(blockorder.compare(exp1, exp2), blockorder.compare(monom1, monom2));
342 BOOST_CHECK_EQUAL(order.compare(exp1, exp2), blockorder.compare(exp1, exp2));
343 monom1 = x*y;
344 monom2 = x*y*w;
345 exp1 = monom1;
346 exp2 = monom2;
347 BOOST_CHECK_EQUAL(blockorder.compare(monom1, monom2), CTypes::less_than);
348 BOOST_CHECK_EQUAL(order.compare(monom1, monom2), blockorder.compare(monom1, monom2));
349 BOOST_CHECK_EQUAL(blockorder.compare(exp1, exp2), blockorder.compare(monom1, monom2));
350 BOOST_CHECK_EQUAL(order.compare(exp1, exp2), blockorder.compare(exp1, exp2));
351 monom1 = x*y*w;
352 monom2 = x*y*w;
353 exp1 = monom1;
354 exp2 = monom2;
355 BOOST_CHECK_EQUAL(blockorder.compare(monom1, monom2), CTypes::equality);
356 BOOST_CHECK_EQUAL(order.compare(monom1, monom2), blockorder.compare(monom1, monom2));
357 BOOST_CHECK_EQUAL(blockorder.compare(exp1, exp2), blockorder.compare(monom1, monom2));
358 BOOST_CHECK_EQUAL(order.compare(exp1, exp2), blockorder.compare(exp1, exp2));
359 BOOST_CHECK_EQUAL(blockorder.compare(0,1), CTypes::less_than);
360 BOOST_CHECK_EQUAL(order.compare(0,1), blockorder.compare(0,1));
361 BOOST_CHECK_EQUAL(blockorder.compare(1,2), CTypes::greater_than);
362 BOOST_CHECK_NE(order.compare(1,2), blockorder.compare(1,2));
363 BOOST_CHECK_EQUAL(blockorder.compare(2,3), CTypes::less_than);
364 BOOST_CHECK_EQUAL(order.compare(2,3), blockorder.compare(2,3));
365 BOOST_CHECK_EQUAL(blockorder.compare(3,4), CTypes::less_than);
366 BOOST_CHECK_EQUAL(order.compare(3,4), blockorder.compare(3,4));
367 BOOST_CHECK_EQUAL(blockorder.compare(4,5), CTypes::less_than);
368 BOOST_CHECK_EQUAL(order.compare(4,5), blockorder.compare(4,5));
369 BOOST_CHECK_EQUAL(blockorder.compare(5,6), CTypes::greater_than);
370 BOOST_CHECK_NE(order.compare(5,6), blockorder.compare(5,6));
371 BOOST_CHECK_EQUAL(blockorder.compare(6,7), CTypes::less_than);
372 BOOST_CHECK_EQUAL(order.compare(6,7), blockorder.compare(6,7));
373 BOOST_CHECK_EQUAL(blockorder.compare(7,-1), CTypes::less_than);
374 // note: no need to have order.compare(7,-1) == blockorder.compare(7,-1)
375 BOOST_CHECK_EQUAL(blockorder.compare(1,1), CTypes::equality);
376 BOOST_CHECK_EQUAL(order.compare(1,1), blockorder.compare(1,1));
377 BOOST_CHECK_EQUAL(blockorder.compare(3,3), CTypes::equality);
378 BOOST_CHECK_EQUAL(order.compare(3,3), blockorder.compare(3,3));
379 BOOST_CHECK_EQUAL(blockorder.compare(7,7), CTypes::equality);
380 BOOST_CHECK_EQUAL(order.compare(7,7), blockorder.compare(7,7));
381 BOOST_CHECK_EQUAL(blockorder.compare(-1,-1), CTypes::equality);
382 BOOST_CHECK_EQUAL(order.compare(-1,-1), blockorder.compare(-1,-1));
383 }
384
BOOST_AUTO_TEST_CASE(test_lead_blocks)385 BOOST_AUTO_TEST_CASE(test_lead_blocks) {
386
387 BOOST_TEST_MESSAGE( "lead with appended blocks" );
388 order_type blockorder;//(x,y)(z,v,w)(5-intmax)
389 order_type order;
390 blockorder.appendBlock(2);
391 blockorder.appendBlock(6);
392
393 BoolePolynomial poly = BoolePolynomial(ring);
394 BOOST_CHECK_THROW(blockorder.lead(poly,1),PBoRiGenericError<CTypes::illegal_on_zero>);
395 BOOST_CHECK_THROW(blockorder.lead(poly),PBoRiGenericError<CTypes::illegal_on_zero>);
396 BOOST_CHECK_THROW(blockorder.leadExp(poly,1),PBoRiGenericError<CTypes::illegal_on_zero>);
397 BOOST_CHECK_THROW(blockorder.leadExp(poly),PBoRiGenericError<CTypes::illegal_on_zero>);
398 BOOST_CHECK_THROW(blockorder.leadFirst(poly),PBoRiGenericError<CTypes::illegal_on_zero>);
399 poly = 1;
400 BOOST_CHECK_EQUAL(blockorder.lead(poly, 1), BooleMonomial(ring));
401 BOOST_CHECK_EQUAL(blockorder.lead(poly), BooleMonomial(ring));
402 BOOST_CHECK_EQUAL(blockorder.leadExp(poly,1), BooleExponent());
403 BOOST_CHECK_EQUAL(blockorder.leadExp(poly), BooleExponent());
404 BOOST_CHECK_EQUAL(blockorder.leadFirst(poly), poly);
405 poly = y*x + y*z*v*w + v*w + z*w + w*w; /// y*x > y*z*v*w for blockorder
406 BOOST_CHECK_EQUAL(order.lead(poly), BooleMonomial(y*z*v*w));
407 BOOST_CHECK_EQUAL(blockorder.lead(poly, 0), BooleMonomial(x*y));
408 BOOST_CHECK_NE(blockorder.lead(poly, 0), order.lead(poly, 0));
409 BOOST_CHECK_EQUAL(blockorder.leadExp(poly, 0), BooleExponent(x*y));
410 BOOST_CHECK_NE(blockorder.leadExp(poly, 0), order.leadExp(poly, 0));
411 }
412
413
BOOST_AUTO_TEST_CASE(test_cover_constructors_and_destructors)414 BOOST_AUTO_TEST_CASE(test_cover_constructors_and_destructors) {
415 int order_code = CTypes::block_dp_asc;
416 BoolePolyRing block_ring(5, order_code);
417
418 BOOST_CHECK_EQUAL(block_ring.ordering().getOrderCode(), order_code);
419
420 class Inherited: public order_type {};
421
422 Inherited dummy;
423 BOOST_CHECK_EQUAL(dummy.getOrderCode(), order_code);
424
425 order_type self;
426 BOOST_CHECK_EQUAL(self.getOrderCode(), order_code);
427
428 order_type* pSelf = new order_type;
429 BOOST_CHECK_EQUAL(pSelf->getOrderCode(), order_code);
430 delete pSelf;
431
432 pSelf = new Inherited;
433 BOOST_CHECK_EQUAL(pSelf->getOrderCode(), order_code);
434 delete pSelf;
435
436 Inherited* pDummy = new Inherited;
437 BOOST_CHECK_EQUAL(pDummy->getOrderCode(), order_code);
438 delete pDummy;
439 }
440
441 BOOST_AUTO_TEST_SUITE_END()
442