Example #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");
            }
        }
Example #2
0
        public PrgState Execute(PrgState state)
        {
            IMyStack <IStmt> stk = state.ExeStack;

            stk.Push(snd);
            stk.Push(first);
            return(state);
        }
Example #3
0
        public void MyStack_2_Push_5_PopIsOkAfter3Push()
        {
            // Arrange
            IMyStack <string> stack    = DSBuilder.CreateMyStack();
            string            expected = "c";

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

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

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

            // Assert
            Assert.AreEqual(expected, actual);
        }
Example #5
0
        public PrgState Execute(PrgState state)
        {
            IMyStack <IStmt>            stk = state.ExeStack;
            IMyDictionary <string, int> sym = state.SymTable;
            int val = expr.Eval(sym);

            if (val == 0)
            {
                stk.Push(elses);
            }
            else
            {
                stk.Push(ifs);
            }
            return(state);
        }
Example #6
0
 public PrgState(IMyStack <IStmt> exe, IMyDictionary <String, int> d, IMyList <int> l, IMyFileTable <int, FileData> ft, IStmt orig)
 {
     exeStack    = exe;
     symTable    = d;
     messages    = l;
     fileTable   = ft;
     originalPrg = orig;
     exeStack.Push(orig);
 }
Example #7
0
        public void MyStack_2_Push_1_IsEmptyReturnsFalse()
        {
            // Arrange
            IMyStack <string> stack = DSBuilder.CreateMyStack();
            bool expected           = false;

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

            // Assert
            Assert.AreEqual(expected, actual);
        }
Example #8
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);
        }
        public void MyStack_3_Top_2_IsEmptyReturnsFalseAfterTopOnOneElement()
        {
            // Arrange
            IMyStack <int> stack    = DSBuilder.CreateMyArrayListStack();
            bool           expected = false;

            // Act
            stack.Push(1);
            stack.Top();
            bool actual = stack.IsEmpty();

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