Exemplo n.º 1
0
        public void Clear()
        {
            IntStack stack = new IntStack(1);

            stack.Push(1);
            Assert.AreEqual(stack.Peek(), 1);
            Assert.AreEqual(stack.Count, 1);
            stack.Push(2);
            Assert.AreEqual(stack.Peek(), 2);
            Assert.AreEqual(stack.Count, 2);
            stack.Push(4);
            Assert.AreEqual(stack.Peek(), 4);
            Assert.AreEqual(stack.Count, 3);
            stack.Clear();
            Assert.AreEqual(stack.Count, 0);
            stack.Push(4);
            Assert.AreEqual(stack.Peek(), 4);
            Assert.AreEqual(stack.Count, 1);
            stack.Push(8);
            Assert.AreEqual(stack.Peek(), 8);
            Assert.AreEqual(stack.Count, 2);
            stack.Push(9);
            Assert.AreEqual(stack.Peek(), 9);
            Assert.AreEqual(stack.Count, 3);
        }
Exemplo n.º 2
0
        public void NonEmpty()
        {
            IntStack stack = new IntStack(4);

            Assert.IsTrue(stack.IsEmpty);
            stack.Push(1);
            Assert.IsFalse(stack.IsEmpty);
            stack.Pop();
            Assert.IsTrue(stack.IsEmpty);
        }
Exemplo n.º 3
0
        public void PopWithResize()
        {
            IntStack stack = new IntStack(1);

            stack.Push(1);
            stack.Push(2);
            stack.Push(3);
            Assert.AreEqual(stack.Pop(), 3);
            Assert.AreEqual(stack.Pop(), 2);
            Assert.AreEqual(stack.Pop(), 1);
        }
Exemplo n.º 4
0
        public void PushDuplicate()
        {
            IntStack stack = new IntStack(4);

            stack.Push(1);
            Assert.AreEqual(stack.Peek(), 1);
            Assert.AreEqual(stack.Count, 1);
            stack.Push(stack.Peek());
            Assert.AreEqual(stack.Peek(), 1);
            Assert.AreEqual(stack.Count, 2);
            stack.Push(stack.Peek());
            Assert.AreEqual(stack.Peek(), 1);
            Assert.AreEqual(stack.Count, 3);
        }
Exemplo n.º 5
0
        public void PushWithResize()
        {
            IntStack stack = new IntStack(1);

            stack.Push(1);
            Assert.AreEqual(stack.Peek(), 1);
            Assert.AreEqual(stack.Count, 1);
            stack.Push(2);
            Assert.AreEqual(stack.Peek(), 2);
            Assert.AreEqual(stack.Count, 2);
            stack.Push(4);
            Assert.AreEqual(stack.Peek(), 4);
            Assert.AreEqual(stack.Count, 3);
        }