예제 #1
0
        public void Push_One_Element_To_Empty_Stack()
        {
            //Arrange
            int stackSize = 1;
            Stack<int> newStack = new Stack<int>();

            //Act
            newStack.Push(1);

            //Assert
            Assert.AreEqual(stackSize, newStack.Count);
        }
예제 #2
0
        public void Peek_On_Stack_With_One_Element()
        {
            //Arrange
            string elementInStack = "Test element";
            Stack<string> newStack = new Stack<string>();

            //Act
            newStack.Push(elementInStack);
            var topElementOfStack = newStack.Peek().elementValue;

            //Assert
            Assert.AreEqual(elementInStack, topElementOfStack);
        }
예제 #3
0
        public void Push_Two_Elements_To_Empty_Stack_Verify_That_Last_Added_Is_The_Top_Element_Of_Stack()
        {
            //Arrange
            string firstElementToAdd = "First added element";
            string secondElementToAdd = "Second added element";
            Stack<string> newStack = new Stack<string>();

            //Act
            newStack.Push(firstElementToAdd);
            newStack.Push(secondElementToAdd);
            var topElement = newStack.Peek().elementValue;

            //Assert
            Assert.AreEqual(secondElementToAdd, topElement);
        }
예제 #4
0
        public void Pop_One_Element_When_Stack_Is_Not_Empty()
        {
            //Arrange
            string firstElementToAdd = "First added element";
            string secondElementToAdd = "Second added element";
            Stack<string> newStack = new Stack<string>();
            newStack.Push(firstElementToAdd);
            newStack.Push(secondElementToAdd);

            //Act
            var popedElement = newStack.Pop().elementValue;

            //Assert
            Assert.AreEqual(popedElement, secondElementToAdd);
            Assert.AreEqual(newStack.Peek().elementValue, FirstElementToAdd);
        }
예제 #5
0
        public void Throwing_An_Exception_When_Stack_Is_Empty()
        {
            //Arrange
            Stack<string> newStack = new Stack<string>();

            //Act
            var topElementOfStack = newStack.Peek();
        }
예제 #6
0
 public void Init()
 {
     stack = new Stack();
 }