2008-05-17 12:51:54 +00:00
|
|
|
#include "RarestPieceSelector.h"
|
2009-03-20 13:37:53 +00:00
|
|
|
|
2008-05-17 12:51:54 +00:00
|
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
|
2009-03-28 13:29:38 +00:00
|
|
|
#include "BitfieldMan.h"
|
2009-05-06 07:49:22 +00:00
|
|
|
#include "PieceStatMan.h"
|
2009-03-20 13:37:53 +00:00
|
|
|
|
2008-05-17 12:51:54 +00:00
|
|
|
namespace aria2 {
|
|
|
|
|
|
|
|
class RarestPieceSelectorTest:public CppUnit::TestFixture {
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE(RarestPieceSelectorTest);
|
2009-03-28 13:29:38 +00:00
|
|
|
CPPUNIT_TEST(testSelect);
|
2008-05-17 12:51:54 +00:00
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
public:
|
|
|
|
void setUp() {}
|
|
|
|
|
|
|
|
void tearDown() {}
|
|
|
|
|
|
|
|
void testAddPieceStats_index();
|
|
|
|
void testAddPieceStats_bitfield();
|
|
|
|
void testUpdatePieceStats();
|
|
|
|
void testSubtractPieceStats();
|
2009-03-28 13:29:38 +00:00
|
|
|
void testSelect();
|
2008-05-17 12:51:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION(RarestPieceSelectorTest);
|
|
|
|
|
2009-03-28 13:29:38 +00:00
|
|
|
void RarestPieceSelectorTest::testSelect()
|
|
|
|
{
|
2013-06-21 16:10:38 +00:00
|
|
|
std::shared_ptr<PieceStatMan> pieceStatMan(new PieceStatMan(10, false));
|
2009-05-06 07:49:22 +00:00
|
|
|
RarestPieceSelector selector(pieceStatMan);
|
2009-03-28 13:29:38 +00:00
|
|
|
BitfieldMan bf(1024, 10*1024);
|
|
|
|
bf.setBitRange(0, 2);
|
|
|
|
size_t index;
|
|
|
|
|
2009-05-06 07:49:22 +00:00
|
|
|
pieceStatMan->addPieceStats(0);
|
2009-03-28 13:29:38 +00:00
|
|
|
|
|
|
|
CPPUNIT_ASSERT(selector.select(index, bf.getBitfield(),
|
2010-01-05 16:01:46 +00:00
|
|
|
bf.countBlock()));
|
2009-03-28 13:29:38 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, index);
|
|
|
|
|
2009-05-06 07:49:22 +00:00
|
|
|
pieceStatMan->addPieceStats(1);
|
2009-03-28 13:29:38 +00:00
|
|
|
|
|
|
|
CPPUNIT_ASSERT(selector.select(index, bf.getBitfield(),
|
2010-01-05 16:01:46 +00:00
|
|
|
bf.countBlock()));
|
2009-03-28 13:29:38 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)2, index);
|
|
|
|
}
|
2008-05-17 12:51:54 +00:00
|
|
|
|
|
|
|
} // namespace aria2
|