2008-05-17 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

Put piece selection strategy algorithm to RarestPieceSelector 
class,
	Added a switch to choose whether randomized selection so that 
unit
	tests emit same results in, possibly, win32.
	* src/DefaultPieceStorage.cc
	* src/DefaultPieceStorage.h
	* src/RarestPieceSelector.cc
	* src/RarestPieceSelector.h
	* test/DefaultPieceStorageTest.cc
	* test/RarestPieceSelectorTest.cc
This commit is contained in:
Tatsuhiro Tsujikawa 2008-05-17 12:51:54 +00:00
parent 77d892d7f2
commit ef02915d82
9 changed files with 551 additions and 200 deletions

View file

@ -76,20 +76,19 @@ void DefaultPieceStorageTest::testGetTotalLength() {
}
void DefaultPieceStorageTest::testGetMissingPiece() {
DefaultPieceStorage pss(btContext, option);
DefaultPieceStorage pss(btContext, option, false);
pss.setEndGamePieceNum(0);
peer->setAllBitfield();
// TODO the ordering of piece may vary depending on the system, so the test
// may fail.
SharedHandle<Piece> piece = pss.getMissingPiece(peer);
CPPUNIT_ASSERT_EQUAL(std::string("piece: index=2, length=128"),
CPPUNIT_ASSERT_EQUAL(std::string("piece: index=0, length=128"),
piece->toString());
piece = pss.getMissingPiece(peer);
CPPUNIT_ASSERT_EQUAL(std::string("piece: index=1, length=128"),
piece->toString());
piece = pss.getMissingPiece(peer);
CPPUNIT_ASSERT_EQUAL(std::string("piece: index=0, length=128"),
CPPUNIT_ASSERT_EQUAL(std::string("piece: index=2, length=128"),
piece->toString());
piece = pss.getMissingPiece(peer);
CPPUNIT_ASSERT(piece.isNull());
@ -119,15 +118,13 @@ void DefaultPieceStorageTest::testHasMissingPiece() {
}
void DefaultPieceStorageTest::testCompletePiece() {
DefaultPieceStorage pss(btContext, option);
DefaultPieceStorage pss(btContext, option, true);
pss.setEndGamePieceNum(0);
peer->setAllBitfield();
// TODO the ordering of piece may vary depending on the system, so the test
// may fail.
SharedHandle<Piece> piece = pss.getMissingPiece(peer);
CPPUNIT_ASSERT_EQUAL(std::string("piece: index=2, length=128"),
CPPUNIT_ASSERT_EQUAL(std::string("piece: index=0, length=128"),
piece->toString());
CPPUNIT_ASSERT_EQUAL(0ULL, pss.getCompletedLength());