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_IsFull_should_return_true_when_stack_has_capacity_number_of_elements() { StackWithArray <int> st2 = new StackWithArray <int>(2); st2.Push(1); st2.Push(3); Assert.AreEqual(true, st2.IsFull()); }
public void Push_Two_Elements() { var stack = new StackWithArray <int>(); stack.Push(10); stack.Push(20); Assert.Equal(2, stack.Length); Assert.Equal(20, stack.Top); Assert.Equal(10, stack.Bottom); }
public void Peek_Element_In_A_Stack_With_Two_Elements() { var stack = new StackWithArray <int>(); stack.Push(10); stack.Push(20); var item = stack.Peek(); Assert.Equal(20, item); Assert.Equal(2, stack.Length); Assert.Equal(20, stack.Top); Assert.Equal(10, stack.Bottom); }
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()); }
public void StackWithArray_IsFull_should_return_false_when_stack_has_less_elements() { StackWithArray <int> st2 = new StackWithArray <int>(2); st2.Push(1); Assert.AreEqual(false, st2.IsFull()); }
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 void Push(int value) { if (value <= Min()) { _minStack.Push(value); } base.Push(value); }
public void StackWithArray_Push_should_throw_exception_when_stack_is_full() { StackWithArray <int> st2 = new StackWithArray <int>(2); st2.Push(1); st2.Push(3); try { st2.Push(4); Assert.Fail(); } catch (InvalidOperationException ex) { Assert.AreEqual("The stack is full", ex.Message); } catch (Exception) { Assert.Fail(); } }
public void Stack_Is_Not_Empty() { var stack = new StackWithArray <int>(); stack.Push(10); var isEmpty = stack.IsEmpty(); Assert.False(isEmpty); Assert.Equal(1, stack.Length); Assert.Equal(10, stack.Top); Assert.Equal(10, stack.Bottom); }
public void Pop_An_Element_In_A_Stack_With_One_Element() { var stack = new StackWithArray <int>(); stack.Push(20); var item = stack.Pop(); Assert.Equal(20, item); Assert.Equal(0, stack.Length); Assert.Equal(0, stack.Top); Assert.Equal(0, stack.Bottom); }
public void Push_Nine_Elements() { var stack = new StackWithArray <int>(); for (int i = 1; i < 10; i++) { stack.Push(i); } Assert.Equal(9, stack.Length); Assert.Equal(9, stack.Top); Assert.Equal(1, stack.Bottom); }
public void Push_WhenCalled_ShouldAddItemToTopOfStack(int capacity, int range) { // Arrange _stack = new StackWithArray <int>(capacity); // Act for (var i = 1; i <= range; i++) { _stack.Push(i); } // Assert Assert.That(_stack.Peek(), Is.EqualTo(range)); Assert.That(_stack.Size, Is.EqualTo(range)); }
public void Size_WhenCalled_ShouldReturnNumberOfItems(int range) { // Arrange for (var i = 1; i <= range; i++) { _stack.Push(i); } // Act var result = _stack.Size; // Assert Assert.That(result, Is.EqualTo(range)); }
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 StackWithArray_IsEmpty_should_return_false_when_stack_is_not_empty() { st.Push(1); Assert.AreEqual(false, st.IsEmpty()); }