9 #include <boost/test/unit_test.hpp> 30 "\x9c\x52\x4a\xdb\xcf\x56\x11\x12\x2b\x29\x12\x5e\x5d\x35\xd2\xd2" 31 "\x22\x81\xaa\xb5\x33\xf0\x08\x32\xd5\x56\xb1\xf9\xea\xe5\x1d\x7d";
32 const char R1ArrayHex[] =
"7D1DE5EAF9B156D53208F033B5AA8122D2d2355d5e12292b121156cfdb4a529c";
35 const uint64_t
R1LLow64 = 0x121156cfdb4a529cULL;
38 "\x70\x32\x1d\x7c\x47\xa5\x6b\x40\x26\x7e\x0a\xc3\xa6\x9c\xb6\xbf" 39 "\x13\x30\x47\xa3\x19\x2d\xda\x71\x49\x13\x72\xf0\xb4\xca\x81\xd7";
42 const char R1LplusR2L[] =
"549FB09FEA236A1EA3E31D4D58F1B1369288D204211CA751527CFC175767850C";
45 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" 46 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
50 "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" 51 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
55 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff" 56 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff";
60 static std::string
ArrayToString(
const unsigned char A[],
unsigned int width)
62 std::stringstream Stream;
64 for (
unsigned int i = 0; i < width; ++i)
66 Stream<<std::setw(2)<<std::setfill(
'0')<<(
unsigned int)A[width-i-1];
90 uint64_t Tmp64 = 0xc4dab720d9c7acaaULL;
91 for (
unsigned int i = 0; i < 256; ++i)
130 static void shiftArrayRight(
unsigned char* to,
const unsigned char* from,
unsigned int arrayLength,
unsigned int bitsToShift)
132 for (
unsigned int T=0;
T < arrayLength; ++
T)
134 unsigned int F = (
T+bitsToShift/8);
136 to[
T] = uint8_t(from[F] >> (bitsToShift % 8));
139 if (F + 1 < arrayLength)
140 to[
T] |= uint8_t(from[(F + 1)] << (8 - bitsToShift % 8));
144 static void shiftArrayLeft(
unsigned char* to,
const unsigned char* from,
unsigned int arrayLength,
unsigned int bitsToShift)
146 for (
unsigned int T=0;
T < arrayLength; ++
T)
148 if (
T >= bitsToShift/8)
150 unsigned int F =
T-bitsToShift/8;
151 to[
T] = uint8_t(from[F] << (bitsToShift % 8));
152 if (
T >= bitsToShift/8+1)
153 to[
T] |= uint8_t(from[F - 1] >> (8 - bitsToShift % 8));
162 unsigned char TmpArray[32];
164 for (
unsigned int i = 0; i < 256; ++i)
168 TmpL =
OneL; TmpL <<= i;
171 TmpL =
HalfL; TmpL >>= (255-i);
176 TmpL =
R1L; TmpL <<= i;
181 TmpL =
R1L; TmpL >>= i;
186 TmpL =
MaxL; TmpL <<= i;
191 TmpL =
MaxL; TmpL >>= i;
196 for (
unsigned int i = 0; i < 128; ++i) {
199 for (
unsigned int i = 128; i < 256; ++i) {
208 unsigned char TmpArray[32];
209 for (
unsigned int i = 0; i < 32; ++i) { TmpArray[i] = uint8_t(~
R1Array[i]); }
214 for (
unsigned int i = 0; i < 256; ++i)
221 #define CHECKBITWISEOPERATOR(_A_,_B_,_OP_) \ 222 for (unsigned int i = 0; i < 32; ++i) { TmpArray[i] = uint8_t(_A_##Array[i] _OP_ _B_##Array[i]); } \ 223 BOOST_CHECK(arith_uint256V(std::vector<unsigned char>(TmpArray,TmpArray+32)) == (_A_##L _OP_ _B_##L)); 225 #define CHECKASSIGNMENTOPERATOR(_A_,_B_,_OP_) \ 226 TmpL = _A_##L; TmpL _OP_##= _B_##L; BOOST_CHECK(TmpL == (_A_##L _OP_ _B_##L)); 230 unsigned char TmpArray[32];
265 uint64_t Tmp64 = 0xe1db685c9a0b47a2ULL;
275 for (
unsigned int i = 0; i < 256; ++i) {
278 BOOST_CHECK( TmpL >= 0 && TmpL > 0 && 0 < TmpL && 0 <= TmpL);
285 BOOST_CHECK_LT(
ZeroL,
288 BOOST_CHECK_LT(
arith_uint256S(
"0000000000000000000000000000000000000000000000000000000000000001"),
289 arith_uint256S(
"1000000000000000000000000000000000000000000000000000000000000000"));
302 for (
unsigned int i = 1; i < 256; ++i) {
307 TmpL = (
MaxL>>i); TmpL += 1;
314 TmpL =
arith_uint256(0xbedc77e27940a7ULL); TmpL += 0xee8d836fce66fbULL;
316 TmpL -= 0xee8d836fce66fbULL;
BOOST_CHECK(TmpL == 0xbedc77e27940a7ULL);
323 for (
unsigned int i = 1; i < 256; ++i) {
326 TmpL = (
HalfL >> (i-1));
329 TmpL = (
HalfL >> (i-1));
354 BOOST_CHECK((
R2L * 0x87654321UL).
ToString() ==
"23f7816e30c4ae2017257b7a0fa64d60402f5234d46e746b61c960d09a26d070");
361 BOOST_CHECK((
R1L / D1L).
ToString() ==
"00000000000000000b8ac01106981635d9ed112290f8895545a7654dde28fb3a");
362 BOOST_CHECK((
R1L / D2L).
ToString() ==
"000000000873ce8efec5b67150bad3aa8c5fcb70e947586153bf2cec7c37c57a");
367 BOOST_CHECK((
R2L / D1L).
ToString() ==
"000000000000000013e1665895a1cc981de6d93670105a6b3ec3b73141b3a3c5");
368 BOOST_CHECK((
R2L / D2L).
ToString() ==
"000000000e8f0abe753bb0afe2e9437ee85d280be60882cf0bd1aaf7fa3cc2c4");
378 return fabs(d1-d2) <= 4*fabs(d1)*std::numeric_limits<double>::epsilon();
405 for (
unsigned int i = 0; i < 255; ++i)
410 for (
int i = 256; i > 53; --i)
412 uint64_t R1L64part = (
R1L>>192).GetLow64();
413 for (
int i = 53; i > 0; --i)
415 BOOST_CHECK((
R1L>>(256-i)).getdouble() == (
double)(R1L64part >> (64-i)));
430 num.
SetCompact(0x00123456, &fNegative, &fOverflow);
436 num.
SetCompact(0x01003456, &fNegative, &fOverflow);
442 num.
SetCompact(0x02000056, &fNegative, &fOverflow);
448 num.
SetCompact(0x03000000, &fNegative, &fOverflow);
454 num.
SetCompact(0x04000000, &fNegative, &fOverflow);
460 num.
SetCompact(0x00923456, &fNegative, &fOverflow);
466 num.
SetCompact(0x01803456, &fNegative, &fOverflow);
472 num.
SetCompact(0x02800056, &fNegative, &fOverflow);
478 num.
SetCompact(0x03800000, &fNegative, &fOverflow);
484 num.
SetCompact(0x04800000, &fNegative, &fOverflow);
490 num.
SetCompact(0x01123456, &fNegative, &fOverflow);
500 num.
SetCompact(0x01fedcba, &fNegative, &fOverflow);
506 num.
SetCompact(0x02123456, &fNegative, &fOverflow);
512 num.
SetCompact(0x03123456, &fNegative, &fOverflow);
518 num.
SetCompact(0x04123456, &fNegative, &fOverflow);
524 num.
SetCompact(0x04923456, &fNegative, &fOverflow);
530 num.
SetCompact(0x05009234, &fNegative, &fOverflow);
536 num.
SetCompact(0x20123456, &fNegative, &fOverflow);
542 num.
SetCompact(0xff123456, &fNegative, &fOverflow);
565 unsigned char TmpArray[32];
std::string ToString() const
#define BOOST_CHECK_THROW(stmt, excMatch)
BOOST_AUTO_TEST_CASE(basics)
#define CHECKBITWISEOPERATOR(_A_, _B_, _OP_)
static void shiftArrayLeft(unsigned char *to, const unsigned char *from, unsigned int arrayLength, unsigned int bitsToShift)
uint32_t GetCompact(bool fNegative=false) const
const arith_uint256 ZeroL
arith_uint256 UintToArith256(const uint256 &a)
const arith_uint256 HalfL
const unsigned char R2Array[]
const unsigned char OneArray[]
BOOST_AUTO_TEST_SUITE_END()
const unsigned char R1Array[]
static arith_uint256 arith_uint256S(std::string_view str)
#define CHECKASSIGNMENTOPERATOR(_A_, _B_, _OP_)
static arith_uint256 arith_uint256V(const std::vector< unsigned char > &vch)
Convert vector to arith_uint256, via uint256 blob.
256-bit unsigned big integer.
const unsigned char MaxArray[]
#define BOOST_CHECK_EQUAL(v1, v2)
uint64_t GetLow64() const
const unsigned char ZeroArray[]
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...
BOOST_AUTO_TEST_SUITE(cuckoocache_tests)
Test Suite for CuckooCache.
uint256 uint256S(std::string_view str)
std::string GetHex() const
Hex encoding of the number (with the most significant digits first).
static bool almostEqual(double d1, double d2)
static void shiftArrayRight(unsigned char *to, const unsigned char *from, unsigned int arrayLength, unsigned int bitsToShift)
static std::string ArrayToString(const unsigned char A[], unsigned int width)
unsigned int size() const
#define T(expected, seed, data)
std::string ToString(const T &t)
Locale-independent version of std::to_string.
#define BOOST_CHECK(expr)