﻿using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace List.Tests
{
    [TestClass]
    public class ArrayListTest
    {
        [TestInitialize]
        public void Initialize()
        {
            arrayList = new ArrayList();
        }

        [TestMethod]
        public void AddTest()
        {
            arrayList.AddElement(18);
            Assert.IsFalse(arrayList.IsEmpty());
        }

        [TestMethod]
        public void DeletionTest()
        {
            arrayList.AddElement(18);
            Assert.AreEqual(18, arrayList.DeleteElement());
            Assert.IsTrue(arrayList.IsEmpty());
        }

        [TestMethod]
        public void TwoElementsDeletionTest()
        {
            arrayList.AddElement(185);
            arrayList.AddElement(23);
            Assert.AreEqual(185, arrayList.DeleteElement());
            Assert.AreEqual(23, arrayList.DeleteElement());
            Assert.IsTrue(arrayList.IsEmpty());
        }

        [TestMethod]
        public void ValueDeletionTest()
        {
            arrayList.AddElement(100);
            arrayList.AddElement(23);
            arrayList.DeleteElement(23);
            Assert.AreEqual(1, arrayList.CountElements());
            Assert.AreEqual(100, arrayList.DeleteElement());
        }

        [TestMethod]
        public void SearchTest()
        {
            arrayList.AddElement(100);
            arrayList.AddElement(23);
            arrayList.AddElement(27);
            Assert.IsFalse(arrayList.SearchElement(105));
            Assert.IsTrue(arrayList.SearchElement(100));
            Assert.IsTrue(arrayList.SearchElement(23));
            Assert.IsTrue(arrayList.SearchElement(27));
        }

        [TestMethod]
        public void ValueTest()
        {
            arrayList.AddElement(100);
            arrayList.AddElement(23);
            arrayList.AddElement(27);
            arrayList.AddElement(29);
            arrayList.AddElement(65);
            Assert.AreEqual(27, arrayList.Value(3));
        }

        [TestMethod]
        public void AddToPositionTest()
        {
            arrayList.AddElement(100);
            arrayList.AddElement(23);
            arrayList.AddElement(27);
            arrayList.AddElement(29);
            arrayList.AddElement(65, 3);
            Assert.AreEqual(65, arrayList.Value(3));
        }

        [TestMethod]
        public void DeleteFromPositionTest()
        {
            arrayList.AddElement(100);
            arrayList.AddElement(23);
            arrayList.AddElement(27);
            arrayList.DeleteElementFromPosition(3);
        }

        [TestMethod]
        public void DeleteFromPositionTest1()
        {
            arrayList.AddElement(100);
            arrayList.AddElement(23);
            arrayList.AddElement(27);
            arrayList.DeleteElementFromPosition(2);
            Assert.AreEqual(100, arrayList.Value(1));
            Assert.AreEqual(27, arrayList.Value(2));
        }

        [TestMethod]
        public void DeleteFromPositionTest2()
        {
            arrayList.AddElement(100);
            arrayList.AddElement(23);
            arrayList.AddElement(27);
            arrayList.AddElement(29);
            arrayList.DeleteElementFromPosition(1);
            Assert.AreEqual(23, arrayList.Value(1));
        }

        [TestMethod()]
        [ExpectedException(typeof(ListIsEmptyException))]
        public void EmptyListTest()
        {
            arrayList.DeleteElement();
        }

        [TestMethod()]
        [ExpectedException(typeof(System.Exception))]
        public void AddToImpossiblePositionTest()
        {
            arrayList.AddElement(2, 2);
        }

        [TestMethod()]
        [ExpectedException(typeof(System.Exception))]
        public void DeleteFromImpossiblePositionTest()
        {
            arrayList.AddElement(25);
            arrayList.DeleteElementFromPosition(3);
        }

        private ArrayList arrayList;
    }
}
