2008-07-12 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

Added the test for the previous change in DefaultBtContext.cc
	* test/DefaultBtContextTest.cc
This commit is contained in:
Tatsuhiro Tsujikawa 2008-07-12 07:41:15 +00:00
parent 8929168380
commit cefbf6407e
2 changed files with 22 additions and 10 deletions

View File

@ -1,3 +1,8 @@
2008-07-12 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added the test for the previous change in DefaultBtContext.cc
* test/DefaultBtContextTest.cc
2008-07-12 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Fixed the bug that causes infinite loop when the number of pieces are

View File

@ -4,6 +4,7 @@
#include "AnnounceTier.h"
#include "FixedNumberRandomizer.h"
#include "FileEntry.h"
#include "array_fun.h"
#include <cstring>
#include <iostream>
#include <cppunit/extensions/HelperMacros.h>
@ -234,29 +235,35 @@ void DefaultBtContextTest::testComputeFastSet()
memset(infoHash, 0, sizeof(infoHash));
infoHash[0] = 0xff;
int pieces = 1000;
int fastSetSize = 10;
DefaultBtContext btContext;
btContext.setInfoHash(infoHash);
btContext.setNumPieces(pieces);
btContext.setNumPieces(1000);
{
std::deque<size_t> fastSet;
btContext.computeFastSet(fastSet, ipaddr, fastSetSize);
//for_each(fastSet.begin(), fastSet.end(), Printer());
//cerr << endl;
size_t ans1[] = { 686, 459, 278, 200, 404, 834, 64, 203, 760, 950 };
std::deque<size_t> ansSet1(&ans1[0], &ans1[10]);
CPPUNIT_ASSERT(std::equal(fastSet.begin(), fastSet.end(), ansSet1.begin()));
size_t ans[] = { 686, 459, 278, 200, 404, 834, 64, 203, 760, 950 };
std::deque<size_t> ansSet(&ans[0], &ans[arrayLength(ans)]);
CPPUNIT_ASSERT(std::equal(fastSet.begin(), fastSet.end(), ansSet.begin()));
}
ipaddr = "10.0.0.1";
{
std::deque<size_t> fastSet;
btContext.computeFastSet(fastSet, ipaddr, fastSetSize);
size_t ans2[] = { 568, 188, 466, 452, 550, 662, 109, 226, 398, 11 };
std::deque<size_t> ansSet2(&ans2[0], &ans2[10]);
CPPUNIT_ASSERT(std::equal(fastSet.begin(), fastSet.end(), ansSet2.begin()));
size_t ans[] = { 568, 188, 466, 452, 550, 662, 109, 226, 398, 11 };
std::deque<size_t> ansSet(&ans[0], &ans[arrayLength(ans)]);
CPPUNIT_ASSERT(std::equal(fastSet.begin(), fastSet.end(), ansSet.begin()));
}
// See when pieces < fastSetSize
btContext.setNumPieces(9);
{
std::deque<size_t> fastSet;
btContext.computeFastSet(fastSet, ipaddr, fastSetSize);
size_t ans[] = { 8, 6, 7, 5, 1, 4, 0, 2, 3 };
std::deque<size_t> ansSet(&ans[0], &ans[arrayLength(ans)]);
CPPUNIT_ASSERT(std::equal(fastSet.begin(), fastSet.end(), ansSet.begin()));
}
}