public void Push_Three_Elements() { var stack = new StackWithArray <int>(); stack.Push(10); stack.Push(20); stack.Push(30); Assert.Equal(3, stack.Length); Assert.Equal(30, 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 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 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 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_Constructor_should_throw_exception_when_capacity_is_zero() { try { StackWithArray <int> st2 = new StackWithArray <int>(0); Assert.Fail(); } catch (ArgumentOutOfRangeException) { Assert.IsTrue(true); } 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 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(); } }
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 SetUp() { _stack = new StackWithArray <int>(_capacity); }
public void SetUp() { st = new StackWithArray <int>(); }