public static void Main() { Stack<int> testStack = new Stack<int>(); testStack.Push(5); testStack.Push(4); testStack.Push(3); testStack.Push(2); testStack.Pop(); foreach (var item in testStack) { Console.WriteLine("Item value: {0}", item); } Console.WriteLine("Stack items count: {0}", testStack.Count); Console.WriteLine("Stack capacity: {0}", testStack.Capacity); testStack.Push(6); testStack.Push(7); Console.WriteLine(new string('-', 15)); Console.WriteLine("After adding 2 more items"); Console.WriteLine("Stack items count: {0}", testStack.Count); Console.WriteLine("Stack capacity: {0}", testStack.Capacity); }
public void Count_PushSeveralPopAll_ReturnZero() { Stack target = new Stack(); //Push several items target.Push("a"); target.Push("b"); target.Push("c"); target.Push("d"); target.Push("e"); target.Push("f"); target.Push("g"); //Pop all items target.Pop(); target.Pop(); target.Pop(); target.Pop(); target.Pop(); target.Pop(); target.Pop(); int expected = 0; int actual = target.Count(); Assert.AreEqual(expected, actual); }
protected void btnPop_Click(object sender, EventArgs e) { Stack1 = (Stack)ViewState["Stack1"]; int? PoppedItem = Stack1.Pop(); if (PoppedItem != null) lblDisplay.Text ="The Popped item is " + PoppedItem.ToString() + "<br/>" + "The top index is" + Stack1.Top; else lblDisplay.Text = "Stack is empty"; //Response.Write(Stack1.Top); ViewState["Stack1"] = Stack1; }
public void TestStackValues() { Stack testStack = new Stack(); int numberOfAddedElements = 12; for (int i = 0; i < numberOfAddedElements; i++) { testStack.Push(10 + i); } for (int i = 0; i < numberOfAddedElements; i++) { int currentElement = testStack.Pop(); Assert.AreEqual(21 - i, currentElement, "The elements are not being popped correctly"); } }
public void TestPopEmptyList() { Stack testStack = new Stack(); testStack.Pop(); }
public void Pop_PushSeveralItemsPopOne_ReturnLastItem() { Stack target = new Stack(); target.Push("a"); target.Push("b"); target.Push("c"); target.Push("d"); target.Push("e"); target.Push("f"); String expected = "f"; String actual = target.Pop(); Assert.AreEqual(expected, actual); }
public void Pop_PushSeveralItemsPopOneAndCount_ReturnNMinusOne() { Stack target = new Stack(); target.Push("a"); target.Push("b"); target.Push("c"); target.Push("d"); target.Push("e"); target.Push("f"); target.Pop(); int expected = 5; int actual = target.Count(); Assert.AreEqual(expected, actual); }
public void Pop_PushOneItemPop_ReturnLastItem() { Stack target = new Stack(); String testItem="My apples are bad"; target.Push(testItem); String expected = testItem; String actual = target.Pop(); Assert.AreEqual(expected, actual); }
public void Pop_PushOneItemPopCount_ReturnZero() { Stack target = new Stack(); String testItem = "My apples are bad"; target.Push(testItem); target.Pop(); int expected = 0; int actual = target.Count(); Assert.AreEqual(expected, actual); }
public void Pop_CalledOnNewStack_ReturnException() { Stack target = new Stack(); target.Pop(); Assert.Fail(); }
public void IsEmpty_PushSeveralAndPopAll_ReturnTrue() { Stack target = new Stack(); //Push several items target.Push("a"); target.Push("b"); target.Push("c"); target.Push("d"); target.Push("e"); target.Push("f"); target.Push("g"); //Pop all items target.Pop(); target.Pop(); target.Pop(); target.Pop(); target.Pop(); target.Pop(); target.Pop(); Boolean expected = true; Boolean actual = target.IsEmpty(); Assert.AreEqual(expected, actual); }