public void HeadTest()
        {
            const string data  = "One Two Three One Three";
            var          queue = data.Split().Aggregate(BootstrappedQueue <string> .Empty, BootstrappedQueue <string> .Snoc);
            var          x     = BootstrappedQueue <string> .Head(queue);

            Assert.AreEqual("One", x);
        }
        public void TailTest()
        {
            const string data  = "One Two Three One Three";
            var          queue = data.Split().Aggregate(BootstrappedQueue <string> .Empty, BootstrappedQueue <string> .Snoc);

            queue = BootstrappedQueue <string> .Tail(queue);

            Assert.AreEqual("[2, {Two, Three}, null, 2, {Three, One}]", DumpQueue(queue));
        }
示例#3
0
 public static C Tail(C c)
 {
     if (c == null)
     {
         throw new ArgumentNullException(nameof(c));
     }
     if (BootstrappedQueue <Lazy <C> > .IsEmpty(c.Q))
     {
         return(Empty);
     }
     return(LinkAll(c.Q));
 }
示例#4
0
        private static C LinkAll(BootstrappedQueue <Lazy <C> > .Queue q)
        {
            var t = BootstrappedQueue <Lazy <C> > .Head(q).Value;

            var qp = BootstrappedQueue <Lazy <C> > .Tail(q);

            if (BootstrappedQueue <Lazy <C> > .IsEmpty(qp))
            {
                return(t);
            }
            return(Link(t, new Lazy <C>(() => LinkAll(qp))));
        }
        public void SnocThreeTest()
        {
            var queue = BootstrappedQueue <string> .Snoc(BootstrappedQueue <string> .Empty, "one");

            queue = BootstrappedQueue <string> .Snoc(queue, "two");

            queue = BootstrappedQueue <string> .Snoc(queue, "three");

            Assert.AreEqual("[3, {one}, [1, {Value is not created.}, null, 0, {}], 0, {}]", DumpQueue(queue));

            queue = BootstrappedQueue <string> .Tail(queue);

            Assert.AreEqual("[2, {two, three}, null, 0, {}]", DumpQueue(queue));
        }
        public void EmptyTest()
        {
            var queue = BootstrappedQueue <string> .Empty;

            Assert.IsTrue(BootstrappedQueue <string> .IsEmpty(queue));

            queue = BootstrappedQueue <string> .Snoc(queue, "Item");

            Assert.IsFalse(BootstrappedQueue <string> .IsEmpty(queue));

            queue = BootstrappedQueue <string> .Tail(queue);

            Assert.IsTrue(BootstrappedQueue <string> .IsEmpty(queue));
        }
        public void PushPopTest()
        {
            const string data  = "One Two Three One Three";
            var          queue = data.Split().Aggregate(BootstrappedQueue <string> .Empty, BootstrappedQueue <string> .Snoc);

            foreach (var expected in data.Split())
            {
                var actual = BootstrappedQueue <string> .Head(queue);

                Assert.AreEqual(expected, actual);
                queue = BootstrappedQueue <string> .Tail(queue);
            }

            Assert.IsTrue(BootstrappedQueue <string> .IsEmpty(queue));
        }
        public void SnocTest()
        {
            var queue = BootstrappedQueue <string> .Empty;

            queue = BootstrappedQueue <string> .Snoc(queue, "One");

            Assert.AreEqual("[1, {One}, null, 0, {}]", DumpQueue(queue));

            queue = BootstrappedQueue <string> .Snoc(queue, "Two");

            Assert.AreEqual("[1, {One}, null, 1, {Two}]", DumpQueue(queue));

            queue = BootstrappedQueue <string> .Snoc(queue, "Three");

            Assert.AreEqual("[3, {One}, [1, {Value is not created.}, null, 0, {}], 0, {}]", DumpQueue(queue));
        }
示例#9
0
 private static C Link(C xs, Lazy <C> s) => new C(xs.X, BootstrappedQueue <Lazy <C> > .Snoc(xs.Q, s));
示例#10
0
 public C(T x, BootstrappedQueue <Lazy <C> > .Queue xs)
 {
     X = x;
     Q = xs;
 }
        public void EmptySnocTest()
        {
            var queue = BootstrappedQueue <string> .Snoc(BootstrappedQueue <string> .Empty, "one");

            Assert.AreEqual("[1, {one}, null, 0, {}]", DumpQueue(queue));
        }
 private static string DumpQueue <T>(BootstrappedQueue <T> .Queue queue)
 {
     return(queue == null
         ? "null"
         : $"[{queue.LenFM}, {DumpList(queue.F)}, {DumpQueue(queue.M)}, {queue.LenR}, {DumpList(queue.R)}]");
 }
        public void EmptyTailTest()
        {
            var queue = BootstrappedQueue <string> .Empty;

            AssertThrows <ArgumentNullException>(() => BootstrappedQueue <string> .Tail(queue));
        }