public void TestVLQUInt24() { 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((UInt24)UInt24.MaxValue) + 1]; var span1 = new SpanStream(mem); var span2 = new SpanStream(mem); var data = new UInt24[memSize]; for (var i = 0; i < memSize; i++) { data[i] = rnd.NextUInt32().ToUInt24(); } for (var i = 0; i < memSize; i++) { span1.WriteVLQ(data[i]); } for (var i = 0; i < memSize; i++) { Assert.Equal(data[i], span2.ReadVLQUInt24(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.ReadVLQUInt24(out _); }); } }