Changeset View
Changeset View
Standalone View
Standalone View
src/test/arith_uint256_tests.cpp
Show First 20 Lines • Show All 230 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(unaryOperators) { | ||||
for (unsigned int i = 0; i < 32; ++i) { | for (unsigned int i = 0; i < 32; ++i) { | ||||
TmpArray[i] = ~R1Array[i]; | TmpArray[i] = ~R1Array[i]; | ||||
} | } | ||||
BOOST_CHECK(arith_uint256V(std::vector<uint8_t>(TmpArray, TmpArray + 32)) == | BOOST_CHECK(arith_uint256V(std::vector<uint8_t>(TmpArray, TmpArray + 32)) == | ||||
(~R1L)); | (~R1L)); | ||||
BOOST_CHECK(-ZeroL == ZeroL); | BOOST_CHECK(-ZeroL == ZeroL); | ||||
BOOST_CHECK(-R1L == (~R1L) + 1); | BOOST_CHECK(-R1L == (~R1L) + 1); | ||||
for (unsigned int i = 0; i < 256; ++i) | for (unsigned int i = 0; i < 256; ++i) { | ||||
BOOST_CHECK(-(OneL << i) == (MaxL << i)); | BOOST_CHECK(-(OneL << i) == (MaxL << i)); | ||||
} | } | ||||
} | |||||
// Check if doing _A_ _OP_ _B_ results in the same as applying _OP_ onto each | // Check if doing _A_ _OP_ _B_ results in the same as applying _OP_ onto each | ||||
// element of Aarray and Barray, and then converting the result into an | // element of Aarray and Barray, and then converting the result into an | ||||
// arith_uint256. | // arith_uint256. | ||||
#define CHECKBITWISEOPERATOR(_A_, _B_, _OP_) \ | #define CHECKBITWISEOPERATOR(_A_, _B_, _OP_) \ | ||||
for (unsigned int i = 0; i < 32; ++i) { \ | for (unsigned int i = 0; i < 32; ++i) { \ | ||||
TmpArray[i] = _A_##Array[i] _OP_ _B_##Array[i]; \ | TmpArray[i] = _A_##Array[i] _OP_ _B_##Array[i]; \ | ||||
} \ | } \ | ||||
▲ Show 20 Lines • Show All 206 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(methods) { | ||||
BOOST_CHECK(R1L.GetLow64() == R1LLow64); | BOOST_CHECK(R1L.GetLow64() == R1LLow64); | ||||
BOOST_CHECK(HalfL.GetLow64() == 0x0000000000000000ULL); | BOOST_CHECK(HalfL.GetLow64() == 0x0000000000000000ULL); | ||||
BOOST_CHECK(OneL.GetLow64() == 0x0000000000000001ULL); | BOOST_CHECK(OneL.GetLow64() == 0x0000000000000001ULL); | ||||
for (unsigned int i = 0; i < 255; ++i) { | for (unsigned int i = 0; i < 255; ++i) { | ||||
BOOST_CHECK((OneL << i).getdouble() == ldexp(1.0, i)); | BOOST_CHECK((OneL << i).getdouble() == ldexp(1.0, i)); | ||||
} | } | ||||
BOOST_CHECK(ZeroL.getdouble() == 0.0); | BOOST_CHECK(ZeroL.getdouble() == 0.0); | ||||
for (int i = 256; i > 53; --i) | for (int i = 256; i > 53; --i) { | ||||
BOOST_CHECK( | BOOST_CHECK( | ||||
almostEqual((R1L >> (256 - i)).getdouble(), ldexp(R1Ldouble, i))); | almostEqual((R1L >> (256 - i)).getdouble(), ldexp(R1Ldouble, i))); | ||||
} | |||||
uint64_t R1L64part = (R1L >> 192).GetLow64(); | uint64_t R1L64part = (R1L >> 192).GetLow64(); | ||||
for (int i = 53; i > 0; | for (int i = 53; i > 0; | ||||
--i) // doubles can store all integers in {0,...,2^54-1} exactly | --i) // doubles can store all integers in {0,...,2^54-1} exactly | ||||
{ | { | ||||
BOOST_CHECK((R1L >> (256 - i)).getdouble() == | BOOST_CHECK((R1L >> (256 - i)).getdouble() == | ||||
(double)(R1L64part >> (64 - i))); | (double)(R1L64part >> (64 - i))); | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 194 Lines • Show Last 20 Lines |