Changeset View
Changeset View
Standalone View
Standalone View
src/test/radix_tests.cpp
Show All 39 Lines | template <typename K> struct TestElementInt : TestElement<K> { | ||||
} | } | ||||
static auto MinusTwo() { | static auto MinusTwo() { | ||||
return std::numeric_limits< | return std::numeric_limits< | ||||
typename std::make_unsigned<K>::type>::max() - | typename std::make_unsigned<K>::type>::max() - | ||||
1; | 1; | ||||
} | } | ||||
}; | }; | ||||
struct TestElementUint256 : TestElement<Uint256KeyWrapper> { | struct TestElementUint256 : TestElement<Uint256RadixKey> { | ||||
TestElementUint256(const uint256 &keyIn) | TestElementUint256(const uint256 &keyIn) | ||||
: TestElement<Uint256KeyWrapper>(Uint256KeyWrapper(keyIn)) {} | : TestElement<Uint256RadixKey>(Uint256RadixKey(keyIn)) {} | ||||
TestElementUint256(uint64_t keyIn) | TestElementUint256(uint64_t keyIn) | ||||
: TestElement<Uint256KeyWrapper>(Uint256KeyWrapper(keyIn)) {} | : TestElement<Uint256RadixKey>(Uint256RadixKey(keyIn)) {} | ||||
static inline arith_uint256 signedMin = arith_uint256(1) << 255; | static inline arith_uint256 signedMin = arith_uint256(1) << 255; | ||||
static inline arith_uint256 signedMax = ~signedMin; | static inline arith_uint256 signedMax = ~signedMin; | ||||
static inline arith_uint256 minusOne = arith_uint256(0) - 1; | static inline arith_uint256 minusOne = arith_uint256(0) - 1; | ||||
static inline arith_uint256 minusTwo = minusOne - 1; | static inline arith_uint256 minusTwo = minusOne - 1; | ||||
static uint256 SignedMin() { return ArithToUint256(signedMin); } | static uint256 SignedMin() { return ArithToUint256(signedMin); } | ||||
static uint256 SignedMax() { return ArithToUint256(signedMax); } | static uint256 SignedMax() { return ArithToUint256(signedMax); } | ||||
▲ Show 20 Lines • Show All 464 Lines • ▼ Show 20 Lines | ret = mytree.forEachLeaf([&](RCUPtr<E> ptr) { | ||||
return count < stopCount; | return count < stopCount; | ||||
}); | }); | ||||
BOOST_CHECK_EQUAL(count, stopCount); | BOOST_CHECK_EQUAL(count, stopCount); | ||||
BOOST_CHECK(!ret); | BOOST_CHECK(!ret); | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(uint256_key_wrapper) { | BOOST_AUTO_TEST_CASE(uint256_key_wrapper) { | ||||
Uint256KeyWrapper key = uint256S( | Uint256RadixKey key = uint256S( | ||||
"AA00000000000000000000000000000000000000000000000000000000000000"); | "AA00000000000000000000000000000000000000000000000000000000000000"); | ||||
auto checkEqual = [&](const Uint256KeyWrapper &val, | auto checkEqual = [&](const Uint256RadixKey &val, const uint256 &expected) { | ||||
const uint256 &expected) { | |||||
BOOST_CHECK_EQUAL(ArithToUint256(val.base), expected); | BOOST_CHECK_EQUAL(ArithToUint256(val.base), expected); | ||||
}; | }; | ||||
auto checkOperands = [&](const Uint256KeyWrapper &val, | auto checkOperands = [&](const Uint256RadixKey &val, | ||||
const uint256 &expected_uint256, | const uint256 &expected_uint256, | ||||
const size_t expected_size_t) { | const size_t expected_size_t) { | ||||
checkEqual(val, expected_uint256); | checkEqual(val, expected_uint256); | ||||
checkEqual(val & Uint256KeyWrapper(uint256::ZERO), uint256::ZERO); | checkEqual(val & Uint256RadixKey(uint256::ZERO), uint256::ZERO); | ||||
checkEqual(val & val, expected_uint256); | checkEqual(val & val, expected_uint256); | ||||
checkEqual(val & TestElementUint256::MinusOne(), expected_uint256); | checkEqual(val & TestElementUint256::MinusOne(), expected_uint256); | ||||
BOOST_CHECK_EQUAL(size_t(val), expected_size_t); | BOOST_CHECK_EQUAL(size_t(val), expected_size_t); | ||||
}; | }; | ||||
// clang-format off | // clang-format off | ||||
checkOperands(key >> 0u, uint256S("AA00000000000000000000000000000000000000000000000000000000000000"), 0x0000000000000000); | checkOperands(key >> 0u, uint256S("AA00000000000000000000000000000000000000000000000000000000000000"), 0x0000000000000000); | ||||
▲ Show 20 Lines • Show All 46 Lines • Show Last 20 Lines |