Beispiel #1
0
        private static void Test(IMyStack <int> stack)
        {
            foreach (var i in Enumerable.Range(0, 9))
            {
                stack.Push(i);
            }
            Console.WriteLine(stack.Pop());
            Console.WriteLine(stack.Peek());
            foreach (var i in Enumerable.Repeat(2, 5))
            {
                stack.Push(i);
            }

            try
            {
                while (true)
                {
                    Console.WriteLine(stack.Pop());
                }
            }
            catch (InvalidOperationException)
            {
                Console.WriteLine("Stack is empty");
            }
        }
Beispiel #2
0
        public void MyStack_2_Push_6_TwoTimesPopIsOkAfter3Push()
        {
            // Arrange
            IMyStack <string> stack    = DSBuilder.CreateMyStack();
            string            expected = "b";

            // Act
            stack.Push("a");
            stack.Push("b");
            stack.Push("c");
            stack.Pop();
            string actual = stack.Pop();

            // Assert
            Assert.AreEqual(expected, actual);
        }
        public void MyStack_2_Push_6_TwoTimesPopIsOkAfter3Push()
        {
            // Arrange
            IMyStack <int> stack    = DSBuilder.CreateMyArrayListStack();
            int            expected = 2;

            // Act
            stack.Push(1);
            stack.Push(2);
            stack.Push(3);
            stack.Pop();
            int actual = stack.Pop();

            // Assert
            Assert.AreEqual(expected, actual);
        }
Beispiel #4
0
        public void MyStack_4_Pop_1_ThrowsExceptionOnEmptyList()
        {
            // Arrange
            IMyStack <string> stack = DSBuilder.CreateMyStack();

            // Act & Assert
            Assert.Throws(typeof(MyStackEmptyException), () => stack.Pop());
        }
Beispiel #5
0
        public PrgState OneStep(PrgState state)
        {
            IMyStack <IStatement> stack = state.Stack;

            if (!(stack.IsEmpty()))
            {
                IStatement statement = stack.Pop();
                return(statement.Execute(state));
            }
            return(null);
        }
Beispiel #6
0
        public PrgState OneStep(PrgState state)
        {
            IMyStack <IStmt> stk = state.ExeStack;

            if (stk.IsEmpty())
            {
                throw new Exception("The execution stack is empty");
            }
            IStmt crtStmt = stk.Pop();

            return(crtStmt.Execute(state));
        }
Beispiel #7
0
        public void MyStack_4_Pop_2_IsEmptyReturnsTrueAfterTopOnOneElement()
        {
            // Arrange
            IMyStack <string> stack = DSBuilder.CreateMyStack();
            bool expected           = true;

            // Act
            stack.Push("a");
            stack.Pop();
            bool actual = stack.IsEmpty();

            // Assert
            Assert.AreEqual(expected, actual);
        }