Exemplo n.º 1
0
        public void TestStackOperations()
        {
            LinkStack <int> stack = new LinkStack <int>();

            stack.Push(1);
            Assert.AreEqual(1, stack.Peek());
            Assert.AreEqual(1, stack.Peek());

            stack.Push(2);
            Assert.AreEqual(2, stack.Peek());
            Assert.AreEqual(2, stack.Peek());

            stack.Push(3);
            Assert.AreEqual(3, stack.Peek());
            Assert.AreEqual(3, stack.Peek());

            Assert.AreEqual(3, stack.Pop());
            Assert.AreEqual(2, stack.Peek());
            Assert.AreEqual(2, stack.Peek());

            Assert.AreEqual(2, stack.Pop());
            Assert.AreEqual(1, stack.Peek());
            Assert.AreEqual(1, stack.Peek());

            Assert.AreEqual(1, stack.Pop());
            Assert.Catch(() => stack.Peek());   //een lege stack geeft een Exception!
            Assert.Catch(() => stack.Peek());   //een lege stack geeft een Exception!
        }
Exemplo n.º 2
0
        public void TestPushPopCheck()
        {
            LinkStack <int> stack = new LinkStack <int>();

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

            Assert.AreEqual(3, stack.Pop());
            Assert.AreEqual(2, stack.Pop());
            Assert.AreEqual(1, stack.Pop());
        }
Exemplo n.º 3
0
        public void TestCount()
        {
            LinkStack <int> stack = new LinkStack <int>();

            Assert.AreEqual(0, stack.Count);
            stack.Push(1);
            stack.Push(2);
            stack.Push(3);
            Assert.AreEqual(3, stack.Count);
            stack.Pop();
            Assert.AreEqual(2, stack.Count);
            stack.Pop();
            stack.Pop();
            Assert.AreEqual(0, stack.Count);
        }
Exemplo n.º 4
0
        public void TestPopEmpty()
        {
            LinkStack <int> stack = new LinkStack <int>();

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

            Assert.AreEqual(3, stack.Pop());
            Assert.AreEqual(2, stack.Pop());
            Assert.AreEqual(1, stack.Pop());

            //Op een lege stack kunnen we geen pop doen
            //we controleren op een "fout" (Exception)
            Assert.Catch(() => stack.Pop());
        }