extend piece picker unit test

This commit is contained in:
Arvid Norberg 2015-02-08 21:44:58 +00:00
parent 9fb98b1151
commit 84fe616ccb
2 changed files with 22 additions and 11 deletions

View File

@ -2027,14 +2027,17 @@ namespace libtorrent
}
// now, sort the list.
// TODO: this could probably be optimized by incrementally
// calling partial_sort to sort one more element in the list. Because
// chances are that we'll just need a single piece, and once we've
// picked from it we're done. Sorting the rest of the list in that
// case is a waste of time.
std::sort(ordered_partials, ordered_partials + num_ordered_partials
, boost::bind(&piece_picker::partial_compare_rarest_first, this
, _1, _2));
if (options & rarest_first)
{
// TODO: this could probably be optimized by incrementally
// calling partial_sort to sort one more element in the list. Because
// chances are that we'll just need a single piece, and once we've
// picked from it we're done. Sorting the rest of the list in that
// case is a waste of time.
std::sort(ordered_partials, ordered_partials + num_ordered_partials
, boost::bind(&piece_picker::partial_compare_rarest_first, this
, _1, _2));
}
for (int i = 0; i < num_ordered_partials; ++i)
{
@ -2212,7 +2215,6 @@ namespace libtorrent
int piece = start_piece;
while (num_blocks > 0)
{
bool done = false;
// skip pieces we can't pick, and suggested pieces
// since we've already picked those
while (!is_piece_free(piece, pieces)

View File

@ -639,8 +639,17 @@ int test_main()
TEST_CHECK(int(picked.size()) > 0);
TEST_CHECK(picked.front() == piece_block(3, 3));
// TODO: 3 if we use prioritize_partials + sequential, we should prefer
// the the partial pieces based on piece index instead
// if we don't use rarest first when we prioritize partials, but instead use
// sequential order, make sure we pick the right one
print_title("test partial piece order (sequential)");
p = setup_picker("1111111", " ", "", "013700f");
picked = pick_pieces(p, "*******", 1, 0, 0
, piece_picker::sequential | piece_picker::prioritize_partials, empty_vector);
TEST_CHECK(int(picked.size()) > 0);
TEST_CHECK(picked.front() == piece_block(1, 1)
|| picked.front() == piece_block(1, 2)
|| picked.front() == piece_block(1, 3));
// ========================================================