Exemplo n.º 1
0
        public static void TestStack2Methods()
        {
            var stack = new Stack2 <int>();

            Assert.AreEqual(0, stack.Size(), "TestSize must be 0, but not");
            stack.Push(1);
            Assert.AreEqual(1, stack.Size(), "TestSize must be 1, but not");
            stack.Push(2);
            Assert.AreEqual(2, stack.Size(), "TestSize must be 2, but not");
            stack.Push(3);
            Assert.AreEqual(3, stack.Size(), "TestSize must be 3, but not");
            var top = stack.Peek();

            Assert.AreEqual(3, top, "TestStackMethods Peek value must be 3");
            var value = stack.Pop();

            Assert.AreEqual(3, value, "TestStackMethods Pop value must be 3");
            Assert.AreEqual(2, stack.Size(), "TestSize must be 2, but not");
            value = stack.Pop();
            Assert.AreEqual(2, value, "TestStackMethods Pop value must be 2");
            Assert.AreEqual(1, stack.Size(), "TestSize must be 1, but not");
            value = stack.Pop();
            Assert.AreEqual(1, value, "TestStackMethods Pop value must be 1");
            Assert.AreEqual(0, stack.Size(), "TestSize must be 0, but not");
            value = stack.Pop();
            Assert.AreEqual(0, stack.Peek(), "TestStackMethods stack is not empty");
            Assert.AreEqual(0, value, "TestStackMethods stack is not empty");
            Assert.AreEqual(0, stack.Peek(), "TestStackMethods stack is not empty");
        }
Exemplo n.º 2
0
        public void Test_Pop()
        {
            var stack = new Stack2();

            stack.Push(1);
            stack.Push(2);
            stack.Push(3);
            var popped = stack.Pop();

            Assert.AreEqual(3, popped);
        }
        public void Pop_StackWithAFewObjects_RemoveObjectFromStack()
        {
            //Arrange
            var stack = new Stack2 <string>();

            stack.Push("a");
            stack.Push("b");
            stack.Push("c");

            //Act
            var result = stack.Pop();

            //Assert
            Assert.That(stack.Count, Is.EqualTo(2));
        }
        public void Peek_StackWithObjects_DoesNotRemoveObjectOnTopOfTheStack()
        {
            //Arrange
            var stack = new Stack2 <string>();

            stack.Push("a");
            stack.Push("b");
            stack.Push("c");

            //Act
            var result = stack.Peek();

            //Assert
            Assert.That(stack.Count, Is.EqualTo(3));
        }
        public void Peek_StackWithObjects_ReturnObjectOnTopOfTheStack()
        {
            //Arrange
            var stack = new Stack2 <string>();

            stack.Push("a");
            stack.Push("b");
            stack.Push("c");

            //Act
            var result = stack.Peek();

            //Assert
            Assert.That(result, Is.EqualTo("c"));
        }
        public void Pop_StackWithAFewObjects_ReturnObjectOnTheTop()
        {
            //Arrange
            var stack = new Stack2 <string>();

            stack.Push("a");
            stack.Push("b");
            stack.Push("c");

            //Act
            var result = stack.Pop();

            //Assert
            Assert.That(result, Is.EqualTo("c"));
            //pre uistenie sa ze test funguje spravne je treba po jeho napisani a uspesnom zbehnuti zmenit business logiku s predpokladom ze by mal test zlyhat pre overenie
        }
Exemplo n.º 7
0
        public void Test_Push()
        {
            var stack  = new Stack2();
            var pushed = stack.Push(1);

            Assert.AreEqual(1, pushed);
        }
    static void Main()
    {
        Stack2 stk1 = new Stack2(10);
        char   ch;
        int    i;

        // Put some characters into stk1.
        Console.WriteLine("Push A through J onto stk1.");
        for (i = 0; !stk1.IsFull(); i++)
        {
            stk1.Push((char)('A' + i));
        }
        // Create a copy of stck1.
        Stack2 stk2 = new Stack2(stk1);

        // Display the contents of stk1.
        Console.Write("Contents of stk1: ");
        while (!stk1.IsEmpty())
        {
            ch = stk1.Pop();
            Console.Write(ch);
        }
        Console.WriteLine();
        Console.Write("Contents of stk2: ");
        while (!stk2.IsEmpty())
        {
            ch = stk2.Pop();
            Console.Write(ch);
        }
        Console.WriteLine("\n");
    }
        public void Count_OneObjectPushedToStack_ReturnOne()
        {
            var stack = new Stack2 <string>();

            stack.Push("a");

            Assert.That(stack.Count, Is.EqualTo(1));
        }
        public void Push_ValidArg_AddObjectToStack()
        {
            var stack = new Stack2 <string>();

            stack.Push("a");

            Assert.That(stack.Count, Is.EqualTo(1));
        }
Exemplo n.º 11
0
        public void Test_Not_Empty()
        {
            var stack = new Stack2();

            stack.Push(1);

            Assert.AreEqual(false, stack.Empty());
        }
Exemplo n.º 12
0
    public static void Main(string[] args)
    {
        Stack2 s = new Stack2(10);

        for (int i = 1; i <= 100; i++)
        {
            s.Push(i);
        }
        for (int i = 1; i <= 100; i++)
        {
            s.Pop();
        }
        s.print();
    }
Exemplo n.º 13
0
 /// <summary>
 /// Add a new item to the "rear" of the queue, which is actually the bottom of the primary stack
 /// </summary>
 /// <param name="val">Value to be enqueued</param>
 public void Enqueue(string val)
 {
     if (Stack1.Top == null)
     {
         Stack1.Push(val);
         Front = Stack1.Top;
     }
     else
     {
         while (Stack1.Top != null)
         {
             Stack2.Push(Stack1.Pop());
         }
         Stack1.Push(val);
         while (Stack2.Top != null)
         {
             Stack1.Push(Stack2.Pop());
         }
         Front = Stack1.Top;
     }
 }
        public void Push_ArgIsNull_ThrowArgNullException()
        {
            var stack = new Stack2 <string>();

            Assert.That(() => stack.Push(null), Throws.Exception.TypeOf <ArgumentNullException>());
        }