예제 #1
0
        public void ResizingArrayStack_Positive()
        {
            var stack = new ResizingArrayStack <int>();

            Assert.IsTrue(stack.IsEmpty());
            stack.Push(1);
            stack.Push(3);
            stack.Push(5);
            stack.Push(7);
            stack.Push(9);
            Assert.AreEqual(5, stack.Size());
            Assert.AreEqual(9, stack.Peek());

            Assert.AreEqual(9, stack.Pop());
            Assert.AreEqual(7, stack.Pop());
            Assert.AreEqual(3, stack.Size());
            Assert.AreEqual(5, stack.Peek());

            stack.Push(66);
            var list = new List <int> {
                66, 5, 3, 1
            };
            int index = 0;

            foreach (var i in stack)
            {
                Assert.AreEqual(list[index++], i);
            }
        }
        public void ResizingArrayStackTest()
        {
            var stack = new ResizingArrayStack <int>();

            stack.Push(1);
            stack.Push(2);

            Assert.IsTrue(stack.ItemCount == 2);
            Assert.IsTrue(stack.IsEmpty() == false);
            Assert.IsTrue(stack.Peek() == 2);
            Assert.IsTrue(stack.Pop() == 2);
            Assert.IsTrue(stack.ItemCount == 1);
            stack.Pop();
            Assert.IsTrue(stack.IsEmpty());

            for (int i = 0; i < 1000; i++)
            {
                stack.Push(i);
            }

            Assert.IsTrue(stack.ItemCount == 1000);

            for (int i = 0; i < 1000; i++)
            {
                stack.Pop();
            }

            Assert.IsTrue(stack.ItemCount == 0);
        }
        public void ManyPushTest()
        {
            IStack <int> stack = new ResizingArrayStack <int>();

            for (int i = 0; i < 10; i++)
            {
                stack.Push(i);
                Assert.IsFalse(stack.IsEmpty());
                Assert.AreEqual(i + 1, stack.Size());
                Assert.AreEqual(i, stack.Peek());
            }
        }
        public void PushAndPopTest_ReferenceType()
        {
            IStack <String> stack = new ResizingArrayStack <String>();

            stack.Push("1");
            Assert.IsFalse(stack.IsEmpty());
            Assert.AreEqual("1", stack.Peek());
            Assert.AreEqual(1, stack.Size());
            String value = stack.Pop();

            Assert.IsTrue(stack.IsEmpty());
            Assert.AreEqual(0, stack.Size());
            Assert.AreEqual("1", value);
        }
        public void PushAndPopTest_ValueType()
        {
            IStack <int> stack = new ResizingArrayStack <int>();

            stack.Push(1);
            Assert.IsFalse(stack.IsEmpty());
            Assert.AreEqual(1, stack.Peek());
            Assert.AreEqual(1, stack.Size());
            int value = stack.Pop();

            Assert.IsTrue(stack.IsEmpty());
            Assert.AreEqual(0, stack.Size());
            Assert.AreEqual(1, value);
        }
        public void PeekTest_EmptyStack()
        {
            IStack <int> stack = new ResizingArrayStack <int>();

            stack.Peek();
        }