Bitcoin Core 28.99.0
P2P Digital Currency
Macros | Functions | Variables
arith_uint256_tests.cpp File Reference
#include <arith_uint256.h>
#include <test/util/setup_common.h>
#include <uint256.h>
#include <boost/test/unit_test.hpp>
#include <cmath>
#include <cstdint>
#include <iomanip>
#include <limits>
#include <sstream>
#include <string>
#include <vector>
Include dependency graph for arith_uint256_tests.cpp:

Go to the source code of this file.

Macros

#define CHECKBITWISEOPERATOR(_A_, _B_, _OP_)
 
#define CHECKASSIGNMENTOPERATOR(_A_, _B_, _OP_)    TmpL = _A_##L; TmpL _OP_##= _B_##L; BOOST_CHECK(TmpL == (_A_##L _OP_ _B_##L));
 

Functions

static arith_uint256 arith_uint256V (const std::vector< unsigned char > &vch)
 Convert vector to arith_uint256, via uint256 blob. More...
 
static std::string ArrayToString (const unsigned char A[], unsigned int width)
 
 BOOST_AUTO_TEST_CASE (basics)
 
static void shiftArrayRight (unsigned char *to, const unsigned char *from, unsigned int arrayLength, unsigned int bitsToShift)
 
static void shiftArrayLeft (unsigned char *to, const unsigned char *from, unsigned int arrayLength, unsigned int bitsToShift)
 
 BOOST_AUTO_TEST_CASE (shifts)
 
 BOOST_AUTO_TEST_CASE (unaryOperators)
 
 BOOST_AUTO_TEST_CASE (bitwiseOperators)
 
 BOOST_AUTO_TEST_CASE (comparison)
 
 BOOST_AUTO_TEST_CASE (plusMinus)
 
 BOOST_AUTO_TEST_CASE (multiply)
 
 BOOST_AUTO_TEST_CASE (divide)
 
static bool almostEqual (double d1, double d2)
 
 BOOST_AUTO_TEST_CASE (methods)
 
 BOOST_AUTO_TEST_CASE (bignum_SetCompact)
 
 BOOST_AUTO_TEST_CASE (getmaxcoverage)
 
 BOOST_AUTO_TEST_CASE (conversion)
 
 BOOST_AUTO_TEST_CASE (operator_with_self)
 

Variables

const unsigned char R1Array []
 
const char R1ArrayHex [] = "7D1DE5EAF9B156D53208F033B5AA8122D2d2355d5e12292b121156cfdb4a529c"
 
const double R1Ldouble = 0.4887374590559308955
 
const arith_uint256 R1L = arith_uint256V(std::vector<unsigned char>(R1Array,R1Array+32))
 
const uint64_t R1LLow64 = 0x121156cfdb4a529cULL
 
const unsigned char R2Array []
 
const arith_uint256 R2L = arith_uint256V(std::vector<unsigned char>(R2Array,R2Array+32))
 
const unsigned char ZeroArray []
 
const arith_uint256 ZeroL = arith_uint256V(std::vector<unsigned char>(ZeroArray,ZeroArray+32))
 
const unsigned char OneArray []
 
const arith_uint256 OneL = arith_uint256V(std::vector<unsigned char>(OneArray,OneArray+32))
 
const unsigned char MaxArray []
 
const arith_uint256 MaxL = arith_uint256V(std::vector<unsigned char>(MaxArray,MaxArray+32))
 
const arith_uint256 HalfL = (OneL << 255)
 

Macro Definition Documentation

◆ CHECKASSIGNMENTOPERATOR

#define CHECKASSIGNMENTOPERATOR (   _A_,
  _B_,
  _OP_ 
)     TmpL = _A_##L; TmpL _OP_##= _B_##L; BOOST_CHECK(TmpL == (_A_##L _OP_ _B_##L));

Definition at line 218 of file arith_uint256_tests.cpp.

◆ CHECKBITWISEOPERATOR

