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
        // [Fact]
        public void CanPeek()
        {
            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);
            var output = stack.Peek();
        }
Example #3
0
        public void PushOne()
        {
            StackClass myStack = new StackClass();

            myStack.Push("my first element");
            Assert.IsFalse(myStack.IsEmpty, "IsEmpty muss falsch sein");
        }
Example #4
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 #5
0
        public void PopOne()
        {
            StackClass myStack = new StackClass();

            myStack.Push("my first element");
            myStack.Pop();
            Assert.IsTrue(myStack.IsEmpty);
        }
Example #6
0
        public void CanPushMultipleNodes()
        {
            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);
            Assert.Equal(22, stack.Top.Value);
        }
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 CanPushOntoStack()
        {
            StackClass <int> stack = new StackClass <int>();
            Node <int>       node  = new Node <int>();

            node.Value = 5;
            stack.Push(node.Value);
            Assert.Equal(5, stack.Top.Value);
        }
Example #9
0
        public void PushPopContentEqual()
        {
            int WasIchHabe = 1234;

            myStack.Push(WasIchHabe);

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

            Assert.AreEqual(WasIchHabe, WasIchBekomme);
        }
Example #10
0
        public static void RunPushMethod()
        {
            StackClass <int> stack = new StackClass <int>();

            Console.WriteLine("Choose a number to push to stack");
            int input1 = Convert.ToInt32(Console.ReadLine());



            stack.Push(input1);

            Console.WriteLine(stack.Peek());
        }
Example #11
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 #12
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 #13
0
        public void Push_Integer()
        {
            // Arrange
            int[] startingStack = { 1, 2, 3, 4 };
            int   theInteger    = 111;

            int[]      expected = { 1, 2, 3, 4, 111 };
            StackClass sc       = new StackClass(startingStack);

            // Act
            sc.Push(theInteger);

            // Assert
            int[] actual = sc.Stack;
            for (int i = 0; i < expected.Length; i++)
            {
                Assert.AreEqual(expected[i], actual[i], "The stack is not pushed correctly");
            }
        }
Example #14
0
 public void PushTest()
 {
     StackClass stack = new StackClass();
     stack.Push(7);
     Assert.IsFalse(stack.IsEmpty());
 }