8 #include <boost/test/unit_test.hpp>
28 "\x9c\x52\x4a\xdb\xcf\x56\x11\x12\x2b\x29\x12\x5e\x5d\x35\xd2\xd2"
29 "\x22\x81\xaa\xb5\x33\xf0\x08\x32\xd5\x56\xb1\xf9\xea\xe5\x1d\x7d";
30 const char R1ArrayHex[] =
"7D1DE5EAF9B156D53208F033B5AA8122D2d2355d5e12292b121156cfdb4a529c";
33 const uint64_t
R1LLow64 = 0x121156cfdb4a529cULL;
36 "\x70\x32\x1d\x7c\x47\xa5\x6b\x40\x26\x7e\x0a\xc3\xa6\x9c\xb6\xbf"
37 "\x13\x30\x47\xa3\x19\x2d\xda\x71\x49\x13\x72\xf0\xb4\xca\x81\xd7";
40 const char R1LplusR2L[] =
"549FB09FEA236A1EA3E31D4D58F1B1369288D204211CA751527CFC175767850C";
43 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
44 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
48 "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
49 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
53 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
54 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff";
58 static std::string
ArrayToString(
const unsigned char A[],
unsigned int width)
60 std::stringstream Stream;
62 for (
unsigned int i = 0; i < width; ++i)
64 Stream<<std::setw(2)<<std::setfill(
'0')<<(
unsigned int)A[width-i-1];
88 uint64_t Tmp64 = 0xc4dab720d9c7acaaULL;
89 for (
unsigned int i = 0; i < 256; ++i)
127 static void shiftArrayRight(
unsigned char* to,
const unsigned char* from,
unsigned int arrayLength,
unsigned int bitsToShift)
129 for (
unsigned int T=0;
T < arrayLength; ++
T)
131 unsigned int F = (
T+bitsToShift/8);
133 to[
T] = uint8_t(from[F] >> (bitsToShift % 8));
136 if (F + 1 < arrayLength)
137 to[
T] |= uint8_t(from[(F + 1)] << (8 - bitsToShift % 8));
141 static void shiftArrayLeft(
unsigned char* to,
const unsigned char* from,
unsigned int arrayLength,
unsigned int bitsToShift)
143 for (
unsigned int T=0;
T < arrayLength; ++
T)
145 if (
T >= bitsToShift/8)
147 unsigned int F =
T-bitsToShift/8;
148 to[
T] = uint8_t(from[F] << (bitsToShift % 8));
149 if (
T >= bitsToShift/8+1)
150 to[
T] |= uint8_t(from[F - 1] >> (8 - bitsToShift % 8));
159 unsigned char TmpArray[32];
161 for (
unsigned int i = 0; i < 256; ++i)
165 TmpL =
OneL; TmpL <<= i;
168 TmpL =
HalfL; TmpL >>= (255-i);
173 TmpL =
R1L; TmpL <<= i;
178 TmpL =
R1L; TmpL >>= i;
183 TmpL =
MaxL; TmpL <<= i;
188 TmpL =
MaxL; TmpL >>= i;
193 for (
unsigned int i = 0; i < 128; ++i) {
196 for (
unsigned int i = 128; i < 256; ++i) {
205 unsigned char TmpArray[32];
206 for (
unsigned int i = 0; i < 32; ++i) { TmpArray[i] = uint8_t(~
R1Array[i]); }
211 for (
unsigned int i = 0; i < 256; ++i)
218 #define CHECKBITWISEOPERATOR(_A_,_B_,_OP_) \
219 for (unsigned int i = 0; i < 32; ++i) { TmpArray[i] = uint8_t(_A_##Array[i] _OP_ _B_##Array[i]); } \
220 BOOST_CHECK(arith_uint256V(std::vector<unsigned char>(TmpArray,TmpArray+32)) == (_A_##L _OP_ _B_##L));
222 #define CHECKASSIGNMENTOPERATOR(_A_,_B_,_OP_) \
223 TmpL = _A_##L; TmpL _OP_##= _B_##L; BOOST_CHECK(TmpL == (_A_##L _OP_ _B_##L));
227 unsigned char TmpArray[32];
262 uint64_t Tmp64 = 0xe1db685c9a0b47a2ULL;
272 for (
unsigned int i = 0; i < 256; ++i) {
275 BOOST_CHECK( TmpL >= 0 && TmpL > 0 && 0 < TmpL && 0 <= TmpL);
293 for (
unsigned int i = 1; i < 256; ++i) {
298 TmpL = (
MaxL>>i); TmpL += 1;
305 TmpL =
arith_uint256(0xbedc77e27940a7ULL); TmpL += 0xee8d836fce66fbULL;
307 TmpL -= 0xee8d836fce66fbULL;
BOOST_CHECK(TmpL == 0xbedc77e27940a7ULL);
314 for (
unsigned int i = 1; i < 256; ++i) {
317 TmpL = (
HalfL >> (i-1));
320 TmpL = (
HalfL >> (i-1));
345 BOOST_CHECK((
R2L * 0x87654321UL).
ToString() ==
"23f7816e30c4ae2017257b7a0fa64d60402f5234d46e746b61c960d09a26d070");
352 BOOST_CHECK((
R1L / D1L).
ToString() ==
"00000000000000000b8ac01106981635d9ed112290f8895545a7654dde28fb3a");
353 BOOST_CHECK((
R1L / D2L).
ToString() ==
"000000000873ce8efec5b67150bad3aa8c5fcb70e947586153bf2cec7c37c57a");
358 BOOST_CHECK((
R2L / D1L).
ToString() ==
"000000000000000013e1665895a1cc981de6d93670105a6b3ec3b73141b3a3c5");
359 BOOST_CHECK((
R2L / D2L).
ToString() ==
"000000000e8f0abe753bb0afe2e9437ee85d280be60882cf0bd1aaf7fa3cc2c4");
369 return fabs(d1-d2) <= 4*fabs(d1)*std::numeric_limits<double>::epsilon();
396 for (
unsigned int i = 0; i < 255; ++i)
401 for (
int i = 256; i > 53; --i)
403 uint64_t R1L64part = (
R1L>>192).GetLow64();
404 for (
int i = 53; i > 0; --i)
406 BOOST_CHECK((
R1L>>(256-i)).getdouble() == (
double)(R1L64part >> (64-i)));
421 num.
SetCompact(0x00123456, &fNegative, &fOverflow);
427 num.
SetCompact(0x01003456, &fNegative, &fOverflow);
433 num.
SetCompact(0x02000056, &fNegative, &fOverflow);
439 num.
SetCompact(0x03000000, &fNegative, &fOverflow);
445 num.
SetCompact(0x04000000, &fNegative, &fOverflow);
451 num.
SetCompact(0x00923456, &fNegative, &fOverflow);
457 num.
SetCompact(0x01803456, &fNegative, &fOverflow);
463 num.
SetCompact(0x02800056, &fNegative, &fOverflow);
469 num.
SetCompact(0x03800000, &fNegative, &fOverflow);
475 num.
SetCompact(0x04800000, &fNegative, &fOverflow);
481 num.
SetCompact(0x01123456, &fNegative, &fOverflow);
491 num.
SetCompact(0x01fedcba, &fNegative, &fOverflow);
497 num.
SetCompact(0x02123456, &fNegative, &fOverflow);
503 num.
SetCompact(0x03123456, &fNegative, &fOverflow);
509 num.
SetCompact(0x04123456, &fNegative, &fOverflow);
515 num.
SetCompact(0x04923456, &fNegative, &fOverflow);
521 num.
SetCompact(0x05009234, &fNegative, &fOverflow);
527 num.
SetCompact(0x20123456, &fNegative, &fOverflow);
533 num.
SetCompact(0xff123456, &fNegative, &fOverflow);
556 unsigned char TmpArray[32];
arith_uint256 UintToArith256(const uint256 &a)
static void shiftArrayLeft(unsigned char *to, const unsigned char *from, unsigned int arrayLength, unsigned int bitsToShift)
static void shiftArrayRight(unsigned char *to, const unsigned char *from, unsigned int arrayLength, unsigned int bitsToShift)
#define CHECKBITWISEOPERATOR(_A_, _B_, _OP_)
#define CHECKASSIGNMENTOPERATOR(_A_, _B_, _OP_)
const unsigned char ZeroArray[]
const unsigned char R1Array[]
BOOST_AUTO_TEST_CASE(basics)
const arith_uint256 HalfL
const unsigned char OneArray[]
static arith_uint256 arith_uint256S(const std::string &str)
static bool almostEqual(double d1, double d2)
const unsigned char R2Array[]
static std::string ArrayToString(const unsigned char A[], unsigned int width)
static arith_uint256 arith_uint256V(const std::vector< unsigned char > &vch)
Convert vector to arith_uint256, via uint256 blob.
const unsigned char MaxArray[]
const arith_uint256 ZeroL
256-bit unsigned big integer.
arith_uint256 & SetCompact(uint32_t nCompact, bool *pfNegative=nullptr, bool *pfOverflow=nullptr)
The "compact" format is a representation of a whole number N using an unsigned 32bit number similar t...
uint32_t GetCompact(bool fNegative=false) const
unsigned int size() const
std::string ToString() const
uint64_t GetLow64() const
std::string GetHex() const
BOOST_AUTO_TEST_SUITE(cuckoocache_tests)
Test Suite for CuckooCache.
BOOST_AUTO_TEST_SUITE_END()
#define T(expected, seed, data)
#define BOOST_CHECK_THROW(stmt, excMatch)
#define BOOST_CHECK_EQUAL(v1, v2)
#define BOOST_CHECK(expr)
std::string ToString(const T &t)
Locale-independent version of std::to_string.
uint256 uint256S(const char *str)