static void Main(string[] args) { IVerifyProgram program = null; // Implement 2 stacks in an array program = new Implement2StacksInArray(); program.VerifyProgram(); }
public void VerifyProgram() { // 1. Test push and pop on an empty stack // 2. Test push to full stack // 3. Test pop to empty stack // 4. Test push again from an emptied stack // 5. Test boundary conditions like testing with just 2 elements. Less than 2 elements etc. // 1. Implement2StacksInArray stack = new Implement2StacksInArray(); int s1_val = 0; int s2_val = 0; stack.Create(6); stack.Push(1, 10); stack.Pop(ref s1_val, ref s2_val); Debug.Assert(s1_val == 1); Debug.Assert(s2_val == 10); // 2. stack.Push(1, 10); stack.Push(2, 11); stack.Push(3, 12); try { stack.Push(4, 13); } catch (Exception ex) { Debug.Assert(ex.Message.Contains("full")); } // 3. stack.Pop(ref s1_val, ref s2_val); Debug.Assert(s1_val == 3); Debug.Assert(s2_val == 12); stack.Pop(ref s1_val, ref s2_val); Debug.Assert(s1_val == 2); Debug.Assert(s2_val == 11); stack.Pop(ref s1_val, ref s2_val); Debug.Assert(s1_val == 1); Debug.Assert(s2_val == 10); try { stack.Pop(ref s1_val, ref s2_val); } catch (Exception ex) { Debug.Assert(ex.Message.Contains("empty")); } // 4. stack.Push(1, 10); stack.Pop(ref s1_val, ref s2_val); Debug.Assert(s1_val == 1); Debug.Assert(s2_val == 10); // 5. stack.Create(2); stack.Push(1, 10); try { stack.Push(2, 11); } catch (Exception ex) { Debug.Assert(ex.Message.Contains("full")); } Debug.Assert(stack.Create(1) == false); }