예제 #1
0
        public void ThrowsIfLargeIsOver64()
        {
            ArgumentException exception = Assert.Throws <ArgumentException>(() =>
            {
                _ = VariableIntPacker.FromBitCount(5, 10, 65);
            });
            var expected = new ArgumentException("Large bits must be 64 or less", "largeBits");

            Assert.That(exception, Has.Message.EqualTo(expected.Message));
        }
예제 #2
0
        public void ThrowsIfMediumIsOver62()
        {
            ArgumentException exception = Assert.Throws <ArgumentException>(() =>
            {
                _ = VariableIntPacker.FromBitCount(5, 63);
            });
            var expected = new ArgumentException("Medium bits must be 62 or less", "mediumBits");

            Assert.That(exception, Has.Message.EqualTo(expected.Message));
        }
예제 #3
0
        public void ThrowsIfLargeLessThanMedium()
        {
            ArgumentException exception = Assert.Throws <ArgumentException>(() =>
            {
                _ = VariableIntPacker.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));
        }
예제 #4
0
        public void ThrowsIfMediumLessThanSmall()
        {
            ArgumentException exception = Assert.Throws <ArgumentException>(() =>
            {
                _ = VariableIntPacker.FromBitCount(6, 5);
            });
            var expected = new ArgumentException("Medium value must be greater than small value", "mediumBits");

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

            Assert.That(exception, Has.Message.EqualTo(expected.Message));
        }
예제 #6
0
        public void WritesMaxIfOverLargeValue(ulong inValue, int largeBits)
        {
            ulong max    = BitMask.Mask(largeBits);
            var   packer = VariableIntPacker.FromBitCount(1, 2, largeBits, false);

            Assert.DoesNotThrow(() =>
            {
                packer.PackUlong(this.writer, inValue);
                packer.PackUint(this.writer, (uint)inValue);
                packer.PackUlong(this.writer, (ushort)inValue);
            });
            NetworkReader reader  = this.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));
        }
예제 #7
0
        public void ThrowsWhenValueIsOverLargeValue()
        {
            var packer = VariableIntPacker.FromBitCount(1, 2, 3, true);
            ArgumentOutOfRangeException exception1 = Assert.Throws <ArgumentOutOfRangeException>(() =>
            {
                packer.PackUlong(this.writer, 20);
            });
            ArgumentOutOfRangeException exception2 = Assert.Throws <ArgumentOutOfRangeException>(() =>
            {
                packer.PackUint(this.writer, 20);
            });
            ArgumentOutOfRangeException exception3 = Assert.Throws <ArgumentOutOfRangeException>(() =>
            {
                packer.PackUlong(this.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));
        }