public void Next()
        {
            var cursor = new PathCursor(KeyBytes.FromHex("cfed4460"), false);

            Assert.Equal(0, cursor.NibbleOffset);
            Assert.Equal(8, cursor.RemainingNibbleLength);
            Assert.Equal((byte)0xc, cursor.NextNibble);
            AssertBytesEqual(FromHex("0c0f0e0d04040600"), cursor.GetRemainingNibbles());

            Assert.Throws <ArgumentOutOfRangeException>(() => { cursor = cursor.Next(-1); });
            Assert.Equal(0, cursor.NibbleOffset);
            Assert.Equal(8, cursor.RemainingNibbleLength);

            Assert.Throws <ArgumentOutOfRangeException>(() => { cursor = cursor.Next(9); });
            Assert.Equal(0, cursor.NibbleOffset);
            Assert.Equal(8, cursor.RemainingNibbleLength);

            var next = cursor.Next(1);

            Assert.Equal(0, cursor.NibbleOffset);
            Assert.Equal(8, cursor.RemainingNibbleLength);
            Assert.Equal((byte)0xc, cursor.NextNibble);
            AssertBytesEqual(FromHex("0c0f0e0d04040600"), cursor.GetRemainingNibbles());
            Assert.Equal(1, next.NibbleOffset);
            Assert.Equal((byte)0xf, next.NextNibble);
            Assert.Equal(7, next.RemainingNibbleLength);
            AssertBytesEqual(FromHex("0f0e0d04040600"), next.GetRemainingNibbles());

            Assert.Throws <ArgumentOutOfRangeException>(() => { next = next.Next(-1); });
            Assert.Equal(1, next.NibbleOffset);
            Assert.Equal(7, next.RemainingNibbleLength);

            Assert.Throws <ArgumentOutOfRangeException>(() => { next = next.Next(8); });
            Assert.Equal(1, next.NibbleOffset);
            Assert.Equal(7, next.RemainingNibbleLength);

            var next2 = next.Next(5);

            Assert.Equal(0, cursor.NibbleOffset);
            Assert.Equal(8, cursor.RemainingNibbleLength);
            Assert.Equal((byte)0xc, cursor.NextNibble);
            AssertBytesEqual(FromHex("0c0f0e0d04040600"), cursor.GetRemainingNibbles());
            Assert.Equal(1, next.NibbleOffset);
            Assert.Equal(7, next.RemainingNibbleLength);
            Assert.Equal((byte)0xf, next.NextNibble);
            AssertBytesEqual(FromHex("0f0e0d04040600"), next.GetRemainingNibbles());
            Assert.Equal(6, next2.NibbleOffset);
            Assert.Equal(2, next2.RemainingNibbleLength);
            Assert.Equal((byte)0x6, next2.NextNibble);
            AssertBytesEqual(FromHex("0600"), next2.GetRemainingNibbles());
        }
        public void RemainingNibblesStartWith()
        {
            var cursor = new PathCursor(KeyBytes.FromHex("cfed4460"), false);

            Assert.True(cursor.RemainingNibblesStartWith(FromHex("0c0f0e0d04")));
            Assert.False(cursor.RemainingNibblesStartWith(FromHex("0c0f0e0d040406000a")));
            Assert.False(cursor.RemainingNibblesStartWith(FromHex("0c0f0e0d0f0f0f")));

            PathCursor next = cursor.Next(3);

            Assert.True(next.RemainingNibblesStartWith(FromHex("0d0404")));
            Assert.False(next.RemainingNibblesStartWith(FromHex("0d040406000a0b0c0d")));
            Assert.False(next.RemainingNibblesStartWith(FromHex("0d040a0b0c")));
        }
        public void CountCommonStartingNibbles()
        {
            var cursor = new PathCursor(KeyBytes.FromHex("cfed4460"), false);

            Assert.Equal(
                0,
                cursor.CountCommonStartingNibbles(ImmutableArray <byte> .Empty)
                );
            Assert.Equal(
                0,
                cursor.CountCommonStartingNibbles(FromHex("0a0b0c0d"))
                );
            Assert.Equal(
                3,
                cursor.CountCommonStartingNibbles(FromHex("0c0f0e0f0f0f0f"))
                );
            Assert.Equal(
                8,
                cursor.CountCommonStartingNibbles(FromHex("0c0f0e0d040406000a0b0c0d"))
                );

            PathCursor next = cursor.Next(3);

            Assert.Equal(
                0,
                next.CountCommonStartingNibbles(ImmutableArray <byte> .Empty)
                );
            Assert.Equal(
                0,
                next.CountCommonStartingNibbles(FromHex("0c0f0e0f0f0f0f"))
                );
            Assert.Equal(
                3,
                next.CountCommonStartingNibbles(FromHex("0d04040a0b0c"))
                );
            Assert.Equal(
                5,
                next.CountCommonStartingNibbles(FromHex("0d040406000a0b0c0d"))
                );
        }