public int CreatesUsing3Values(ulong inValue, ulong smallValue, ulong mediumValue, ulong largeValue)
        {
            var packer = new VarIntPacker(smallValue, mediumValue, largeValue);

            packer.PackUlong(writer, inValue);
            return(writer.BitPosition);
        }
        public void ThrowsIfMediumIsOver62()
        {
            ArgumentException exception = Assert.Throws <ArgumentException>(() =>
            {
                _ = VarIntPacker.FromBitCount(5, 63);
            });
            var expected = new ArgumentException("Medium bits must be 62 or less", "mediumBits");

            Assert.That(exception, Has.Message.EqualTo(expected.Message));
        }
        public void ThrowsIfLargeIsOver64()
        {
            ArgumentException exception = Assert.Throws <ArgumentException>(() =>
            {
                _ = VarIntPacker.FromBitCount(5, 10, 65);
            });
            var expected = new ArgumentException("Large bits must be 64 or less", "largeBits");

            Assert.That(exception, Has.Message.EqualTo(expected.Message));
        }
        public void ThrowsIfLargeLessThanMedium()
        {
            ArgumentException exception = Assert.Throws <ArgumentException>(() =>
            {
                _ = VarIntPacker.FromBitCount(4, 10, 8);
            });
            var expected = new ArgumentException("Large value must be greater than medium value", "largeBits");

            Assert.That(exception, Has.Message.EqualTo(expected.Message));
        }
        public void ThrowsIfMediumLessThanSmall()
        {
            ArgumentException exception = Assert.Throws <ArgumentException>(() =>
            {
                _ = VarIntPacker.FromBitCount(6, 5);
            });
            var expected = new ArgumentException("Medium value must be greater than small value", "mediumBits");

            Assert.That(exception, Has.Message.EqualTo(expected.Message));
        }
        public void ThrowsIfSmallBitIsZero()
        {
            ArgumentException exception = Assert.Throws <ArgumentException>(() =>
            {
                _ = VarIntPacker.FromBitCount(0, 10);
            });
            var expected = new ArgumentException("Small value can not be zero", "smallBits");

            Assert.That(exception, Has.Message.EqualTo(expected.Message));
        }
Beispiel #7
0
 public UintPackerTests(ulong smallValue, ulong mediumValue, ulong?largeValue)
 {
     if (largeValue.HasValue)
     {
         packer = new VarIntPacker(smallValue, mediumValue, largeValue.Value, false);
         max    = largeValue.Value;
     }
     else
     {
         packer = new VarIntPacker(smallValue, mediumValue);
         max    = ulong.MaxValue;
     }
 }
        public void WritesMaxIfOverLargeValue(ulong inValue, int largeBits)
        {
            ulong max    = BitMask.Mask(largeBits);
            var   packer = VarIntPacker.FromBitCount(1, 2, largeBits, false);

            Assert.DoesNotThrow(() =>
            {
                packer.PackUlong(writer, inValue);
                packer.PackUint(writer, (uint)inValue);
                packer.PackUlong(writer, (ushort)inValue);
            });
            NetworkReader reader  = GetReader();
            ulong         unpack1 = packer.UnpackUlong(reader);
            uint          unpack2 = packer.UnpackUint(reader);
            ushort        unpack3 = packer.UnpackUshort(reader);

            Assert.That(unpack1, Is.EqualTo(max));
            Assert.That(unpack2, Is.EqualTo(max));
            Assert.That(unpack3, Is.EqualTo(max));
        }
        public void ThrowsWhenValueIsOverLargeValue()
        {
            var packer = VarIntPacker.FromBitCount(1, 2, 3, true);
            ArgumentOutOfRangeException exception1 = Assert.Throws <ArgumentOutOfRangeException>(() =>
            {
                packer.PackUlong(writer, 20);
            });
            ArgumentOutOfRangeException exception2 = Assert.Throws <ArgumentOutOfRangeException>(() =>
            {
                packer.PackUint(writer, 20);
            });
            ArgumentOutOfRangeException exception3 = Assert.Throws <ArgumentOutOfRangeException>(() =>
            {
                packer.PackUlong(writer, 20);
            });
            var expected = new ArgumentOutOfRangeException("value", 20, $"Value is over max of {7}");

            Assert.That(exception1, Has.Message.EqualTo(expected.Message));
            Assert.That(exception2, Has.Message.EqualTo(expected.Message));
            Assert.That(exception3, Has.Message.EqualTo(expected.Message));
        }