Ejemplo n.º 1
0
        public static void AddRangeAndInsertRange()
        {
            var distributedArray = new BigArray <int>();
            var size             = MaxBlockSize * 2;

            var array1 = new int[size / 4];
            var array2 = new int[size / 4];
            var array3 = new int[size / 4];
            var array4 = new int[size / 4];

            //1
            for (int i = size / 4; i < size / 2; i++)
            {
                array1[i - size / 4] = i;
            }
            distributedArray.AddRange(array1);
            Assert.AreEqual(distributedArray.Count, size / 4);
            //2
            for (int i = 0; i < size / 4; i++)
            {
                array2[i] = i;
            }
            distributedArray.InsertRange(0, array2);
            Assert.AreEqual(distributedArray.Count, size / 2);
            //3
            for (int i = size / 2; i < size * 3 / 4; i++)
            {
                array3[i - size / 2] = i;
            }
            distributedArray.AddRange(array3);
            Assert.AreEqual(distributedArray.Count, size * 3 / 4);
            //4
            for (int i = size * 3 / 4; i < size; i++)
            {
                array4[i - size * 3 / 4] = i;
            }
            distributedArray.InsertRange(distributedArray.Count, array4);
            Assert.AreEqual(distributedArray.Count, size);

            //Check insertion in the empty array
            distributedArray.Clear();
            distributedArray.InsertRange(0, array1);

            //DA must be : 0,1,2,3...,n-1,n
            for (int i = 0; i < distributedArray.Count - 1; i++)
            {
                Assert.IsTrue(distributedArray[i] + 1 == distributedArray[i + 1]);
            }

            //Exceptions
            Assert.IsTrue(ExceptionManager.IsThrowActionException
                          <ArgumentNullException, int, ICollection <int> >
                              (distributedArray.InsertRange, 0, null));

            Assert.IsTrue(ExceptionManager.IsThrowActionException
                          <ArgumentOutOfRangeException, int, ICollection <int> >
                              (distributedArray.InsertRange, -1, new Collection <int>()));
            Assert.IsTrue(ExceptionManager.IsThrowActionException
                          <ArgumentOutOfRangeException, int, ICollection <int> >
                              (distributedArray.InsertRange, distributedArray.Count + 1, new Collection <int>()));
        }