1 // -*- c++ -*-
2 //*****************************************************************************
3 /** @file PseudoLongProductTest.cc
4 *
5 * @author Alexander Dreyer
6 * @date 2012-02-24
7 *
8 * boost/test-driven unit test
9 *
10 * @par Copyright:
11 * (c) 2012 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/groebner/PseudoLongProduct.h>
28 #include <polybori/groebner/PseudoLongLong.h>
29 #include <polybori/groebner/Long64From32BitsPair.h>
30 USING_NAMESPACE_PBORI
31 USING_NAMESPACE_PBORIGB
32
33 struct Fdelayedlongprod {
34 typedef unsigned long long_type;
35 unsigned nhalf;
36 unsigned nbits;
FdelayedlongprodFdelayedlongprod37 Fdelayedlongprod(): nhalf(sizeof(long_type)*4), nbits(sizeof(long_type)*8) {
38
39 BOOST_TEST_MESSAGE( "setup fixture" );
40 }
41
~FdelayedlongprodFdelayedlongprod42 ~Fdelayedlongprod() { BOOST_TEST_MESSAGE( "teardown fixture" ); }
43 };
44
45
BOOST_FIXTURE_TEST_SUITE(PseudoLongProductTest,Fdelayedlongprod)46 BOOST_FIXTURE_TEST_SUITE(PseudoLongProductTest, Fdelayedlongprod)
47
48 BOOST_AUTO_TEST_CASE(test_less) {
49
50 BOOST_TEST_MESSAGE( "operator<..." );
51
52 BOOST_CHECK_EQUAL((PseudoLongProduct(long_type(-1),
53 long_type(-1)) >
54 PseudoLongLong<long_type(-1), long_type(-1)>()), false);
55
56 BOOST_CHECK_EQUAL((PseudoLongProduct(long_type(-1),
57 long_type(-1)) >
58 PseudoLongLong<long_type(-1), 0>()), false);
59
60
61 BOOST_CHECK_EQUAL((PseudoLongProduct(long_type(-1),
62 long_type(-1)) >
63 PseudoLongLong<long_type(-1)/2,
64 long_type(-1)>()), true);
65
66 BOOST_CHECK_EQUAL((PseudoLongProduct(long_type(2)<< nhalf,
67 long_type(2)<< nhalf) >
68 PseudoLongLong<3,long_type(-1)>()), true);
69
70 BOOST_CHECK_EQUAL((PseudoLongProduct(long_type(2)<< nhalf ,
71 long_type(2)<< nhalf ) >
72 PseudoLongLong<4,0>()), false);
73
74 BOOST_CHECK_EQUAL((PseudoLongProduct(long_type(2)<< nhalf,
75 long_type(2)<< nhalf )>
76 PseudoLongLong<4,1>()), false);
77
78 BOOST_CHECK_EQUAL((PseudoLongProduct(5, 7) > 34), true);
79 BOOST_CHECK_EQUAL((PseudoLongProduct(5, 7) > 35), false);
80 BOOST_CHECK_EQUAL((PseudoLongProduct(5, 7) > 36), false);
81
82 BOOST_CHECK_EQUAL((PseudoLongProduct(long_type(5)<<nhalf, 7) >
83 long_type(34)<<nhalf), true);
84 BOOST_CHECK_EQUAL((PseudoLongProduct(long_type(5)<<nhalf, 7) >
85 long_type(35)<<nhalf), false);
86 BOOST_CHECK_EQUAL((PseudoLongProduct(long_type(5)<<nhalf, 7) >
87 long_type(36)<<nhalf), false);
88
89 BOOST_CHECK_EQUAL((PseudoLongProduct(long_type(5)<<(nhalf - 4), long_type(7)<<(nhalf-4)) >
90 long_type(34)<<(nbits - 8)), true);
91 BOOST_CHECK_EQUAL((PseudoLongProduct(long_type(5)<<(nhalf - 4), long_type(7)<<(nhalf-4)) >
92 long_type(35)<<(nbits - 8)), false);
93 BOOST_CHECK_EQUAL((PseudoLongProduct(long_type(5)<<(nhalf - 4), long_type(7)<<(nhalf-4)) >
94 long_type(36)<<(nbits - 8)), false);
95
96
97 BOOST_CHECK_EQUAL((PseudoLongProduct(long_type(3)<<16, long_type(1)<<16) >
98 Long64From32BitsPair<4, 0>::get()), false);
99 BOOST_CHECK_EQUAL((PseudoLongProduct(long_type(4)<<16, long_type(1)<<16) >
100 Long64From32BitsPair<4, 0>::get()), false);
101 BOOST_CHECK_EQUAL((PseudoLongProduct(long_type(5)<<16, long_type(1)<<16) >
102 Long64From32BitsPair<4, 0>::get()), true);
103
104
105 }
106
107 BOOST_AUTO_TEST_SUITE_END()
108