public void StackWithArray() { StackWithArray stack = new StackWithArray(); stack.Push(1); Assert.False(stack.IsEmpty); Assert.Equal(1, stack.Pop()); Assert.True(stack.IsEmpty); stack.Push(1); stack.Push(2); Assert.Equal(2, stack.Pop()); }
static void Main(string[] args) { var stack = new StackWithArray(10); stack.Push("sej"); stack.Push("er"); stack.Push("Nicolai"); Console.WriteLine($"Top: {stack.Top}"); stack.ToggleTop(); Console.WriteLine("Running ToggleTop()..."); Console.WriteLine($"Top: {stack.Top}"); stack.ToggleTop(); Console.WriteLine("Running ToggleTop()..."); Console.WriteLine($"Top: {stack.Top}"); Console.WriteLine("Emptying stack..."); while (!stack.Empty) { Console.WriteLine(stack.Top); stack.Pop(); } Console.ReadLine(); }
public void StackWithArray_Pop_should_throw_exception_when_stack_is_empty() { try { st.Pop(); Assert.Fail(); } catch (InvalidOperationException ex) { Assert.AreEqual("The stack is empty", ex.Message); } catch (Exception) { Assert.Fail(); } }
public void Pop_Two_Elements_In_A_Stack_With_Three_Elements() { var stack = new StackWithArray <int>(); stack.Push(10); stack.Push(20); stack.Push(30); var item1 = stack.Pop(); var item2 = stack.Pop(); Assert.Equal(30, item1); Assert.Equal(20, item2); Assert.Equal(1, stack.Length); Assert.Equal(10, stack.Top); Assert.Equal(10, stack.Bottom); }
public override int Pop() { if (Peek() == Min()) { _minStack.Pop(); } return(base.Pop()); }
public void Pop_An_Element_In_A_Stack_With_No_Element() { var stack = new StackWithArray <int>(); var item = stack.Pop(); Assert.Equal(0, item); Assert.Equal(0, stack.Length); Assert.Equal(0, stack.Top); Assert.Equal(0, stack.Bottom); }
private static void Main() { IStackWithArray<int> testStack = new StackWithArray<int>(); Console.WriteLine("Push"); testStack.Push(23); testStack.Push(13); testStack.Push(7); testStack.Push(5); testStack.Push(15); testStack.Push(243); testStack.Push(544); testStack.Push(42); Console.WriteLine("Pushed: " + string.Join(", ", testStack)); Console.WriteLine("Peek: " + testStack.Peek()); Console.WriteLine("Pop: " + testStack.Pop()); Console.WriteLine("Poped: " + string.Join(", ", testStack)); Console.WriteLine("Count: " + testStack.Count()); Console.WriteLine("Contains 13: " + testStack.Contains(13)); Console.WriteLine("Contains 42: " + testStack.Contains(42)); Console.WriteLine("Trim excess"); testStack.TrimExcess(); }
private static void Main() { IStackWithArray <int> testStack = new StackWithArray <int>(); Console.WriteLine("Push"); testStack.Push(23); testStack.Push(13); testStack.Push(7); testStack.Push(5); testStack.Push(15); testStack.Push(243); testStack.Push(544); testStack.Push(42); Console.WriteLine("Pushed: " + string.Join(", ", testStack)); Console.WriteLine("Peek: " + testStack.Peek()); Console.WriteLine("Pop: " + testStack.Pop()); Console.WriteLine("Poped: " + string.Join(", ", testStack)); Console.WriteLine("Count: " + testStack.Count()); Console.WriteLine("Contains 13: " + testStack.Contains(13)); Console.WriteLine("Contains 42: " + testStack.Contains(42)); Console.WriteLine("Trim excess"); testStack.TrimExcess(); }
public void Pop_WhenStackIsEmpty_ShouldThrowInvalidOperationException() { // Arrange & Act & Assert Assert.Throws <InvalidOperationException>(() => _stack.Pop()); }