public void TestPiecePicker1() { PiecePicker piecePicker1 = new PiecePicker(8); //收到第0,2,4和6个片断的have信息 piecePicker1.GotHave(0); piecePicker1.GotHave(2); piecePicker1.GotHave(4); piecePicker1.GotHave(6); //发送第0,1,3,6个片断的请求信息 piecePicker1.Requested(1); piecePicker1.Requested(1); piecePicker1.Requested(3); piecePicker1.Requested(0); piecePicker1.Requested(6); List <int> pull1 = Pull(piecePicker1); //因为第5和7个片断没有发送request信息,并且没有收到have信息,所以请求队列长度为6 Assert.AreEqual(6, pull1.Count); //严格优先选择策略 Assert.AreEqual(1, pull1[0]); Assert.AreEqual(3, pull1[1]); Assert.AreEqual(0, pull1[2]); Assert.AreEqual(6, pull1[3]); Assert.AreEqual(true, (pull1[4] == 2 && pull1[5] == 4) || (pull1[4] == 4 && pull1[5] == 2)); }
public void TestPiecePicker5() { PiecePicker piecePicker1 = new PiecePicker(3); //完成了第2个片断 piecePicker1.Complete(2); //发送第0和1个片断的请求信息 piecePicker1.Requested(0); piecePicker1.Requested(1); //收到第0和1个片断的have信息 piecePicker1.GotHave(1); piecePicker1.GotHave(0); piecePicker1.GotHave(0); List <int> pull1 = Pull(piecePicker1); Assert.AreEqual(2, pull1.Count); Assert.AreEqual(1, pull1[0]); Assert.AreEqual(0, pull1[1]); }