public void PerfTest()
        {
            var heap = RealTimeQueue <int> .Empty;

            for (var i = 0; i < Size; i++)
            {
                heap = RealTimeQueue <int> .Snoc(heap, i);
            }

            Console.WriteLine(DumpQueue(heap, true));

            var count = 0;

            while (!RealTimeQueue <int> .IsEmpty(heap))
            {
                var next = RealTimeQueue <int> .Head(heap);

                Assert.AreEqual(count, next);
                heap = RealTimeQueue <int> .Tail(heap);

                count++;
            }

            Assert.AreEqual(Size, count);
        }
Beispiel #2
0
        public bool Dequeue(out T t)
        {
            t = default(T);

            lock (_lock)
            {
                while (!_token.IsCancellationRequested && RealTimeQueue <T> .IsEmpty(_queue))
                {
                    Monitor.Wait(_lock);
                }

                // We can exit, once the queue is empty.
                if (RealTimeQueue <T> .IsEmpty(_queue))
                {
                    return(false);
                }

                _count--;
                t = RealTimeQueue <T> .Head(_queue);

                _queue = RealTimeQueue <T> .Tail(_queue);

                Monitor.PulseAll(_lock);
            }

            return(true);
        }
        public void HeadTest()
        {
            const string data  = "One Two Three One Three";
            var          queue = data.Split().Aggregate(RealTimeQueue <string> .Empty, RealTimeQueue <string> .Snoc);
            var          head  = RealTimeQueue <string> .Head(queue);

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

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

                Assert.AreEqual(expected, head);
                queue = RealTimeQueue <string> .Tail(queue);
            }

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

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