예제 #1
0
        public void Stack_Count_ReturnsZeroIfStackIsEmpty()
        {
            Stack stack = new Stack();
            int expectedNumberOfItems = 0;

            int stackCountValue = stack.Count();

            Assert.AreEqual(expectedNumberOfItems, stackCountValue);
        }
예제 #2
0
        public void Stack_IsEmpty_ReturnsFalseOnNonEmptyStack()
        {
            Stack stack = new Stack();
            bool expectedIsEmptyReturnValue = false;

            stack.Push("Hello worldz");
            stack.Push("Hi again");

            bool actualIsEmptyReturnValue = stack.IsEmpty();

            Assert.AreEqual(expectedIsEmptyReturnValue, actualIsEmptyReturnValue);
        }
예제 #3
0
        public void Stack_Count_ReturnsZeroIfPreviouslyPopulatedStackIsEmpty()
        {
            Stack stack = new Stack();
            int expectedNumberOfItems = 0;

            stack.Push("Some data");
            stack.Pop();

            int stackCountValue = stack.Count();

            Assert.AreEqual(expectedNumberOfItems, stackCountValue);
        }
예제 #4
0
        public void Stack_Count_ReturnsCorrectNumberOfItems()
        {
            Stack stack = new Stack();
            int expectedNumberOfItems = 4;

            stack.Push("Data");
            stack.Push("More data");
            stack.Push("Even more data");
            stack.Push("DATA");

            int actualNumberOfItems = stack.Count();

            Assert.AreEqual(expectedNumberOfItems, actualNumberOfItems);
        }
예제 #5
0
        public void Stack_Count_ReturnsCorrectNumberOfItemsAfterMultiplePops()
        {
            Stack stack = new Stack();
            int expectedNumberOfItems = 2;

            stack.Push("Data");
            stack.Push("More data");
            stack.Push("Even more data");
            stack.Push("DATA");
            stack.Push("DATAAA!!!!!");

            stack.Pop();
            stack.Pop();
            stack.Pop();

            int numberOfItemsAfterMultiplePops = stack.Count();

            Assert.AreEqual(expectedNumberOfItems, numberOfItemsAfterMultiplePops);
        }
예제 #6
0
 public void Stack_Pop_ThrowsExceptionWhenStackIsEmpty()
 {
     Stack stack = new Stack();
     stack.Pop();
 }
예제 #7
0
        public void Stack_Pop_ThrowsExceptionWhenPreviouslyPopulatedStackIsEmpty()
        {
            Stack stack = new Stack();

            stack.Push("Some data");
            stack.Push("More data");

            // Pop the existing items
            stack.Pop();
            stack.Pop();

            // No items left, try Pop again
            stack.Pop();
        }
예제 #8
0
        public void Stack_IsEmpty_ReturnsTrueOnPreviouslyPopulatedEmptyStack()
        {
            Stack stack = new Stack();
            bool expectedIsEmptyReturnValue = true;

            stack.Push("Dataz");
            stack.Push("More dataz");

            stack.Pop();
            stack.Pop();

            bool actualIsEmptyReturnValue = stack.IsEmpty();

            Assert.AreEqual(actualIsEmptyReturnValue, expectedIsEmptyReturnValue);
        }
예제 #9
0
        public void Stack_Push_MultipleItemsToEmptyStack()
        {
            Stack stack = new Stack();
            int expectedStackCount = 3;

            stack.Push("First item");
            stack.Push("Second item");
            stack.Push("Third item");

            int actualStackCount = stack.Count();

            Assert.AreEqual(expectedStackCount, actualStackCount);
        }
예제 #10
0
        public void Stack_Pop_RemovesNodeFromStackWithOnlyOneNode()
        {
            Stack stack = new Stack();
            int expectedCount = 0;

            stack.Push("Item to be popped");
            stack.Pop();

            int actualCount = stack.Count();

            Assert.AreEqual(expectedCount, actualCount);
        }
예제 #11
0
 public void Stack_Peek_ThrowsExceptionIfStackIsEmpty()
 {
     Stack stack = new Stack();
     stack.Peek();
 }
예제 #12
0
        public void Stack_Peek_ThrowsExceptionIfPreviouslyPopulatedStackIsEmpty()
        {
            Stack stack = new Stack();

            stack.Push("Some data");
            stack.Push("More data");

            stack.Pop();
            stack.Pop();

            stack.Peek();
        }
예제 #13
0
        public void Stack_Peek_ReturnsLastAddedItem()
        {
            Stack stack = new Stack();
            String lastStackItemValue = "Last item value";

            stack.Push("First item");
            stack.Push("Second item");
            stack.Push(lastStackItemValue);

            String peekValue = stack.Peek();

            Assert.AreEqual(lastStackItemValue, peekValue);
        }
