aria2/test/LongestSequencePieceSelectorTest.cc
Tatsuhiro Tsujikawa a6b02840fa 2009-03-28 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
BitfieldMan::getMissingIndexes family functions now takes
	unsigned char* bitfield instead of stl container for efficiency.
	PieceSelector::select now takes this
	bitfield. RarestPieceSelector::select now also performs
	efficiently for this change.  bitfield namespace is introduced
	and it has several helper functions to handle basic bitfield
	operations such as test, count set bits, etc.
	* src/BitfieldMan.cc
	* src/BitfieldMan.h
	* src/DefaultBtRequestFactory.cc
	* src/DefaultPieceStorage.cc
	* src/DefaultPieceStorage.h
	* src/LongestSequencePieceSelector.cc
	* src/LongestSequencePieceSelector.h
	* src/Makefile.am
	* src/Piece.cc
	* src/Piece.h
	* src/PieceSelector.h
	* src/RarestPieceSelector.cc
	* src/RarestPieceSelector.h
	* src/Util.cc
	* src/Util.h
	* src/bitfield.h
	* test/BitfieldManTest.cc
	* test/LongestSequencePieceSelectorTest.cc
	* test/Makefile.am
	* test/RarestPieceSelectorTest.cc
	* test/UtilTest.cc
	* test/bitfieldTest.cc
2009-03-28 13:29:38 +00:00

50 lines
1.2 KiB
C++

#include "LongestSequencePieceSelector.h"
#include <cppunit/extensions/HelperMacros.h>
#include "array_fun.h"
#include "BitfieldMan.h"
namespace aria2 {
class LongestSequencePieceSelectorTest:public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(LongestSequencePieceSelectorTest);
CPPUNIT_TEST(testSelect);
CPPUNIT_TEST_SUITE_END();
public:
void setUp() {}
void tearDown() {}
void testSelect();
};
CPPUNIT_TEST_SUITE_REGISTRATION(LongestSequencePieceSelectorTest);
void LongestSequencePieceSelectorTest::testSelect()
{
size_t A[] = { 1,2,3,4,7,10,11,12,13,14,15,100,112,113,114 };
BitfieldMan bf(1024, 1024*256);
for(size_t i = 0; i < arrayLength(A); ++i) {
bf.setBit(A[i]);
}
LongestSequencePieceSelector selector;
size_t index;
CPPUNIT_ASSERT(selector.select(index, bf.getBitfield(), bf.countBlock()));
CPPUNIT_ASSERT_EQUAL((size_t)15, index);
bf.clearAllBit();
CPPUNIT_ASSERT(!selector.select(index, bf.getBitfield(), bf.countBlock()));
// See it works in just one range
bf.setBitRange(1, 4);
CPPUNIT_ASSERT(selector.select(index, bf.getBitfield(), bf.countBlock()));
CPPUNIT_ASSERT_EQUAL((size_t)4, index);
}
} // namespace aria2