Example #1
0
 public void PopTest()
 {
     StackClass stack = new StackClass();
     stack.Pop(56);
     stack.Push(4);
     stack.Pop(4);
     Assert.IsTrue(stack.IsEmpty());
     stack.Push(4);
     stack.Pop(48);
 }
Example #2
0
    private static void GetStack(StackClass <int> stackClass)
    {
        string input = string.Empty;

        while ((input = Console.ReadLine()) != "END")
        {
            string[] commandOfArgs = input.Split(new[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries);
            string   command       = commandOfArgs[0];

            try
            {
                switch (command)
                {
                case "Pop":
                    stackClass.Pop();
                    break;

                case "Push":
                    int[] elements = commandOfArgs
                                     .Skip(1)
                                     .Select(int.Parse)
                                     .ToArray();
                    stackClass.Push(elements);
                    break;

                default:
                    break;
                }
            }
            catch (ArgumentException ArgEx)
            {
                Console.WriteLine(ArgEx.Message);
            }
        }
    }
Example #3
0
        public void PopOne()
        {
            StackClass myStack = new StackClass();

            myStack.Push("my first element");
            myStack.Pop();
            Assert.IsTrue(myStack.IsEmpty);
        }
Example #4
0
        public void PushPopContentEqual()
        {
            int WasIchHabe = 1234;

            myStack.Push(WasIchHabe);

            int WasIchBekomme = (int)myStack.Pop();

            Assert.AreEqual(WasIchHabe, WasIchBekomme);
        }
Example #5
0
        public void CanEmptyStack()
        {
            StackClass <int> stack = new StackClass <int>();
            Node <int>       node  = new Node <int>();

            node.Value = 5;
            stack.Push(node.Value);
            Node <int> node2 = new Node <int>();

            node.Value = 15;
            stack.Push(node.Value);
            Node <int> node3 = new Node <int>();

            node.Value = 22;
            stack.Push(node.Value);
            while (node.Next != null)
            {
                stack.Pop();
            }
            stack.Pop();
            var result = stack.Peek();

            Assert.Null(result);
        }
Example #6
0
        static void Stack()
        {
            var _stack = new StackClass();

            int ini = 1;
            int max = 5;

            for (int i = ini; i <= max; i++)
            {
                _stack.Push(i);
            }
            _stack.Clear();
            for (int i = ini; i <= max; i++)
            {
                Console.WriteLine(_stack.Pop());
            }
        }
Example #7
0
        public void CanPopOffStack()
        {
            StackClass <int> stack = new StackClass <int>();
            Node <int>       node  = new Node <int>();

            node.Value = 5;
            stack.Push(node.Value);
            Node <int> node2 = new Node <int>();

            node.Value = 15;
            stack.Push(node.Value);
            Node <int> node3 = new Node <int>();

            node.Value = 22;
            stack.Push(node.Value);
            stack.Pop();
            Assert.Equal(15, stack.Top.Value);
        }
Example #8
0
 public void PopOne()
 {
     myStack.Push("first element");
     myStack.Pop();
     Assert.IsTrue(myStack.IsEmpty);
 }