public void CanFindFirstUnmarked(int count)
        {
            if (count == 0)
            {
                return;
            }

            Span <int> span      = stackalloc int[StackAllocThreshold];
            BitHelper  bitHelper = count <= StackAllocThreshold
                ? new BitHelper(span.Slice(0, count), clear: true)
                : new BitHelper(new int[count], clear: false);

            for (int i = 0; i < count; i++)
            {
                Assert.Equal(i, bitHelper.FindFirstUnmarked());
                bitHelper.MarkBit(i);
            }

            Assert.Equal(count, bitHelper.FindFirstUnmarked());
        }
        public void CanFindFirstUnmarkedWithOffset(int count)
        {
            if (count < 5)
            {
                return;
            }

            Span <int> span      = stackalloc int[StackAllocThreshold];
            BitHelper  bitHelper = count <= StackAllocThreshold
                ? new BitHelper(span.Slice(0, count), clear: true)
                : new BitHelper(new int[count], clear: false);

            // flag a block of bits in the middle
            int start = count / 3;
            int end   = start * 2;

            for (int i = start; i <= end; i++)
            {
                bitHelper.MarkBit(i);
            }

            Assert.Equal(0, bitHelper.FindFirstUnmarked());
            Assert.False(bitHelper.IsMarked(bitHelper.FindFirstUnmarked()));
            Assert.Equal(start - 1, bitHelper.FindFirstUnmarked(start - 1));
            Assert.False(bitHelper.IsMarked(bitHelper.FindFirstUnmarked(start - 1)));
            Assert.Equal(end + 1, bitHelper.FindFirstUnmarked(start));
            Assert.False(bitHelper.IsMarked(bitHelper.FindFirstUnmarked(start)));
            Assert.Equal(end + 1, bitHelper.FindFirstUnmarked(start + 1));
            Assert.False(bitHelper.IsMarked(bitHelper.FindFirstUnmarked(start + 1)));
            Assert.Equal(end + 1, bitHelper.FindFirstUnmarked(end));
            Assert.False(bitHelper.IsMarked(bitHelper.FindFirstUnmarked(end)));
            Assert.Equal(end + 1, bitHelper.FindFirstUnmarked(end + 1));
            Assert.False(bitHelper.IsMarked(bitHelper.FindFirstUnmarked(end + 1)));
        }