Changeset View
Changeset View
Standalone View
Standalone View
src/test/radix_tests.cpp
Show First 20 Lines • Show All 496 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(tree_traversal) { | ||||
Shuffle(randomizedElements.begin(), randomizedElements.end(), | Shuffle(randomizedElements.begin(), randomizedElements.end(), | ||||
FastRandomContext()); | FastRandomContext()); | ||||
for (auto &element : randomizedElements) { | for (auto &element : randomizedElements) { | ||||
BOOST_CHECK(mytree.insert(element)); | BOOST_CHECK(mytree.insert(element)); | ||||
} | } | ||||
// Check the tree is traversed in ascending key order | // Check the tree is traversed in ascending key order | ||||
size_t count = 0; | size_t count = 0; | ||||
mytree.forEachLeaf([&](RCUPtr<E> ptr) { | bool ret = mytree.forEachLeaf([&](RCUPtr<E> ptr) { | ||||
// This test assumes the key is equal to the value | // This test assumes the key is equal to the value | ||||
BOOST_CHECK_EQUAL(ptr->getId(), count); | BOOST_CHECK_EQUAL(ptr->getId(), count); | ||||
BOOST_CHECK_EQUAL(ptr, elements[count++]); | BOOST_CHECK_EQUAL(ptr, elements[count++]); | ||||
return true; | |||||
}); | }); | ||||
// All the elements are parsed | // All the elements are parsed | ||||
BOOST_CHECK_EQUAL(count, ELEMENTS); | BOOST_CHECK_EQUAL(count, ELEMENTS); | ||||
BOOST_CHECK(ret); | |||||
// Check we can stop the traversal when needed | |||||
const size_t stopCount = ELEMENTS / 2; | |||||
count = 0; | |||||
ret = mytree.forEachLeaf([&](RCUPtr<E> ptr) { | |||||
// This test assumes the key is equal to the value | |||||
BOOST_CHECK_EQUAL(ptr->getId(), count); | |||||
BOOST_CHECK_EQUAL(ptr, elements[count++]); | |||||
return count < stopCount; | |||||
}); | |||||
BOOST_CHECK_EQUAL(count, stopCount); | |||||
BOOST_CHECK(!ret); | |||||
} | } | ||||
BOOST_AUTO_TEST_CASE(uint256_key_wrapper) { | BOOST_AUTO_TEST_CASE(uint256_key_wrapper) { | ||||
Uint256KeyWrapper key = uint256S( | Uint256KeyWrapper key = uint256S( | ||||
"AA00000000000000000000000000000000000000000000000000000000000000"); | "AA00000000000000000000000000000000000000000000000000000000000000"); | ||||
auto checkEqual = [&](const Uint256KeyWrapper &val, | auto checkEqual = [&](const Uint256KeyWrapper &val, | ||||
const uint256 &expected) { | const uint256 &expected) { | ||||
▲ Show 20 Lines • Show All 63 Lines • Show Last 20 Lines |