Ejemplo n.º 1
0
        public void DoesPeekRetrieveTopWhenStackIsNotEmpty()
        {
            LinkedListTypedStack stack = new LinkedListTypedStack();

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

            int expected = 2;
            int actual   = ((Node)stack.Peek()).Data;

            Assert.AreEqual(expected, actual);

            int expected_size = 2;
            int actual_size   = stack.Size;

            Assert.AreEqual(expected_size, actual_size);
        }
Ejemplo n.º 2
0
        public void DoesPushAddElementIntoStackWhenStackIsNotEmpty()
        {
            LinkedListTypedStack stack = new LinkedListTypedStack();

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

            string expected = "2 1 ";
            string actual   = stack.DisplayElements();

            Assert.AreEqual(expected, actual);

            int expected_top_val = 2;
            int actual_top_val   = ((Node)stack.Top).Data;

            Assert.AreEqual(expected_top_val, actual_top_val);
        }
Ejemplo n.º 3
0
        public void DoesIsEmptyReturnsFaleWhenStackIsNotEmpty() // Depends on push() method
        {
            LinkedListTypedStack stack = new LinkedListTypedStack();

            stack.Push(1);

            bool expected = false;
            bool actual   = stack.IsEmpty();

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 4
0
        public void DoesPopMethodRetrieveTopWhenStackHasOnlyOneElement()
        {
            LinkedListTypedStack stack = new LinkedListTypedStack();

            stack.Push(1);

            int expected = 1;
            int actual   = ((Node)stack.Pop()).Data;

            Assert.AreEqual(expected, actual);

            Assert.AreEqual(true, stack.IsEmpty());
            Assert.IsNull(stack.Top);
        }
Ejemplo n.º 5
0
        public void DoesPeekRetrieveTopWhenStackHasOnlyOneElement()
        {
            LinkedListTypedStack stack = new LinkedListTypedStack();

            stack.Push(1);

            int expected = 1;
            int actual   = ((Node)stack.Peek()).Data;

            Assert.AreEqual(expected, actual);

            int expected_size = 1;
            int actual_size   = stack.Size;

            Assert.AreEqual(expected_size, actual_size);
        }