public void Overwrite_Bit() { var streamer = new BitRingBuffer(0x100); for (int i = 0; i < 0x100 * 8 + 1; ++i) { streamer.Write(true); } }
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); }
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); }
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()); } }
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); }
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); }
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()); } }
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); }
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); }
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); }
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()); }
public void Overread_Bit() { var streamer = new BitRingBuffer(0x100); streamer.ReadBoolean(); }