/** * @file testlinkedintstack.cs * @author Fred Sullivan */ using System; /** * A test program for the LinkedIntStack class from linkedintstack.cs. */ class TestLinkedIntStack { const int n = 5; static void Main() { // Make an empty stack. Console.WriteLine("Making new stack"); var s = new LinkedIntStack(); Console.WriteLine($"Empty={s.Empty}"); // Push the numbers 0 through 5 onto the stack. // The last push should throw an exception. try { for (var i = 0; i <= n; i++) { Console.Write($"Push({i}) "); s.Push(i); Console.WriteLine($"Empty={s.Empty}"); } } catch (InvalidOperationException e) { Console.WriteLine($"Caught InvalidOperationException: {e.Message}"); } Console.WriteLine(); // Pop the stack 6 times. // The numbers should come off in reverse order. // The last pop should throw an exception. try { for (var i = 0; i <= n; i++) { Console.WriteLine($"Pop()={s.Pop()} Empty={s.Empty}"); } } catch (InvalidOperationException e) { Console.WriteLine($"Caught InvalidOperationException: {e.Message}"); } } }