public void Enqueue_Dequeue_Test()
        {
            var queue = new TwoStacksQueue();

            queue.Enqueue(1);
            queue.Enqueue(2);
            queue.Enqueue(3);

            Assert.AreEqual(1, queue.Dequeue());
            Assert.AreEqual(2, queue.Dequeue());
            Assert.AreEqual(3, queue.Dequeue());
        }
예제 #2
0
        public void TestTwoStacksQueue()
        {
            var queue = new TwoStacksQueue <int>();

            Assert.Throws <Exception>(() => { var _ = queue.Peek; }, "Queue underflow");
            Assert.Throws <Exception>(() => { var _ = queue.Dequeue(); }, "Queue underflow");

            var fixtures = new[] { 1, 2, 3, 4, 5 };

            for (var idx = 0; idx < fixtures.Length; idx++)
            {
                queue.Enqueue(fixtures[idx]);
            }
            for (var idx = 0; idx < fixtures.Length; idx++)
            {
                Assert.AreEqual(fixtures[idx], queue.Peek);
                Assert.AreEqual(fixtures[idx], queue.Dequeue());
            }

            Assert.Throws <Exception>(() => { var _ = queue.Peek; }, "Queue underflow");
            Assert.Throws <Exception>(() => { var _ = queue.Dequeue(); }, "Queue underflow");

            queue.Enqueue(1);
            queue.Enqueue(2);
            queue.Enqueue(3);
            Assert.AreEqual(1, queue.Dequeue());
            queue.Enqueue(4);
            queue.Enqueue(5);
            Assert.AreEqual(2, queue.Dequeue());
            Assert.AreEqual(3, queue.Dequeue());
            Assert.AreEqual(4, queue.Dequeue());
            Assert.AreEqual(5, queue.Dequeue());
        }