public void CompareToNaiveTest([Range(0, 30)] int n)
        {
            var y = "";

            bool SimpleQuery(Monoid x) => x.Value.Length <= y.Length;

            var oracle = new Oracle();
            var st     = new SegmentTree <Monoid>(n, oracle);

            Assert.That(st.Length, Is.EqualTo(n));
            var stn = new SegmentTreeNaive <Monoid>(n, oracle);

            for (var i = 0; i < n; i++)
            {
                var s = new Monoid($"a{i}");
                st.Set(i, s);
                stn.Set(i, s);
            }

            for (var i = 0; i < n; i++)
            {
                Assert.That(st.Get(i), Is.EqualTo(stn.Get(i)));
            }

            for (var l = 0; l <= n; l++)
            {
                for (var r = l; r <= n; r++)
                {
                    Assert.That(st.Query(l, r), Is.EqualTo(stn.Query(l, r)));
                }
            }

            for (var l = 0; l <= n; l++)
            {
                for (var r = l; r <= n; r++)
                {
                    y = st.Query(l, r).Value;
                    Assert.That(st.MaxRight(l, SimpleQuery), Is.EqualTo(stn.MaxRight(l, SimpleQuery)));
                    Assert.That(st.MaxRight(l, SimpleQuery),
                                Is.EqualTo(stn.MaxRight(l, x => x.Value.Length <= y.Length)));
                }
            }

            for (var r = 0; r <= n; r++)
            {
                for (var l = 0; l <= r; l++)
                {
                    y = st.Query(l, r).Value;
                    Assert.That(st.MinLeft(r, SimpleQuery), Is.EqualTo(stn.MinLeft(r, SimpleQuery)));
                    Assert.That(st.MinLeft(r, SimpleQuery),
                                Is.EqualTo(stn.MinLeft(r, x => x.Value.Length <= y.Length)));
                }
            }
        }
        public void EmptyTest()
        {
            var oracle = new Oracle();
            var st     = new SegmentTree <Monoid>(0, new Oracle());

            Assert.That(st.Length, Is.Zero);
            Assert.That(st.QueryToAll(), Is.EqualTo(oracle.MonoidIdentity));

            st = new SegmentTree <Monoid>(new Monoid[] { }, new Oracle());
            Assert.That(st.Length, Is.Zero);
            Assert.That(st.QueryToAll(), Is.EqualTo(oracle.MonoidIdentity));
        }
        public void OneTest()
        {
            var oracle   = new Oracle();
            var identity = oracle.MonoidIdentity;
            var st       = new SegmentTree <Monoid>(1, oracle);

            Assert.That(st.Length, Is.EqualTo(1));
            Assert.That(st.QueryToAll(), Is.EqualTo(identity));
            Assert.That(st.Get(0), Is.EqualTo(identity));
            Assert.That(st.Query(0, 1), Is.EqualTo(identity));

            var expected = new Monoid("dummy");

            st.Set(0, expected);
            Assert.That(st.Get(0), Is.EqualTo(expected));
            Assert.That(st.Query(0, 0), Is.EqualTo(identity));
            Assert.That(st.Query(0, 1), Is.EqualTo(expected));
            Assert.That(st.Query(1, 1), Is.EqualTo(identity));
        }