public void NotContainTest()
 {
     MyStack<int> Stack = new MyArrayStack<int>();
     Stack.Push(31);
     Stack.Push(9);
     Assert.AreEqual(Stack.Contains(63), false);
 }
Example #2
0
    static void Main()
    {
        MyArrayStack<int> myStack = new MyArrayStack<int>();

        for (int i = 1; i <= 10; i++)
        {
            myStack.Push(i);
        }

        Console.WriteLine("{0}", string.Join("-", myStack.ToArray()));

        foreach (var item in myStack)
        {
            Console.Write("{0}-", item);
        }

        Console.WriteLine();

        while (myStack.Count > 0)
        {
            Console.WriteLine(myStack.Pop());
        }

        Console.Read();
    }
 public void PushedStack_ShouldIncrementCountWithOne()
 {
     MyArrayStack<int> myStack = new MyArrayStack<int>();
     Assert.AreEqual(0, myStack.Count);
     myStack.Push(1);
     Assert.AreEqual(1, myStack.Count);
 }
 public void ContainTest()
 {
     MyStack<int> Stack = new MyArrayStack<int>();
     Stack.Push(31);
     Stack.Push(9);
     Assert.AreEqual(Stack.Contains(31), true);
 }
 public void CustomCapacityInitTest()
 {
     int actualCapacity = 24;
     MyStack<int> Stack = new MyArrayStack<int>(actualCapacity);
     Assert.AreEqual(Stack.Count, 0);
     Assert.AreEqual((Stack as MyArrayStack<int>).Capacity, actualCapacity);
 }
 public void CopyConstructorTest()
 {
     MyStack<int> Stack = new MyArrayStack<int>();
     Stack.Push(1);
     Stack.Push(2);
     MyStack<int> Stack2 = new MyArrayStack<int>(Stack);
     Assert.AreEqual(Stack2, Stack);
 }
 public void ClearTest()
 {
     MyStack<int> Stack = new MyArrayStack<int>();
     Stack.Push(1);
     Stack.Push(2);
     Stack.Clear();
     Assert.AreEqual(Stack.Count, 0);
     Assert.AreEqual((Stack as MyArrayStack<int>).Capacity, 10);
 }
 public void CopyToArray()
 {
     int[] array = new int[2];
     MyStack<int> Stack = new MyArrayStack<int>();
     Stack.Push(51);
     Stack.Push(94);
     Stack.CopyTo(array, 0);
     Assert.AreEqual(array[0], 51);
     Assert.AreEqual(array[1], 94);
 }
    public void PushOneThousandElements_CountShouldBeOneThousand()
    {
        MyArrayStack<int> myStack = new MyArrayStack<int>();

        for (int i = 0; i < 1000; i++)
        {
            myStack.Push(i);
        }

        Assert.AreEqual(1000, myStack.Count);
    }
 public void CustomCapacityLessThanZeroInitTest()
 {
     int actualCapacity = -83;
     try
     {
         MyStack<int> Stack = new MyArrayStack<int>(actualCapacity);
     }
     catch (ArgumentOutOfRangeException e)
     {
         StringAssert.Contains(e.Message, "Вместимость стека должна быть натуральным числом.");
     }
 }
    public void TestToArrayMethod_ReturnedArrayShouldBeInReversedOrder()
    {
        MyArrayStack<int> myStack = new MyArrayStack<int>();

        myStack.Push(3);
        myStack.Push(5);
        myStack.Push(-2);
        myStack.Push(7);

        var arr = myStack.ToArray();

        Assert.AreEqual(7, arr[0]);
        Assert.AreEqual(-2, arr[1]);
        Assert.AreEqual(5, arr[2]);
        Assert.AreEqual(3, arr[3]);
    }
    public void PopOneThousandTimesFromMyStackWithOneThousendElements_CountShoulBeZero()
    {
        MyArrayStack<int> myStack = new MyArrayStack<int>();

        for (int i = 0; i < 1000; i++)
        {
            myStack.Push(i);
        }

        for (int i = 0; i < 1000; i++)
        {
            myStack.Pop();
        }

        Assert.AreEqual(0, myStack.Count);
    }
    public void PopAndPushTwoTimesInitCapcityOne_ResizeAndCountShouldBehaveCorectly()
    {
        MyArrayStack<string> myStack = new MyArrayStack<string>(1);

        Assert.AreEqual(0, myStack.Count);

        myStack.Push("One");
        Assert.AreEqual(1, myStack.Count);

        myStack.Push("Two");
        Assert.AreEqual(2, myStack.Count);

        var poppedElement = myStack.Pop();
        Assert.AreEqual("Two", poppedElement);
        Assert.AreEqual(1, myStack.Count);

        poppedElement = myStack.Pop();
        Assert.AreEqual("One", poppedElement);
        Assert.AreEqual(0, myStack.Count);
    }
 public void PushPopTest()
 {
     MyStack<int> Stack = new MyArrayStack<int>();
     Stack.Push(85);
     Stack.Push(48);
     Assert.AreEqual(Stack.Pop(), 48);
 }
    public void EmptyMyStack_ShouldReturnEmptyArray()
    {
        MyArrayStack<DateTime> myStack = new MyArrayStack<DateTime>();

        var arr = myStack.ToArray();

        Assert.AreEqual(0, arr.Length);       
    }
 public void DefaultInitTest()
 {
     MyStack<int> Stack = new MyArrayStack<int>();
     Assert.AreEqual(Stack.Count, 0);
     Assert.AreEqual((Stack as MyArrayStack<int>).Capacity, 10);
 }
    public void PopElementFromEmptyMyStack_ShouldThrow()
    {
        MyArrayStack<int> myStack = new MyArrayStack<int>();

        myStack.Pop();
    }
 public void PeekTest()
 {
     MyStack<int> Stack = new MyArrayStack<int>();
     Stack.Push(98);
     Stack.Push(20);
     Assert.AreEqual(Stack.Peek(), 20);
 }
        public void PeekFromEmptyTest()
        {
            MyStack<int> Stack = new MyArrayStack<int>();
            try
            {
                Stack.Peek();
            }
            catch (InvalidOperationException e)
            {
                StringAssert.Contains(e.Message, "Стек пуст.");
            }

        }
 public void InvalidCopyToArray()
 {
     int[] array = new int[2];
     MyStack<int> Stack = new MyArrayStack<int>();
     Stack.Push(51);
     Stack.Push(94);
     try
     {
         Stack.CopyTo(array, 2);
     }
     catch (IndexOutOfRangeException e)
     {
         StringAssert.Contains(e.Message, "Индекс вне диапазона.");
     }
 }
 public void PushMoreThanCapacityTest()
 {
     int actualCapacity = 1;
     MyStack<int> Stack = new MyArrayStack<int>(actualCapacity);
     Stack.Push(70);
     Stack.Push(52);
     Assert.AreEqual(Stack.Count, 2);
     Assert.AreEqual((Stack as MyArrayStack<int>).Capacity, actualCapacity + 10);
 }