Beispiel #1
0
        public void InitTest()
        {
            const string data  = "One Two Three One Three";
            var          queue = data.Split().Aggregate(RealTimeDeque <string> .Empty, RealTimeDeque <string> .Snoc);
            var          init  = RealTimeDeque <string> .Init(queue);

            Assert.AreEqual("[3, {One, Two, $Three}, {Three}, 1, {One}, {}]", DumpQueue(init, true));
        }
Beispiel #2
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));
        }
Beispiel #3
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);
        }
Beispiel #4
0
        public void LastTest()
        {
            const string data  = "One Two Three One Three";
            var          queue = data.Split().Aggregate(RealTimeDeque <string> .Empty, RealTimeDeque <string> .Snoc);
            var          last  = RealTimeDeque <string> .Last(queue);

            Assert.AreEqual("Three", last);
        }
Beispiel #5
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));
        }
Beispiel #6
0
        public void SnocTest()
        {
            var queue = RealTimeDeque <string> .Empty;

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

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

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

            Assert.AreEqual("[1, {$Head}, {Head}, 1, {$Last}, {Last}]", DumpQueue(queue, true));
        }
Beispiel #7
0
        public void IncrementalLastTest()
        {
            const string data  = "One Two Three Four Five";
            var          queue = data.Split().Aggregate(RealTimeDeque <string> .Empty, RealTimeDeque <string> .Snoc);

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

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

            Assert.AreEqual("Five", last);
            Assert.AreEqual("[3, {$}, {$}, 2, {Five, $}, {Five, $}]", DumpQueue(queue, false));
        }
Beispiel #8
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));
        }
Beispiel #9
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));
        }
Beispiel #10
0
        public void SnocLastInitTest()
        {
            const string data  = "One Two Three One Three";
            var          queue = data.Split().Aggregate(RealTimeDeque <string> .Empty, RealTimeDeque <string> .Snoc);

            var dat = data.Split().Reverse();

            foreach (var expected in dat)
            {
                var actual = RealTimeDeque <string> .Last(queue);

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

            Assert.IsTrue(RealTimeDeque <string> .IsEmpty(queue));
        }
Beispiel #11
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));
        }
Beispiel #12
0
        public void EmptyTailTest()
        {
            var queue = RealTimeDeque <string> .Empty;

            AssertThrows <ArgumentNullException>(() => RealTimeDeque <string> .Tail(queue));
        }
Beispiel #13
0
 public void EmptyConsTest()
 {
     AssertThrows <NullReferenceException>(() => RealTimeDeque <string> .Cons("Item", null));
 }
Beispiel #14
0
 private static string DumpQueue <T>(RealTimeDeque <T> .Queue queue, bool expandUnCreated)
 {
     return($"[{queue.LenF}, {{{DumpStream(queue.F, expandUnCreated)}}}, {{{DumpStream(queue.Sf, expandUnCreated)}}}, "
            + $"{queue.LenR}, {{{DumpStream(queue.R, expandUnCreated)}}}, {{{DumpStream(queue.Sr, expandUnCreated)}}}]");
 }
Beispiel #15
0
 public void EmptySoncTest()
 {
     AssertThrows <NullReferenceException>(() => RealTimeDeque <string> .Snoc(null, "Item"));
 }