예제 #14
0
        public void Stack_Peek_DoesntRemoveNode()
        {
            Stack stack = new Stack();

            stack.Push("First Item");
            stack.Push("Second Item");

            int countBeforePeeking = stack.Count();

            stack.Peek();

            int countAfterPeeking = stack.Count();

            Assert.AreEqual(countBeforePeeking, countAfterPeeking);
        }
예제 #15
0
        public void Stack_Push_ItemToEmptyStack()
        {
            Stack stack = new Stack();
            int expectedStackCount = 1;

            stack.Push("This is a string :)");

            int actualStackCount = stack.Count();

            Assert.AreEqual(expectedStackCount, actualStackCount);
        }
예제 #16
0
        public void Stack_Push_ItemToPreviouslyPopulatedEmptyStack()
        {
            Stack stack = new Stack();
            int expectedStackCount = 1;

            stack.Push("This is a string :)");
            stack.Push("This is another string :)");

            stack.Pop();
            stack.Pop();

            stack.Push("Some data");

            int actualStackCount = stack.Count();

            Assert.AreEqual(expectedStackCount, actualStackCount);
        }
예제 #17
0
        public void Stack_Pop_ReturnsCorrectValueForMultiplePops()
        {
            Stack stack = new Stack();
            String[] stackValues = { "data 1", "data 2", "data 3", "data 4" };

            foreach (String valueToAdd in stackValues)
            {
                stack.Push(valueToAdd);
            }

            Array.Reverse(stackValues);

            foreach (String expectedValue in stackValues)
            {
                String actualValue = stack.Pop();
                Assert.AreEqual(expectedValue, actualValue);
            }
        }
예제 #18
0
        public void Stack_Push_MultipleItemsToStackAfterMultiplePops()
        {
            Stack stack = new Stack();
            int expectedStackCount = 3;

            stack.Push("First item");
            stack.Push("Second item");
            stack.Push("Third item");

            stack.Pop();
            stack.Pop();

            stack.Push("Hello");
            stack.Push("Last item");

            int actualStackCount = stack.Count();

            Assert.AreEqual(expectedStackCount, actualStackCount);
        }
예제 #19
0
        public void Stack_Pop_ReturnsCorrectValueFromStackWithMultipleItems()
        {
            Stack stack = new Stack();
            String expectedPopValue = "Something";

            stack.Push("Random data");
            stack.Push("More random data");
            stack.Push(expectedPopValue);

            String actualPopValue = stack.Pop();

            Assert.AreEqual(expectedPopValue, actualPopValue);
        }
예제 #20
0
        public void Stack_Pop_ReturnsCorrectValueFromStackWithMultipleItemsAfterPoppingThenPushing()
        {
            Stack stack = new Stack();
            String expectedPopValue = "Something";

            stack.Push("Random data");
            stack.Push("More random data");
            stack.Push("Some data that will be popped");
            stack.Push("Some more data that will be popped");

            stack.Pop();
            stack.Pop();

            stack.Push(expectedPopValue);

            String actualPopValue = stack.Pop();

            Assert.AreEqual(expectedPopValue, actualPopValue);
        }
예제 #21
0
        public void Stack_Pop_ReturnsCorrectValueFromStackWithOnlyOneNode()
        {
            Stack stack = new Stack();
            String itemValue = "This is the correct value";

            stack.Push(itemValue);

            String popValue = stack.Pop();

            Assert.AreEqual(itemValue, popValue);
        }
예제 #22
0
        public void Stack_IsEmpty_ReturnsFalseOnNonEmptyStackAfterMultiplePops()
        {
            Stack stack = new Stack();
            bool expectedIsEmptyReturnValue = false;

            stack.Push("Hello worldz");
            stack.Push("Hi again");
            stack.Push("Hi again, again");
            stack.Push("Hi again, but I'll be popped soon :(");

            stack.Pop();
            stack.Pop();

            bool actualIsEmptyReturnValue = stack.IsEmpty();

            Assert.AreEqual(expectedIsEmptyReturnValue, actualIsEmptyReturnValue);
        }
예제 #23
0
        public void Stack_IsEmpty_ReturnsTrueOnNewlyCreatedStack()
        {
            Stack stack = new Stack();
            bool expectedIsEmptyReturnValue = true;

            bool actualIsEmptyReturnValue = stack.IsEmpty();

            Assert.AreEqual(expectedIsEmptyReturnValue, actualIsEmptyReturnValue);
        }