Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 2
0
        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));
        }
Ejemplo n.º 3
0
        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));
        }
Ejemplo n.º 4
0
        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));
        }
Ejemplo n.º 5
0
        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));
        }
Ejemplo n.º 6
0
        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));
        }
Ejemplo n.º 7
0
        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));
        }