Example #1
0
        public void TestPiecePicker4()
        {
            PiecePicker piecePicker1 = new PiecePicker(3);

            //完成了第2个片断
            piecePicker1.Complete(2);

            //发送第1个片断的请求信息
            piecePicker1.Requested(0);

            //收到第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]);
        }
Example #2
0
        public void TestPiecePicker3()
        {
            PiecePicker piecePicker1 = new PiecePicker(9);

            //完成了第8个片断
            piecePicker1.Complete(8);

            //收到第0,2,4和6个片断的have信息
            piecePicker1.GotHave(0);
            piecePicker1.GotHave(2);
            piecePicker1.GotHave(4);
            piecePicker1.GotHave(6);

            //丢失第2和6个片断的have信息
            piecePicker1.LostHave(2);
            piecePicker1.LostHave(6);
            List <int> pull1 = Pull(piecePicker1);

            Assert.AreEqual(2, pull1.Count);
            Assert.AreEqual(true, (pull1[0] == 0 && pull1[1] == 4) || (pull1[0] == 4 && pull1[1] == 0));
        }