From b967a15c8bccb42e5bd30cc7d6d7fd08ace7872c Mon Sep 17 00:00:00 2001 From: victor Date: Mon, 12 Oct 2009 07:42:36 +0000 Subject: [PATCH] more tests git-svn-id: https://ttuki.vtt.fi/svn/p2p-next/TUD/p2tp/trunk@398 e16421f0-f15b-0410-abcd-98678b794739 --- bin64.h | 17 ++++++++++++----- tests/binstest2.cpp | 16 ++++++++++++++++ tests/transfertest.cpp | 7 ++++--- 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/bin64.h b/bin64.h index d867545..a9a7698 100644 --- a/bin64.h +++ b/bin64.h @@ -3,9 +3,13 @@ #include #include -//#include -/** Bin numbers in the tail111 encoding: meaningless + +/** Numbering for (aligned) logarithmical bins. + Each number stands for an interval + [o*2^l,(o+1)*2^l), where l is the layer and o + is the offset. + Bin numbers in the tail111 encoding: meaningless bits in the tail are set to 0111...11, while the head denotes the offset. Thus, 1101 is the bin at layer 1, offset 3 (i.e. fourth). */ @@ -87,10 +91,11 @@ struct bin64_t { return (v&~short_tail) == (maybe_asc.v&~short_tail) ; } - bin64_t towards (bin64_t desc) const { - if (!desc.within(*this)) + /** Left or right, depending whether the destination is. */ + bin64_t towards (bin64_t dest) const { + if (!dest.within(*this)) return NONE; - if (desc.within(left())) + if (dest.within(left())) return left(); else return right(); @@ -111,10 +116,12 @@ struct bin64_t { return bin64_t(0,base_offset()); } + /** Whether layer is 0. */ bool is_base () const { return !(v & 1); } + /** Depth-first in-order binary tree traversal. */ bin64_t next_dfsio (uint8_t floor); bin64_t width () const { diff --git a/tests/binstest2.cpp b/tests/binstest2.cpp index 35eb9d4..5882eff 100755 --- a/tests/binstest2.cpp +++ b/tests/binstest2.cpp @@ -174,6 +174,22 @@ TEST(BinsTest,Alloc) { } +TEST(BinsTest,Remove) { + + bins b; + b.set(bin64_t(5,0)); + bins c; + c.set(bin64_t(2,0)); + c.set(bin64_t(2,2)); + b.remove(c); + EXPECT_EQ(bins::EMPTY,b.get(bin64_t(2,0))); + EXPECT_EQ(bins::FILLED,b.get(bin64_t(2,1))); + EXPECT_EQ(bins::EMPTY,b.get(bin64_t(2,2))); + EXPECT_EQ(bins::FILLED,b.get(bin64_t(2,3))); + EXPECT_EQ(bins::FILLED,b.get(bin64_t(4,1))); + +} + /*TEST(BinsTest,AddSub) { bins b; b|=15; diff --git a/tests/transfertest.cpp b/tests/transfertest.cpp index ba1d82c..f8c6993 100644 --- a/tests/transfertest.cpp +++ b/tests/transfertest.cpp @@ -25,7 +25,7 @@ TEST(TransferTest,TransferFile) { E000 = Sha1Hash(E0,Sha1Hash::ZERO); ABCDE000 = Sha1Hash(ABCD,E000); ROOT = ABCDE000; - for (int i=0; i<60; i++) + for (bin64_t pos(3,0); pos!=bin64_t::ALL; pos=pos.parent()) ROOT = Sha1Hash(ROOT,Sha1Hash::ZERO); // submit a new file @@ -51,9 +51,10 @@ TEST(TransferTest,TransferFile) { leech->OfferHash(bin64_t(1,0), seed->hashes[bin64_t(1,0)]); leech->OfferHash(bin64_t(1,1), seed->hashes[bin64_t(1,1)]); for (int i=0; i<4; i++) { - /*if (leech->complete()==trap) { + /*if (leech->seq_complete==3) { delete leech; - FileTransfer* leech = new FileTransfer(seed,"copy"); + leech = new FileTransfer(seed,"copy"); + EXPECT_EQ(3,leech->complete); }*/ bin64_t next = leech->picker->Pick(seed->ack_out,0); uint8_t buf[1024]; //size_t len = seed->storer->ReadData(next,&buf); -- 2.20.1