示例#1
0
 public void TestResizingArrayQueue() {
     var queue = new ResizingArrayQueue<string>();
     queue.Enqueue("Hello");
     queue.Enqueue("World");
     queue.Enqueue("how");
     queue.Enqueue("are");
     queue.Enqueue("you");
     foreach (var item in queue) {
         Console.WriteLine(item);
     }
 }
示例#2
0
        public void TestResizingArrayQueue()
        {
            var queue = new ResizingArrayQueue <string>();

            queue.Enqueue("Hello");
            queue.Enqueue("World");
            queue.Enqueue("how");
            queue.Enqueue("are");
            queue.Enqueue("you");
            foreach (var item in queue)
            {
                Console.WriteLine(item);
            }
        }
        public void ResizedArrayQueueTest()
        {
            var q = new ResizingArrayQueue <int>();

            q.Enqueue(1);
            q.Enqueue(2);
            Assert.IsTrue(q.Count == 2);
            int i = q.Dequeue();

            Assert.IsTrue(i == 1);
            Assert.IsTrue(q.Count == 1);
            i = q.Dequeue();
            Assert.IsTrue(i == 2);
            Assert.IsTrue(q.Count == 0);
        }
        public void ToStringTest()
        {
            IQueue <int> queue = new ResizingArrayQueue <int>();

            for (int i = 0; i < 10; i++)
            {
                queue.Enqueue(i);
            }
            Assert.AreEqual("0 1 2 3 4 5 6 7 8 9", 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());
            }
        }
示例#6
0
        public void ResizingArrayQueueTest2()
        {
            int[] input = { 3, 2, 4, 6, 9 };
            ResizingArrayQueue <int> queue = new ResizingArrayQueue <int>();

            queue.Enqueue(3);
            Assert.AreEqual("3 ", IteratorToString(queue));
            queue.Enqueue(4);

            Assert.AreEqual("3 4 ", IteratorToString(queue));
            Assert.AreEqual(3, queue.Dequeue());
            Assert.AreEqual(4, queue.Dequeue());
            Assert.AreEqual(0, queue.Count, "New queue has zero size");

            foreach (int i in input)
            {
                queue.Enqueue(i);
            }
            Assert.AreEqual(input.Length, queue.Count);
            Assert.AreEqual("3 2 4 6 9 ", IteratorToString(queue));
        }
        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 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);
            }
        }
示例#10
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());
        }
示例#11
0
        [Test] // 1.3.14
        public void ResizeQueue()
        {
            var queue = new ResizingArrayQueue <string>(2);

            queue.Enqueue("a");
            queue.Enqueue("b");
            queue.Enqueue("c");
            Assert.AreEqual("a", queue.Dequeue());
            queue.Enqueue("d");
            queue.Enqueue("e");
            Assert.AreEqual("b", queue.Dequeue());
            queue.Enqueue("f");
            queue.Enqueue("g");
            Assert.AreEqual("c", queue.Dequeue());
            queue.Enqueue("h");
            queue.Enqueue("i");
            queue.Enqueue("j");
            Assert.AreEqual("d", queue.Dequeue());

            Assert.AreEqual("e", queue.Dequeue());
            Assert.AreEqual("f", queue.Dequeue());
            Assert.AreEqual("g", queue.Dequeue());
            Assert.AreEqual("h", queue.Dequeue());
            Assert.AreEqual("i", queue.Dequeue());
            Assert.AreEqual("j", queue.Dequeue());

            for (int i = 0; i < 32; i++)
            {
                queue.Enqueue("1");
                Assert.AreEqual("1", queue.Dequeue());
            }

            for (int i = 0; i < 32; i++)
            {
                queue.Enqueue("2");
            }

            for (int i = 0; i < 32; i++)
            {
                queue.Enqueue("3");
                Assert.AreEqual("2", queue.Dequeue());
            }

            for (int i = 0; i < 32; i++)
            {
                Assert.AreEqual("3", queue.Dequeue());
            }
        }
        public void EnqueueTest_NullItem()
        {
            IQueue <String> queue = new ResizingArrayQueue <String>();

            queue.Enqueue(null);
        }