示例#1
0
        public void Overwrite_Bit()
        {
            var streamer = new BitRingBuffer(0x100);

            for (int i = 0; i < 0x100 * 8 + 1; ++i)
            {
                streamer.Write(true);
            }
        }
示例#2
0
        public void InitialState()
        {
            var streamer = new BitRingBuffer(0x100);

            Assert.AreEqual(0x100, streamer.AvailableBytes);
            Assert.AreEqual(0, streamer.UsedBytes);
            Assert.AreEqual(0, streamer.LengthBytes);
            Assert.AreEqual(0, streamer.LengthBits);
            Assert.AreEqual(0x100 * 8, streamer.AvailableBits);
        }
示例#3
0
        public void OneBit_Written()
        {
            var streamer = new BitRingBuffer(0x100);

            streamer.Write(true);
            Assert.AreEqual(0x100 - 1, streamer.AvailableBytes);
            Assert.AreEqual(1, streamer.UsedBytes);
            Assert.AreEqual(0, streamer.LengthBytes);
            Assert.AreEqual(1, streamer.LengthBits);
            Assert.AreEqual(0x100 * 8 - 1, streamer.AvailableBits);
        }
示例#4
0
        public void ReadByte_BitByBit()
        {
            byte b        = 0xc7; // 11000111
            var  values   = new[] { false, true, true, false, false, false, true, true, true };
            var  streamer = new BitRingBuffer(0x100);

            streamer.Write(false);
            streamer.Write(b);
            for (int i = 0; i < 8; ++i)
            {
                Assert.AreEqual(values[i], streamer.ReadBoolean());
            }
        }
示例#5
0
        public void Nine_Bits_Written()
        {
            var streamer = new BitRingBuffer(0x100);

            for (int i = 0; i < 9; ++i)
            {
                streamer.Write(true);
            }
            Assert.AreEqual(0x100 - 2, streamer.AvailableBytes);
            Assert.AreEqual(2, streamer.UsedBytes);
            Assert.AreEqual(1, streamer.LengthBytes);
            Assert.AreEqual(9, streamer.LengthBits);
            Assert.AreEqual(0x100 * 8 - 9, streamer.AvailableBits);
        }
示例#6
0
        public void Seven_Bits_Written()
        {
            var streamer = new BitRingBuffer(0x100);

            for (int i = 0; i < 7; ++i)
            {
                streamer.Write(true);
            }
            Assert.AreEqual(0x100 - 1, streamer.AvailableBytes);
            Assert.AreEqual(1, streamer.UsedBytes);
            Assert.AreEqual(0, streamer.LengthBytes);
            Assert.AreEqual(7, streamer.LengthBits);
            Assert.AreEqual(0x100 * 8 - 7, streamer.AvailableBits);
        }
示例#7
0
        public void ReadFullBuffer_BitByBit()
        {
            var streamer = new BitRingBuffer(0x100);

            for (int i = 0; i < 0x100 * 8; ++i)
            {
                streamer.Write((i * (i % 7)) % 2 == 1);
            }

            for (int i = 0; i < 0x100 * 8; ++i)
            {
                Assert.AreEqual((i * (i % 7)) % 2 == 1, streamer.ReadBoolean());
            }
        }
示例#8
0
        public void Full()
        {
            var streamer = new BitRingBuffer(0x100);

            for (int i = 0; i < 0x100 * 8; ++i)
            {
                streamer.Write(true);
            }
            Assert.AreEqual(0, streamer.AvailableBytes);
            Assert.AreEqual(0x100, streamer.UsedBytes);
            Assert.AreEqual(0x100, streamer.LengthBytes);
            Assert.AreEqual(0x100 * 8, streamer.LengthBits);
            Assert.AreEqual(0, streamer.AvailableBits);
        }
示例#9
0
        public void WriteByteArray()
        {
            var streamer = new BitRingBuffer(0x100);
            var buffer   = new byte[0x100];

            for (int i = 0; i < 0x100; ++i)
            {
                buffer[i] = (byte)(((i + 123) * (i + 7)) % 256);
            }
            streamer.Write(buffer, 0, 0x100);
            var result = new byte[0x100];

            streamer.ReadBytes(result, 0, 0x100);
            CollectionAssert.AreEqual(buffer, result);
        }
示例#10
0
        public void ReadOneBit_After_Full()
        {
            var streamer = new BitRingBuffer(0x100);

            for (int i = 0; i < 0x100 * 8; ++i)
            {
                streamer.Write(true);
            }
            streamer.ReadBoolean();
            Assert.AreEqual(0, streamer.AvailableBytes);
            Assert.AreEqual(0x100, streamer.UsedBytes);
            Assert.AreEqual(0x100 - 1, streamer.LengthBytes);
            Assert.AreEqual(0x100 * 8 - 1, streamer.LengthBits);
            Assert.AreEqual(1, streamer.AvailableBits);
        }
示例#11
0
        public void EnsureIndexWrap()
        {
            var streamer = new BitRingBuffer(2);

            streamer.Write(0x3c);
            for (int i = 0; i < 7; ++i)
            {
                streamer.Write(true);
            }
            byte result = streamer.ReadByte();

            Assert.AreEqual((byte)0x3c, result);
            streamer.Write(false); // End of buffer
            streamer.Write(true);  // Wrap
            result = streamer.ReadByte();
            Assert.AreEqual((byte)0xfe, result);
            Assert.AreEqual(true, streamer.ReadBoolean());
        }
示例#12
0
        public void Overread_Bit()
        {
            var streamer = new BitRingBuffer(0x100);

            streamer.ReadBoolean();
        }