コード例 #1
0
        public void CircularBuffer_Revert()
        {
            CircularBuffer<byte> cb = new CircularBuffer<byte>(50);

            // Move the pointer to the middle
            cb.Produce(25);
            cb.Consume(25);

            // Now allocate all space
            cb.Produce(25);
            cb.Produce(25);

            Assert.AreEqual(25, cb.Start);
            Assert.AreEqual(25, cb.ReadLength);
            Assert.AreEqual(25, cb.End);
            Assert.AreEqual(0, cb.WriteLength);

            cb.Revert(5);
            Assert.AreEqual(25, cb.Start);
            Assert.AreEqual(25, cb.ReadLength);
            Assert.AreEqual(20, cb.End);
            Assert.AreEqual(5, cb.WriteLength);

            cb.Revert(20);
            Assert.AreEqual(25, cb.Start);
            Assert.AreEqual(25, cb.ReadLength);
            Assert.AreEqual(0, cb.End);
            Assert.AreEqual(25, cb.WriteLength);

            cb.Revert(20);
            Assert.AreEqual(25, cb.Start);
            Assert.AreEqual(5, cb.ReadLength);
            Assert.AreEqual(30, cb.End);
            Assert.AreEqual(20, cb.WriteLength);
        }