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.rbegin()->stop = 300; | slots[99] = Slot(slots[99].getStart(), 300); | ||||
max = 300; | 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); | ||||
BOOST_CHECK_EQUAL(selectPeerImpl(slots, 299, max), 99); | BOOST_CHECK_EQUAL(selectPeerImpl(slots, 299, max), 99); | ||||
BOOST_CHECK_EQUAL(selectPeerImpl(slots, 300, max), NO_PEER); | BOOST_CHECK_EQUAL(selectPeerImpl(slots, 300, max), NO_PEER); | ||||
// Update the slots to be heavily skewed toward the first element. | // Update the slots to be heavily skewed toward the first element. | ||||
for (int i = 0; i < 100; i++) { | for (int i = 0; i < 100; i++) { | ||||
slots[i].start += 100; | slots[i] = Slot(slots[i].getStart() + 100, slots[i].getStop() + 100); | ||||
slots[i].stop += 100; | |||||
} | } | ||||
slots.begin()->start = 1; | slots[0] = Slot(1, slots[0].getStop()); | ||||
slots.rbegin()->stop = 300; | slots[99] = Slot(slots[99].getStart(), 300); | ||||
BOOST_CHECK_EQUAL(selectPeerImpl(slots, 0, max), NO_PEER); | BOOST_CHECK_EQUAL(selectPeerImpl(slots, 0, max), NO_PEER); | ||||
BOOST_CHECK_EQUAL(selectPeerImpl(slots, 1, max), 0); | BOOST_CHECK_EQUAL(selectPeerImpl(slots, 1, max), 0); | ||||
BOOST_CHECK_EQUAL(selectPeerImpl(slots, 42, max), 0); | BOOST_CHECK_EQUAL(selectPeerImpl(slots, 42, max), 0); | ||||
for (int i = 0; i < 100; i++) { | for (int i = 0; i < 100; i++) { | ||||
BOOST_CHECK_EQUAL(selectPeerImpl(slots, 100 + 2 * i + 1, max), i); | BOOST_CHECK_EQUAL(selectPeerImpl(slots, 100 + 2 * i + 1, max), i); | ||||
BOOST_CHECK_EQUAL(selectPeerImpl(slots, 100 + 2 * i + 2, max), NO_PEER); | BOOST_CHECK_EQUAL(selectPeerImpl(slots, 100 + 2 * i + 2, max), NO_PEER); | ||||
▲ Show 20 Lines • Show All 162 Lines • Show Last 20 Lines |