#define CHECKBITWISEOPERATOR (   _A_,
  _B_,
  _OP_ 
)
Value:
for (unsigned int i = 0; i < 32; ++i) { TmpArray[i] = uint8_t(_A_##Array[i] _OP_ _B_##Array[i]); } \
BOOST_CHECK(arith_uint256V(std::vector<unsigned char>(TmpArray,TmpArray+32)) == (_A_##L _OP_ _B_##L));
static arith_uint256 arith_uint256V(const std::vector< unsigned char > &vch)
Convert vector to arith_uint256, via uint256 blob.

Definition at line 214 of file arith_uint256_tests.cpp.

Function Documentation

◆ almostEqual()

static bool almostEqual ( double  d1,
double  d2 
)
static

Definition at line 366 of file arith_uint256_tests.cpp.

Here is the caller graph for this function:

◆ arith_uint256V()

static arith_uint256 arith_uint256V ( const std::vector< unsigned char > &  vch)
inlinestatic

Convert vector to arith_uint256, via uint256 blob.

Definition at line 22 of file arith_uint256_tests.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ArrayToString()

static std::string ArrayToString ( const unsigned char  A[],
unsigned int  width 
)
static

Definition at line 55 of file arith_uint256_tests.cpp.

Here is the caller graph for this function:

◆ BOOST_AUTO_TEST_CASE() [1/13]

BOOST_AUTO_TEST_CASE ( basics  )

Definition at line 66 of file arith_uint256_tests.cpp.

Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [2/13]

BOOST_AUTO_TEST_CASE ( bignum_SetCompact  )

Definition at line 409 of file arith_uint256_tests.cpp.

Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [3/13]

BOOST_AUTO_TEST_CASE ( bitwiseOperators  )

Definition at line 221 of file arith_uint256_tests.cpp.

◆ BOOST_AUTO_TEST_CASE() [4/13]

BOOST_AUTO_TEST_CASE ( comparison  )

Definition at line 265 of file arith_uint256_tests.cpp.

◆ BOOST_AUTO_TEST_CASE() [5/13]

BOOST_AUTO_TEST_CASE ( conversion  )

Definition at line 564 of file arith_uint256_tests.cpp.

Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [6/13]

BOOST_AUTO_TEST_CASE ( divide  )

Definition at line 347 of file arith_uint256_tests.cpp.

Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [7/13]

BOOST_AUTO_TEST_CASE ( getmaxcoverage  )

Definition at line 538 of file arith_uint256_tests.cpp.

◆ BOOST_AUTO_TEST_CASE() [8/13]

BOOST_AUTO_TEST_CASE ( methods  )

Definition at line 371 of file arith_uint256_tests.cpp.

Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [9/13]

BOOST_AUTO_TEST_CASE ( multiply  )

Definition at line 326 of file arith_uint256_tests.cpp.

Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [10/13]

BOOST_AUTO_TEST_CASE ( operator_with_self  )

Definition at line 581 of file arith_uint256_tests.cpp.

◆ BOOST_AUTO_TEST_CASE() [11/13]

BOOST_AUTO_TEST_CASE ( plusMinus  )

Definition at line 282 of file arith_uint256_tests.cpp.

Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [12/13]

BOOST_AUTO_TEST_CASE ( shifts  )

Definition at line 154 of file arith_uint256_tests.cpp.

Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [13/13]

BOOST_AUTO_TEST_CASE ( unaryOperators  )

Definition at line 197 of file arith_uint256_tests.cpp.

Here is the call graph for this function:

◆ shiftArrayLeft()

static void shiftArrayLeft ( unsigned char *  to,
const unsigned char *  from,
unsigned int  arrayLength,
unsigned int  bitsToShift 
)
static

Definition at line 137 of file arith_uint256_tests.cpp.

Here is the caller graph for this function:

◆ shiftArrayRight()

static void shiftArrayRight ( unsigned char *  to,
const unsigned char *  from,
unsigned int  arrayLength,
unsigned int  bitsToShift 
)
static

Definition at line 123 of file arith_uint256_tests.cpp.

Here is the caller graph for this function:

Variable Documentation

◆ HalfL

const arith_uint256 HalfL = (OneL << 255)

Definition at line 54 of file arith_uint256_tests.cpp.

◆ MaxArray

const unsigned char MaxArray[]
Initial value:
=
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"

Definition at line 49 of file arith_uint256_tests.cpp.

◆ MaxL

const arith_uint256 MaxL = arith_uint256V(std::vector<unsigned char>(MaxArray,MaxArray+32))

Definition at line 52 of file arith_uint256_tests.cpp.

◆ OneArray

const unsigned char OneArray[]
Initial value:
=
"\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"

Definition at line 44 of file arith_uint256_tests.cpp.

◆ OneL

const arith_uint256 OneL = arith_uint256V(std::vector<unsigned char>(OneArray,OneArray+32))

Definition at line 47 of file arith_uint256_tests.cpp.

◆ R1Array

const unsigned char R1Array[]
Initial value:
=
"\x9c\x52\x4a\xdb\xcf\x56\x11\x12\x2b\x29\x12\x5e\x5d\x35\xd2\xd2"
"\x22\x81\xaa\xb5\x33\xf0\x08\x32\xd5\x56\xb1\xf9\xea\xe5\x1d\x7d"

Definition at line 26 of file arith_uint256_tests.cpp.

◆ R1ArrayHex

const char R1ArrayHex[] = "7D1DE5EAF9B156D53208F033B5AA8122D2d2355d5e12292b121156cfdb4a529c"

Definition at line 29 of file arith_uint256_tests.cpp.

◆ R1L

const arith_uint256 R1L = arith_uint256V(std::vector<unsigned char>(R1Array,R1Array+32))

Definition at line 31 of file arith_uint256_tests.cpp.

◆ R1Ldouble

const double R1Ldouble = 0.4887374590559308955

Definition at line 30 of file arith_uint256_tests.cpp.

◆ R1LLow64

const uint64_t R1LLow64 = 0x121156cfdb4a529cULL

Definition at line 32 of file arith_uint256_tests.cpp.

◆ R2Array

const unsigned char R2Array[]
Initial value:
=
"\x70\x32\x1d\x7c\x47\xa5\x6b\x40\x26\x7e\x0a\xc3\xa6\x9c\xb6\xbf"
"\x13\x30\x47\xa3\x19\x2d\xda\x71\x49\x13\x72\xf0\xb4\xca\x81\xd7"

Definition at line 34 of file arith_uint256_tests.cpp.

◆ R2L

const arith_uint256 R2L = arith_uint256V(std::vector<unsigned char>(R2Array,R2Array+32))

Definition at line 37 of file arith_uint256_tests.cpp.

◆ ZeroArray

const unsigned char ZeroArray[]
Initial value:
=
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"

Definition at line 39 of file arith_uint256_tests.cpp.

◆ ZeroL

const arith_uint256 ZeroL = arith_uint256V(std::vector<unsigned char>(ZeroArray,ZeroArray+32))

Definition at line 42 of file arith_uint256_tests.cpp.