Exemplo n.º 1
0
        public void ValidatesPoppedObjEqualsPushedObj(int value)
        {
            IStack <int> intStack = new SampleStack <int>();

            intStack.Push(value);
            Assert.AreEqual(value, intStack.Pop());
        }
Exemplo n.º 2
0
        public void ValidatesUnderflowCondition()
        {
            IStack <int> intStack = new SampleStack <int>();
            var          ex       = Assert.Throws <InvalidOperationException>(() => intStack.Pop());

            Assert.That(ex.Message, Is.EqualTo("Underflow!"));
        }
Exemplo n.º 3
0
        public void ValidatesIsEmptyFollowedByTop()
        {
            IStack <int> intStack = new SampleStack <int>();

            intStack.Push(1);
            Console.Write(intStack.Top());
            Assert.False(intStack.IsEmpty());
        }
Exemplo n.º 4
0
        public void ValidatesizeAfterPop()
        {
            IStack <int> intStack = new SampleStack <int>();

            intStack.Push(1);
            intStack.Pop();
            Assert.True(intStack.IsEmpty());
            Assert.AreEqual(0, intStack.Size());
        }
Exemplo n.º 5
0
        public void ValidatesSize()
        {
            IStack <int> intStack = new SampleStack <int>();

            intStack.Push(1);
            intStack.Push(3);
            intStack.Push(2);
            Assert.AreEqual(3, intStack.Size());
        }
Exemplo n.º 6
0
        public void ValidatesPopElement()
        {
            IStack <int> intStack = new SampleStack <int>();

            intStack.Push(1);
            intStack.Push(3);
            intStack.Push(2);
            intStack.Pop();
            Assert.AreEqual(2, intStack.Size());
        }
Exemplo n.º 7
0
        public void GivenStackWithLengthZero_Pop_ShouldThrowIndexOutOfRangeException()
        {
            //Arrange
            var size        = 0;
            var sampleStack = new SampleStack(size);

            //Act
            Action action = () => sampleStack.Pop();

            //Assert
            Assert.ThrowsException <IndexOutOfRangeException>(action);
        }
Exemplo n.º 8
0
        public void GivenTwoItems_Push_CountShouldBeTwo()
        {
            //Arrange
            var size        = 5;
            var sampleStack = new SampleStack(size);

            //Act
            sampleStack.Push(1);
            sampleStack.Push(2);

            //Assert
            Assert.AreEqual(2, sampleStack.Count);
        }
Exemplo n.º 9
0
        public void ValidatesRemovedObjectsBackwards()
        {
            IStack <int> intStack = new SampleStack <int>();

            int[] list = { 1, 3, 5 };
            for (int i = 0; i < list.Length; ++i)
            {
                intStack.Push(list[i]);
            }
            for (int i = list.Length - 1; i >= 0; --i)
            {
                Assert.AreEqual(list[i], intStack.Pop());
            }
        }
Exemplo n.º 10
0
        public void GivenStackWithFullCapacity_Push_ShouldThrowStackOverflowException()
        {
            //Arrange
            var size        = 5;
            var sampleStack = new SampleStack(size);

            sampleStack.Push(1);
            sampleStack.Push(2);
            sampleStack.Push(3);
            sampleStack.Push(4);
            sampleStack.Push(5);

            //Act
            Action action = () => sampleStack.Push(6);

            //Assert
            Assert.ThrowsException <StackOverflowException>(action);
        }
Exemplo n.º 11
0
        public void GivenStackWithLengthFive_Pop_TwoItems_LengthOfStackShouldBeThree()
        {
            //Arrange
            var size        = 5;
            var sampleStack = new SampleStack(size);

            sampleStack.Push(1);
            sampleStack.Push(2);
            sampleStack.Push(3);
            sampleStack.Push(4);
            sampleStack.Push(5);

            //Act
            sampleStack.Pop();
            sampleStack.Pop();

            //Assert
            Assert.AreEqual(3, sampleStack.Count);
        }