Exemple #1
0
        public void Count_OnFilledThenEmptiedStack_ReturnsOne()
        {
            //Assemble
            int stackTestSize = 3;
            Stack target = new Stack(stackTestSize);

            //Act
            target.Push("A");
            target.Push("B");

            //Pop all but one item from the stack.
            target.Pop();

            //Verify that count has returned value of 1.
            int expected = 1;
            int actual = target.Count();

            //Assert
            Assert.AreEqual(expected, actual);
        }
Exemple #2
0
        public void Count_OnFilledMinusOneStack_ReturnsFour()
        {
            //Assemble
            int stackTestSize = 5;
            Stack target = new Stack(stackTestSize);

            //Act
            target.Push("A");
            target.Push("B");
            target.Push("C");
            target.Push("D");
            target.Push("E");

            //Pop the last item from the stack.
            target.Pop();

            //Verify that count has returned value of 4.
            int expected = 4;
            int actual = target.Count();

            //Assert
            Assert.AreEqual(expected, actual);
        }
Exemple #3
0
        public void IsEmpty_EmptyStackBlankString_ReturnsTrue()
        {
            //Near-arbitrary stack size for the creation of the stack:
            int stackTestSize = 5;
            Stack target = new Stack(stackTestSize);

            //Add item to stack
            target.Push("TestItem");
            //Pop from stack
            target.Pop();

            bool expected = true;
            bool actual = target.IsEmpty();

            Assert.AreEqual(expected, actual);
        }
Exemple #4
0
        public void Pop_OnStackWithOneItem_ReturnsCorrectFeedback()
        {
            //Assemble
            int stackTestSize = 1;
            Stack target = new Stack(stackTestSize);

            //Act
            target.Push("A");

            //Verify that pop has given the correct user-friendly feedback.
            string expected = "A";
            string actual = target.Pop();

            //Assert
            Assert.AreEqual(expected, actual);
        }
Exemple #5
0
        public void Pop_OnStackThatUsedToHaveItems_Returns()
        {
            //Assemble
            int stackTestSize = 3;
            Stack target = new Stack(stackTestSize);

            //Act
            target.Push("A");
            target.Push("B");
            target.Push("C");
            target.Pop();
            target.Pop();

            //Verify that an array can be filled and then all elements can be popped from it.
            string expected = "A";
            string actual = target.Pop();

            //Assert
            Assert.AreEqual(expected, actual);
        }
Exemple #6
0
        public void Pop_OnEmptyStack_ReturnsExceptionHandler()
        {
            //Near-arbitrary stack size for the creation of the stack:
            int stackTestSize = 5;
            Stack target = new Stack(stackTestSize);

            //Attempt to pop an empty stack - will return outofrange exception with a message.
            target.Pop();
        }
Exemple #7
0
        public void Peek_OnFilledThenEmptiedStack_ReturnCorrectItem()
        {
            //Assemble
            int stackTestSize = 3;
            Stack target = new Stack(stackTestSize);

            //Act
            target.Push("A");
            target.Push("B");
            target.Push("C");

            //Pop all but one item from the stack.
            target.Pop();
            target.Pop();

            string expected = target.Peek();
            string actual = "A";

            //Assert
            Assert.AreEqual(expected, actual);
        }