Пример #1
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);
        }
Пример #2
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));
        }
Пример #3
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));
        }
Пример #4
0
        public void EmptyHeadTest()
        {
            var queue = RealTimeDeque <string> .Empty;

            AssertThrows <ArgumentNullException>(() => RealTimeDeque <string> .Head(queue));
        }