private static byte[] RanRandomOperations(CircularBuffer sut, byte[] input, Random random) { var output = new byte[input.Length]; var writeOffset = 0; var stream = sut.WriteStream; while (writeOffset < input.Length || sut.BytesReady > 0) { var operation = writeOffset == input.Length || random.Next(2) == 0 ? Operation.Read : Operation.Write; if (operation == Operation.Write) { var length = Math.Min(input.Length - writeOffset, random.Next(1, 100 * kb)); stream.Write(input, writeOffset, length); writeOffset += length; } else { var length = Math.Min(sut.BytesReady, random.Next(1, 100 * kb)); sut.Read(output.AsSpan((int)sut.BytesCut, length)); sut.Cut(length); } } return(output); }
public void Update_Bytes_Cut_And_Bytes_Ready_On_Cut() { var sut = new CircularBuffer(ArrayPool <byte> .Shared); sut.WriteStream.Write(new byte[] { 7, 5, 6, 8, 17, 93 }, 0, 6); sut.Cut(2); (sut.BytesReady, sut.BytesCut).Should().Be( (4, 2) ); }
public void Drop_On_Cut() { var sut = new CircularBuffer(ArrayPool <byte> .Shared); sut.WriteStream.Write(new byte[] { 7, 5, 6, 8 }, 0, 4); sut.Cut(2); var result = new byte[2]; sut.Read(new Span <byte>(result)); result.Should().Equal(6, 8); }