public void VIntTest_EncodeDecode() { for (int i = 0; i < 1000000; i++) { Int64 number = libWyvernzora.Utilities.RandomEx.Instance.NextInt64(); if (number > VInt.MaxValue || number < VInt.MinValue) continue; VInt x = new VInt(number); Byte[] b = x.Encode(); VInt y = new VInt(b); Assert.AreEqual(number, y); } for (int i = 0; i < 1000000; i++) { Int32 number = libWyvernzora.Utilities.RandomEx.Instance.NextInt32(); if (number > VInt.MaxValue || number < VInt.MinValue) continue; VInt x = new VInt(number); Byte[] b = x.Encode(); VInt y = new VInt(b); Assert.AreEqual(number, y); } for (int i = 0; i < 1000000; i++) { Int16 number = libWyvernzora.Utilities.RandomEx.Instance.NextInt16(); if (number > VInt.MaxValue || number < VInt.MinValue) continue; VInt x = new VInt(number); Byte[] b = x.Encode(); VInt y = new VInt(b); Assert.AreEqual(number, y); } }
/// <summary> /// Writes a signed variable-bit integer to the StreamEx. /// </summary> /// <param name="b">Variable-bit integer.</param> /// <param name="width">Desired width of the VInt representation; if negative, default width will be used.</param> /// <exception cref="ArgumentException">Throws ArgumentException if the specified width is positive and less than necessary width to contain the VInt value.</exception> public void WriteVInt(VInt b, Int32 width = -1) { WriteBytes(b.Encode(width)); }