Exemplo n.º 1
0
        public void StackImplementation()
        {
            var input    = new[] { "1 2 3 4", "10 -2 3 4" };
            var expected = new[] { "4 2", "4 -2" };
            var result   = new StackImplementation(input).Run();

            AssertExtensions.AreEqual(expected, result);
        }
Exemplo n.º 2
0
        public void Exception_On_Too_Much_Push()
        {
            StackImplementation <int> stack = new StackImplementation <int>(3);

            stack.Push(1);
            stack.Push(2);
            stack.Push(3);
            Assert.Throws <ExceededSizeException>(() => stack.Push(4));
        }
Exemplo n.º 3
0
        public void Push()
        {
            StackImplementation <int> stack = new StackImplementation <int>(3);

            stack.Push(1);
            stack.Push(2);
            stack.Push(3);

            Assert.AreEqual(3, stack.Size);
        }
Exemplo n.º 4
0
        public void Peek_Element()
        {
            StackImplementation <int> stack = new StackImplementation <int>(3);

            stack.Push(1);
            stack.Push(2);
            stack.Push(3);
            int val = stack.Peek();

            Assert.AreEqual(3, val);
            Assert.AreEqual(3, stack.Size);
        }
Exemplo n.º 5
0
        public void Run()
        {
            StackImplementation <int> si = new StackImplementation <int>();

            si.Push(1);
            si.Push(2);
            si.Push(3);
            si.Push(4);
            Console.WriteLine("Size of the stack: {0}", si.Count);
            Console.WriteLine("Removing the top item from the stack: {0}", si.Pop());
            Console.WriteLine("Size of the stack: {0}", si.Count);
            Console.WriteLine("Value of the top item from the stack: {0}", si.Peek());
        }
Exemplo n.º 6
0
 public Stack(string s)
 {
     if (s == "array")
     {
         impl = new StackArray();
     }
     else if (s == "list")
     {
         impl = new StackList();
     }
     else
     {
         Console.WriteLine("Stack: unknown parameter");
     }
 }
Exemplo n.º 7
0
 public void StackImplementation()
 {
     var input = new[] { "1 2 3 4", "10 -2 3 4" };
     var expected = new[] { "4 2", "4 -2" };
     var result = new StackImplementation(input).Run();
     AssertExtensions.AreEqual(expected, result);
 }
Exemplo n.º 8
0
        public void Creation()
        {
            StackImplementation <int> stack = new StackImplementation <int>(3);

            Assert.AreEqual(0, stack.Size);
        }
Exemplo n.º 9
0
        public void Exception_On_Peek()
        {
            StackImplementation <int> stack = new StackImplementation <int>(3);

            Assert.Throws <ExpenditureProhibitedException>(() => stack.Peek());
        }