Ejemplo n.º 1
0
        public void RarestPieceTest()
        {
            for (int i = 0; i < 5; i++)
            {
                for (int j = 0; j < (i * 5) + 5; j++)
                {
                    peers[i].BitField [j] = true;
                }
            }

            // No pieces should be selected, but we can check what was requested.
            picker.PickPiece(peer, peer.BitField, peers);
            Assert.AreEqual(6, checker.PickPieceBitfield.Count);

            // Two peers have piece 25
            Assert.AreEqual(25, checker.PickPieceBitfield[0].FirstTrue(), "#1");
            Assert.AreEqual(-1, checker.PickPieceBitfield[0].FirstFalse(25, torrentData.Pieces), "#2");

            // Three peers have piece 20
            Assert.AreEqual(20, checker.PickPieceBitfield[1].FirstTrue(), "#3");
            Assert.AreEqual(-1, checker.PickPieceBitfield[1].FirstFalse(20, torrentData.Pieces), "#4");

            // Three peers have piece 20
            Assert.AreEqual(15, checker.PickPieceBitfield[2].FirstTrue(), "#4");
            Assert.AreEqual(-1, checker.PickPieceBitfield[2].FirstFalse(15, torrentData.Pieces), "#6");

            // Three peers have piece 20
            Assert.AreEqual(10, checker.PickPieceBitfield[3].FirstTrue(), "#5");
            Assert.AreEqual(-1, checker.PickPieceBitfield[3].FirstFalse(10, torrentData.Pieces), "#8");
        }
Ejemplo n.º 2
0
        public void RarestPieceTest()
        {
            rarest.PickPiece(peers[0], peers);
            Assert.AreEqual(5, tester.PickPieceBitfield.Count, "#1");
            BitField bf = tester.PickPieceBitfield[0];

            int[] trueIndices = new int[] { 1, 7, 11, 13, 17, 19, 23, 29, 31, 37 };
            for (int i = 0; i < bf.Length; i++)
            {
                if (Array.IndexOf <int>(trueIndices, i) > -1)
                {
                    Assert.IsTrue(bf[i]);
                }
                else
                {
                    Assert.IsFalse(bf[i]);
                }
            }

            bf          = tester.PickPieceBitfield[1];
            trueIndices = new int[] { 1, 5, 7, 11, 13, 17, 19, 23, 25, 29, 31, 35, 37 };
            for (int i = 0; i < bf.Length; i++)
            {
                if (Array.IndexOf <int>(trueIndices, i) > -1)
                {
                    Assert.IsTrue(bf[i]);
                }
                else
                {
                    Assert.IsFalse(bf[i]);
                }
            }
        }