public void EnqueueAndDequeueTest_ReferenceType()
        {
            IQueue <String> queue = new ResizingArrayQueue <String>();

            queue.Enqueue("1");
            Assert.IsFalse(queue.IsEmpty());
            Assert.AreEqual("1", queue.Peek());
            Assert.AreEqual(1, queue.Size());
            String value = queue.Dequeue();

            Assert.IsTrue(queue.IsEmpty());
            Assert.AreEqual(0, queue.Size());
            Assert.AreEqual("1", value);
        }
        public void EnqueueAndDequeueTest_ValueType()
        {
            IQueue <int> queue = new ResizingArrayQueue <int>();

            queue.Enqueue(1);
            Assert.IsFalse(queue.IsEmpty());
            Assert.AreEqual(1, queue.Peek());
            Assert.AreEqual(1, queue.Size());
            int value = queue.Dequeue();

            Assert.IsTrue(queue.IsEmpty());
            Assert.AreEqual(0, queue.Size());
            Assert.AreEqual(1, value);
        }
        public void ConstructorTest()
        {
            IQueue <int> queue = new ResizingArrayQueue <int>();

            Assert.IsTrue(queue.IsEmpty());
            Assert.AreEqual(0, queue.Size());
            Assert.IsTrue(string.IsNullOrWhiteSpace(queue.ToString()));
        }
        public void ManyEnqueueTest()
        {
            IQueue <int> queue = new ResizingArrayQueue <int>();

            for (int i = 0; i < 10; i++)
            {
                queue.Enqueue(i);
                Assert.IsFalse(queue.IsEmpty());
                Assert.AreEqual(i + 1, queue.Size());
                Assert.AreEqual(0, queue.Peek());
            }
        }
コード例 #5
0
        public void ResizingArrayQueue_Positive()
        {
            var queue = new ResizingArrayQueue <int>();

            Assert.IsTrue(queue.IsEmtpy());
            queue.Enqueue(1);
            queue.Enqueue(2);
            queue.Enqueue(5);
            queue.Enqueue(7);
            queue.Enqueue(9);
            queue.Enqueue(16);

            Assert.AreEqual(6, queue.Size());

            Assert.AreEqual(1, queue.Dequeue());
            Assert.AreEqual(2, queue.Dequeue());
            Assert.AreEqual(5, queue.Dequeue());
            Assert.AreEqual(7, queue.Dequeue());
            Assert.AreEqual(2, queue.Size());
            Assert.AreEqual(9, queue.Dequeue());
            Assert.AreEqual(16, queue.Dequeue());
            Assert.AreEqual(0, queue.Size());

            queue.Enqueue(22);
            queue.Enqueue(33);
            queue.Enqueue(44);
            var list = new List <int> {
                22, 33, 44
            };
            var index = 0;

            foreach (var i in queue)
            {
                Assert.AreEqual(i, list[index++]);
            }

            Assert.AreEqual(22, queue.Peek());
        }
        public void ManyDequeueTest()
        {
            IQueue <int> queue = new ResizingArrayQueue <int>();

            for (int i = 0; i < 10; i++)
            {
                queue.Enqueue(i);
            }
            for (int i = 0; i < 10; i++)
            {
                int value = queue.Dequeue();
                Assert.AreEqual(10 - i - 1, queue.Size());
                Assert.AreEqual(i, value);
            }
        }