/// <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 IsEmptyTest_EmptyStack() { // Arrange var s = new StackContainer <int>(); // Assert Assert.IsTrue(s.IsEmpty()); Assert.AreEqual(0, s.Size()); }
public void PushTest_OneItem() { // Arrange var s = new StackContainer <int>(); // Action s.Push(10); // Assert Assert.AreEqual(1, s.Size()); }
public void IsEmptyTest_WithOneItem() { // Arrange var s = new StackContainer <int>(); s.Push(10); // Assert Assert.IsFalse(s.IsEmpty()); Assert.AreEqual(1, s.Size()); }
public void PushTest_TwoStringItems() { // Arrange var s = new StackContainer <string>(); // Action s.Push("item1"); s.Push("item2"); // Assert Assert.AreEqual(2, s.Size()); }
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); }
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); }