コード例 #1
0
        public void EmptyFlagIsCorectAfterQueueBecomesEmpty()
        {
            var queue = new QueueViaLinkedList <int>();

            queue.Enqueue(5);
            queue.Dequeue();
            Assert.True(queue.IsEmpty());
        }
コード例 #2
0
        public void Dequeue_Test()
        {
            IQueue <char> queue = new QueueViaLinkedList <char>(5);

            queue.Enqueue('A');
            queue.Enqueue('B');
            queue.Enqueue('C');
            queue.Enqueue('D');
            queue.Enqueue('E');
            queue.IsEmpty.Should().BeFalse();
            queue.IsFull.Should().BeTrue();
            queue.Count.Should().Be(5);
            queue.Dequeue().Should().Be('A');
            queue.Count.Should().Be(4);
            queue.Dequeue().Should().Be('B');
            queue.Count.Should().Be(3);
            queue.Dequeue().Should().Be('C');
            queue.Count.Should().Be(2);
            queue.Dequeue().Should().Be('D');
            queue.Count.Should().Be(1);
            queue.Dequeue().Should().Be('E');
            queue.Count.Should().Be(0);

            Action act = () => queue.Dequeue();

            act.Should().Throw <IndexOutOfRangeException>()
            .WithMessage("Queue is empty.");
        }
コード例 #3
0
        static void Main(string[] args)
        {
            QueueViaLinkedList <int> queue = new QueueViaLinkedList <int>();

            int i = 9;

            queue.Enqueue(i);
            queue.Enqueue(i * 3);
            queue.Enqueue(i * 6);

            Console.WriteLine(queue.Peek());

            Console.WriteLine(queue.Dequeue());
        }
コード例 #4
0
        public void ExerciseQueueOperation()
        {
            var queue = new QueueViaLinkedList <int>();

            queue.Enqueue(4);
            queue.Enqueue(-1);
            queue.Enqueue(2);

            Assert.AreEqual(3, queue.Size);
            Assert.AreEqual(4, queue.Peak());
            Assert.AreEqual(4, queue.Dequeue());
            Assert.AreEqual(-1, queue.Peak());
            Assert.AreEqual(2, queue.Size);

            queue.Enqueue(2);
            queue.Enqueue(0);
            queue.Enqueue(-9);

            Assert.AreEqual(5, queue.Size);
            Assert.AreEqual(-1, queue.Dequeue());
            Assert.AreEqual(2, queue.Peak());
            Assert.AreEqual(2, queue.Dequeue());
            Assert.AreEqual(2, queue.Peak());
            Assert.AreEqual(2, queue.Dequeue());
            Assert.AreEqual(0, queue.Peak());
            Assert.AreEqual(0, queue.Dequeue());
            Assert.AreEqual(-9, queue.Peak());
            Assert.AreEqual(-9, queue.Dequeue());
            Assert.True(queue.IsEmpty());
            Assert.AreEqual(0, queue.Size);

            queue.Enqueue(0);
            queue.Enqueue(-5);
            queue.Enqueue(8);

            Assert.AreEqual(3, queue.Size);
            Assert.AreEqual(0, queue.Peak());

            queue.Enqueue(-3);
            queue.Enqueue(10);

            Assert.AreEqual(5, queue.Size);
            Assert.AreEqual(0, queue.Dequeue());
            Assert.AreEqual(-5, queue.Peak());
            Assert.AreEqual(-5, queue.Dequeue());
            Assert.AreEqual(8, queue.Peak());
            Assert.AreEqual(8, queue.Dequeue());
            Assert.AreEqual(-3, queue.Peak());
            Assert.AreEqual(-3, queue.Dequeue());
            Assert.AreEqual(10, queue.Peak());
            Assert.AreEqual(1, queue.Size);

            queue.Enqueue(-1);
            queue.Enqueue(1);
            queue.Enqueue(2);
            queue.Enqueue(5);
            queue.Enqueue(7);
            queue.Enqueue(10);
            queue.Enqueue(0);
            queue.Enqueue(9);
            queue.Enqueue(11);

            Assert.AreEqual(10, queue.Size);
        }
コード例 #5
0
        public void ExceptionThrownOnDequeueFromEmptyQueue()
        {
            var queue = new QueueViaLinkedList <int>();

            Assert.Throws <IndexOutOfRangeException>(() => queue.Dequeue());
        }