Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/test/peermanager_tests.cpp
Show First 20 Lines • Show All 77 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(select_peer_dichotomic) { | ||||
for (int i = 0; i < 100; i++) { | for (int i = 0; i < 100; i++) { | ||||
BOOST_CHECK_EQUAL(selectPeerImpl(slots, 2 * i, max), NO_PEER); | BOOST_CHECK_EQUAL(selectPeerImpl(slots, 2 * i, max), NO_PEER); | ||||
BOOST_CHECK_EQUAL(selectPeerImpl(slots, 2 * i + 1, max), i); | BOOST_CHECK_EQUAL(selectPeerImpl(slots, 2 * i + 1, max), i); | ||||
} | } | ||||
BOOST_CHECK_EQUAL(selectPeerImpl(slots, max, max), NO_PEER); | BOOST_CHECK_EQUAL(selectPeerImpl(slots, max, max), NO_PEER); | ||||
// Update the slots to be heavily skewed toward the last element. | // Update the slots to be heavily skewed toward the last element. | ||||
slots[99] = Slot(slots[99].getStart(), 300); | slots[99] = slots[99].withScore(101); | ||||
max = 300; | max = slots[99].getStop(); | ||||
BOOST_CHECK_EQUAL(max, 300); | |||||
for (int i = 0; i < 100; i++) { | for (int i = 0; i < 100; i++) { | ||||
BOOST_CHECK_EQUAL(selectPeerImpl(slots, 2 * i, max), NO_PEER); | BOOST_CHECK_EQUAL(selectPeerImpl(slots, 2 * i, max), NO_PEER); | ||||
BOOST_CHECK_EQUAL(selectPeerImpl(slots, 2 * i + 1, max), i); | BOOST_CHECK_EQUAL(selectPeerImpl(slots, 2 * i + 1, max), i); | ||||
} | } | ||||
BOOST_CHECK_EQUAL(selectPeerImpl(slots, 200, max), 99); | BOOST_CHECK_EQUAL(selectPeerImpl(slots, 200, max), 99); | ||||
BOOST_CHECK_EQUAL(selectPeerImpl(slots, 256, max), 99); | BOOST_CHECK_EQUAL(selectPeerImpl(slots, 256, max), 99); | ||||
▲ Show 20 Lines • Show All 180 Lines • Show Last 20 Lines |