コード例 #1
0
        public void ConsTest()
        {
            var queue = RealTimeDeque <string> .Empty;

            queue = RealTimeDeque <string> .Cons("Last", queue);

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

            queue = RealTimeDeque <string> .Cons("Head", queue);

            Assert.AreEqual("[1, {$Head}, {Head}, 1, {$Last}, {Last}]", DumpQueue(queue, true));
        }
コード例 #2
0
        public void EmptyTest()
        {
            var queue = RealTimeDeque <string> .Empty;

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

            queue = RealTimeDeque <string> .Cons("Head", queue);

            Assert.IsFalse(RealTimeDeque <string> .IsEmpty(queue));
            queue = RealTimeDeque <string> .Tail(queue);

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

            queue = RealTimeDeque <string> .Snoc(queue, "Tail");

            Assert.IsFalse(RealTimeDeque <string> .IsEmpty(queue));
            queue = RealTimeDeque <string> .Init(queue);

            Assert.IsTrue(RealTimeDeque <string> .IsEmpty(queue));
        }
コード例 #3
0
        public void TailTest()
        {
            const string data  = "One Two Three One Three";
            var          queue = data.Split().Aggregate(RealTimeDeque <string> .Empty, (queue1, s) => RealTimeDeque <string> .Cons(s, queue1));
            var          tail  = RealTimeDeque <string> .Tail(queue);

            Assert.AreEqual("[1, {One}, {}, 3, {One, Two, $Three}, {Three}]", DumpQueue(tail, true));
        }
コード例 #4
0
        public void HeadTest()
        {
            const string data  = "One Two Three One Three";
            var          queue = data.Split().Aggregate(RealTimeDeque <string> .Empty, (queue1, s) => RealTimeDeque <string> .Cons(s, queue1));
            var          head  = RealTimeDeque <string> .Head(queue);

            Assert.AreEqual("Three", head);
        }
コード例 #5
0
 public void EmptyConsTest()
 {
     AssertThrows <NullReferenceException>(() => RealTimeDeque <string> .Cons("Item", null));
 }
コード例 #6
0
        public void IncrementalHeadTest()
        {
            const string data  = "One Two Three Four Five";
            var          queue = data.Split().Aggregate(RealTimeDeque <string> .Empty, (queue1, s) => RealTimeDeque <string> .Cons(s, queue1));

            Assert.AreEqual("[2, {$}, {$}, 3, {$}, {$}]", DumpQueue(queue, false));

            // After looking at the first element, the rest of the queue should be not created.
            var head = RealTimeDeque <string> .Head(queue);

            Assert.AreEqual("Five", head);
            Assert.AreEqual("[2, {Five, $}, {Five, $}, 3, {$}, {$}]", DumpQueue(queue, false));
        }
コード例 #7
0
        public void ConsHeadTailTest()
        {
            const string data  = "One Two Three One Three";
            var          queue = data.Split().Aggregate(RealTimeDeque <string> .Empty, (queue1, s) => RealTimeDeque <string> .Cons(s, queue1));

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

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

            Assert.IsTrue(RealTimeDeque <string> .IsEmpty(queue));
        }