public void VariableLength_FourLeadingOnes_FourBytes()
        {
            var expected = B("11100101") << 24 | B("11111111") << 16 | B("00001111") << 8 | B("10101010");

            UdpPacketReader r = R(B("11110010"), B("11100101"), B("11111111"), B("00001111"), B("10101010"));

            var actual = r.ReadVarInt64();

            Assert.AreEqual(expected, actual);
        }
        public void VariableLength_ZeroLeadingOnes()
        {
            var expected = B("01001001");

            UdpPacketReader r = R(expected, B("11111111"));

            var actual = r.ReadVarInt64();

            Assert.AreEqual(expected, actual);
        }
        public void VariableLength_Negative()
        {
            var expected = ~(B("11100101") << 24 | B("10000001") << 16 | B("00001111") << 8 | B("10101010"));

            UdpPacketReader r = R(B("11111000"), B("11110010"), B("11100101"), B("10000001"), B("00001111"), B("10101010"));

            var actual = r.ReadVarInt64();

            Assert.AreEqual(expected, actual);
        }
        public void LeadingOnesInAllBytes()
        {
            for (int i = 0; i <= byte.MaxValue; i++)
            {
                var digits = Convert.ToString(i, 2);
                if (digits.Length < 8)
                {
                    digits = Enumerable.Repeat("0", 8 - digits.Length).Aggregate((a, b) => a + b) + digits;
                }

                var expected = digits.TakeWhile(a => a == '1').Count();
                var actual   = UdpPacketReader.LeadingOnes((byte)i);
                Assert.AreEqual(expected, actual);
            }
        }