public void TestVLQUInt16() { var rnd = new Random(); for (var c = 0; c < count; c++) { var memSize = rnd.Next(1, 10_000); var mem = new byte[memSize * SpanUtils.MeasureVLQ(UInt16.MaxValue) + 1]; var span1 = new SpanStream(mem); var span2 = new SpanStream(mem); var data = new UInt16[memSize]; for (var i = 0; i < memSize; i++) { data[i] = rnd.NextUInt16(); } for (var i = 0; i < memSize; i++) { span1.WriteVLQ(data[i]); } for (var i = 0; i < memSize; i++) { Assert.Equal(data[i], span2.ReadVLQUInt16(out var len)); Assert.Equal(SpanUtils.MeasureVLQ(data[i]), len); } // Check overflow new Span <byte>(mem).Fill(0xFF); Assert.Throws <OverflowException>(() => { var span3 = new SpanStream(mem); span3.ReadVLQUInt16(out _); }); } }