/// <summary> /// Q2. Stack implementation /// </summary> private static void Question2() { Console.WriteLine("Q2: Stack implementation"); var s = new StackContainer <string>(); Console.WriteLine($"Stack initialized. stack size: {s.Size()} stack is empty? {s.IsEmpty()}"); s.Push("item1"); Console.WriteLine($"Push \"item1\" into stack. stack size: {s.Size()} stack is empty? {s.IsEmpty()}"); s.Push("item2"); Console.WriteLine($"Push \"item2\" into stack. stack size: {s.Size()} stack is empty? {s.IsEmpty()}"); var popItem = s.Pop(); Console.WriteLine($"Pop \"{popItem}\" out of stack. stack size: {s.Size()} stack is empty? {s.IsEmpty()}"); popItem = s.Pop(); Console.WriteLine($"Pop \"{popItem}\" out of stack. stack size: {s.Size()} stack is empty? {s.IsEmpty()}"); Console.WriteLine(); }
public void PopTest_NoItem() { // Arrange var s = new StackContainer <string>(); // Action var item = s.Pop(); }
public void StackContainerTest() { // Arrange var s = new StackContainer <int>(); // Action s.Push(1); s.Push(2); var popItem1 = s.Pop(); s.Push(3); var popItem2 = s.Pop(); var popItem3 = s.Pop(); // Assert Assert.IsTrue(s.IsEmpty()); Assert.AreEqual(0, s.Size()); Assert.AreEqual(2, popItem1); Assert.AreEqual(3, popItem2); Assert.AreEqual(1, popItem3); }
public void PopTest_OneItem() { // Arrange var s = new StackContainer <string>(); // Action s.Push("item1"); s.Push("item2"); var item = s.Pop(); // Assert Assert.AreEqual(1, s.Size()); Assert.AreEqual("item2", item); }