Esempio n. 1
0
        public void ShouldIncreseCapacityOnInsertWhenMaxCapacityIsReached()
        {
            var array = new ResizeableArray <int>();

            Assert.AreEqual(16, array.Capacity);

            for (int i = 0; i < 15; i++)
            {
                array.Add(i);
            }

            Assert.AreEqual(16, array.Capacity);
            array.Insert(200, 4);
            Assert.AreEqual(32, array.Capacity);

            for (int i = 0; i < 16; i++)
            {
                if (i < 4)
                {
                    Assert.AreEqual(i, array.ElementAt(i));
                }

                if (i == 4)
                {
                    Assert.AreEqual(200, array.ElementAt(i));
                }

                if (i > 4)
                {
                    Assert.AreEqual(i - 1, array.ElementAt(i));
                }
            }
        }
Esempio n. 2
0
        public void ShouldDecreaseCapacityOnRemove()
        {
            var array = new ResizeableArray <int>();

            Assert.AreEqual(16, array.Capacity);

            for (int i = 0; i < 16; i++)
            {
                array.Add(i);
            }

            Assert.AreEqual(32, array.Capacity);
            Assert.AreEqual(16, array.Length);

            for (int i = 0; i < 8; i++)
            {
                var elem = array.ElementAt(0);
                array.Remove(elem);
            }

            Assert.AreEqual(16, array.Capacity);
            Assert.AreEqual(8, array.Length);

            for (int i = 0; i < 6; i++)
            {
                var elem = array.ElementAt(0);
                array.Remove(elem);
            }

            Assert.AreEqual(2, array.Length);
            Assert.AreEqual(16, array.Capacity);
        }
Esempio n. 3
0
        public void ShouldThrowExceptionOnElementAtWhenIndexOutOfBounds()
        {
            var array = new ResizeableArray <int>();

            Assert.Throws <ValidationException>(() => array.ElementAt(10));
            Assert.Throws <ValidationException>(() => array.ElementAt(0));
            array.Add(10);
            array.Add(11);
            Assert.Throws <ValidationException>(() => array.ElementAt(2));
        }
Esempio n. 4
0
        public void ShouldReturnCorrectElementOnElementAtWhenArrayIsNotEmpty()
        {
            var array = new ResizeableArray <int>();

            array.Add(10);
            array.Add(0);

            Assert.AreEqual(10, array.ElementAt(0));
            Assert.AreEqual(0, array.ElementAt(1));
            Assert.AreEqual(2, array.Length);
        }
Esempio n. 5
0
        public void ShouldSetCorrectAtValueAtGivenIndexOnSet()
        {
            var array = new ResizeableArray <int>();

            array.Add(1);
            array.Add(2);
            array.Add(3);
            array.Set(1, 15);

            Assert.AreEqual(3, array.Length);
            Assert.AreEqual(1, array.ElementAt(0));
            Assert.AreEqual(15, array.ElementAt(1));
            Assert.AreEqual(3, array.ElementAt(2));
        }
Esempio n. 6
0
        public void ShouldRemoveElementAtCorrectIndexOnRemoveAt()
        {
            var array = new ResizeableArray <int>();

            array.Add(1);
            array.Add(2);
            array.Add(3);
            Assert.AreEqual(3, array.Length);

            array.RemoveAt(1);
            Assert.AreEqual(2, array.Length);
            Assert.AreEqual(1, array.ElementAt(0));
            Assert.AreEqual(3, array.ElementAt(1));
        }
Esempio n. 7
0
        public void ShouldAddElementAtStartOfArrayOnPreprend()
        {
            var array = new ResizeableArray <int>();

            array.Add(10);
            array.Add(15);
            array.Add(20);
            array.Prepend(25);

            Assert.AreEqual(25, array.ElementAt(0));
            Assert.AreEqual(10, array.ElementAt(1));
            Assert.AreEqual(15, array.ElementAt(2));
            Assert.AreEqual(20, array.ElementAt(3));
        }
Esempio n. 8
0
        public void ShouldRemoveLastElementOnPop()
        {
            var array = new ResizeableArray <int>();

            array.Add(1);
            array.Add(2);
            array.Add(3);
            Assert.AreEqual(3, array.Length);

            var element = array.Pop();

            Assert.AreEqual(3, element);
            Assert.AreEqual(2, array.Length);
            Assert.AreEqual(1, array.ElementAt(0));
            Assert.AreEqual(2, array.ElementAt(1));
        }
Esempio n. 9
0
        public void ShouldNotThrowExceptionOnPrependWhenArrayIsEmpty()
        {
            var array = new ResizeableArray <int>();

            array.Prepend(1);

            Assert.AreEqual(1, array.Length);
            Assert.AreEqual(1, array.ElementAt(0));
        }
Esempio n. 10
0
        public void ShouldNotThrowExceptionOnInsertWhenIndexIsZero()
        {
            var array = new ResizeableArray <int>();

            array.Insert(1, 0);

            Assert.AreEqual(1, array.Length);
            Assert.AreEqual(1, array.ElementAt(0));
        }
Esempio n. 11
0
        public void ShouldIncreseCapacityOnPrependWhenMaxCapacityIsReached()
        {
            var array = new ResizeableArray <int>();

            Assert.AreEqual(16, array.Capacity);

            for (int i = 0; i < 15; i++)
            {
                array.Add(i);
            }

            Assert.AreEqual(16, array.Capacity);
            array.Prepend(200);
            Assert.AreEqual(32, array.Capacity);

            Assert.AreEqual(200, array.ElementAt(0));
            for (int i = 1; i < 16; i++)
            {
                Assert.AreEqual(i - 1, array.ElementAt(i));
            }
        }
Esempio n. 12
0
        public void ShouldRemoveAllOccurencesOnRemove()
        {
            var array = new ResizeableArray <int>();

            array.Add(12);
            array.Add(1);
            array.Add(2);
            array.Add(13);
            array.Add(1);

            Assert.AreEqual(5, array.Length);
            Assert.AreEqual(12, array.ElementAt(0));
            Assert.AreEqual(1, array.ElementAt(1));
            Assert.AreEqual(2, array.ElementAt(2));
            Assert.AreEqual(13, array.ElementAt(3));
            Assert.AreEqual(1, array.ElementAt(4));

            array.Remove(1);

            Assert.AreEqual(3, array.Length);
            Assert.AreEqual(12, array.ElementAt(0));
            Assert.AreEqual(2, array.ElementAt(1));
            Assert.AreEqual(13, array.ElementAt(2));
        }
Esempio n. 13
0
        public void ShouldThrowExceptionOnElementAtWhenArrayIsEmpty()
        {
            var array = new ResizeableArray <int>();

            Assert.Throws <ValidationException>(() => array.ElementAt(10));
        }