Skip to content

Commit

Permalink
test: improve code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
richardschneider committed Nov 25, 2018
1 parent 0dddec6 commit d49a292
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
18 changes: 18 additions & 0 deletions test/DistanceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,23 @@ public void Tristanls()
Assert.AreEqual(255, bucket.Distance(new byte[] { 0x00 }, new byte[] { 0x00, 0x00 }));
Assert.AreEqual(16640, bucket.Distance(new byte[] { 0x01, 0x24 }, new byte[] { 0x40, 0x24 }));
}

[TestMethod]
public void ByContact()
{
var bucket = new KBucket<Contact>();
var c0 = new Contact((byte)0);
var c1 = new Contact((byte)1);
var c2 = new Contact((byte)2);
var c00 = new Contact((byte)0, (byte)0);
var c0124 = new Contact((byte)0x01, (byte)0x24);
var c4024 = new Contact((byte)0x40, (byte)0x24);
Assert.AreEqual(0, bucket.Distance(c0, c0));
Assert.AreEqual(1, bucket.Distance(c0, c1));
Assert.AreEqual(3, bucket.Distance(c2, c1));
Assert.AreEqual(255, bucket.Distance(c0, c00));
Assert.AreEqual(16640, bucket.Distance(c0124, c4024));

}
}
}
17 changes: 17 additions & 0 deletions test/SplitTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,22 @@ void traverse (Bucket<Contact> node, bool dontSplit)
Assert.AreEqual(dontSplit, node.DontSplit);
}
}

[TestMethod]
public void PingEvent()
{
var kBucket = new KBucket<Contact>
{
LocalContactId = new byte[] { 0x00 }
};
int pings = 0;
kBucket.Ping += (s, e) => ++pings;

for (var i = 0; i < 0x255; ++i)
{
kBucket.Add(new Contact((byte)i));
}
Assert.AreNotEqual(0, pings);
}
}
}

0 comments on commit d49a292

Please sign in to comment.