public void StackWithArray_Peek_should_throw_exception_when_stack_is_empty()
 {
     try
     {
         st.Peek();
         Assert.Fail();
     }
     catch (InvalidOperationException ex)
     {
         Assert.AreEqual("The stack is empty", ex.Message);
     }
     catch (Exception)
     {
         Assert.Fail();
     }
 }
Exemplo n.º 2
0
        public void Peek_An_Element_In_A_Stack_With_No_Element()
        {
            var stack = new StackWithArray <int>();

            var item = stack.Peek();

            Assert.Equal(0, item);
            Assert.Equal(0, stack.Length);
            Assert.Equal(0, stack.Top);
            Assert.Equal(0, stack.Bottom);
        }
Exemplo n.º 3
0
 public int Min()
 {
     if (_minStack.IsEmpty())
     {
         return(int.MaxValue);
     }
     else
     {
         return(_minStack.Peek());
     }
 }
Exemplo n.º 4
0
        public void Peek_Element_In_A_Stack_With_One_Element()
        {
            var stack = new StackWithArray <int>();

            stack.Push(20);

            var item = stack.Peek();

            Assert.Equal(20, item);
            Assert.Equal(1, stack.Length);
            Assert.Equal(20, stack.Top);
            Assert.Equal(20, stack.Bottom);
        }
Exemplo n.º 5
0
        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));
        }
Exemplo n.º 6
0
 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();
 }
Exemplo n.º 7
0
        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();
        }
Exemplo n.º 8
0
 public void Peek_WhenStackIsEmpty_ShouldThrowInvalidOperationException()
 {
     // Arrange & Act & Assert
     Assert.Throws <InvalidOperationException>(() => _stack.Peek());
 }