Ejemplo n.º 1
0
        public static void FindLastIndex()
        {
            var distributedArray = new BigArray <int>();

            for (int i = 0; i < MaxBlockSize * 2; i++)
            {
                distributedArray.Add(i);
            }
            for (int i = 0; i < MaxBlockSize * 2; i++) //For mistakes with duplicate elements
            {
                distributedArray.Add(i);
            }

            //If MaxBlockSize is change, we need to change this code
            Assert.AreEqual(MaxBlockSize, MaxBlockSize);

            Assert.AreEqual(distributedArray.FindLastIndex(IsEqual5000), 13192);
            Assert.AreEqual(distributedArray.FindLastIndex(4999, 5000, IsEqual5000), -1);
            Assert.AreEqual(distributedArray.FindLastIndex(IsEqual128000), -1);
            Assert.AreEqual(distributedArray.FindLastIndex(5001, 1000, IsEqual5000), 5000);

            var emptyArray = new BigArray <int>();

            Assert.AreEqual(emptyArray.FindLastIndex(IsEqual0), -1);

            //Exceptions
            Assert.IsTrue(ExceptionManager.IsThrowFuncException
                          <ArgumentNullException, Predicate <int>, int>
                              (distributedArray.FindLastIndex, null));

            Assert.IsTrue(ExceptionManager.IsThrowFuncException
                          <ArgumentOutOfRangeException, int, Predicate <int>, int>
                              (distributedArray.FindLastIndex, distributedArray.Count, IsEqual0));
            Assert.IsTrue(ExceptionManager.IsThrowFuncException
                          <ArgumentOutOfRangeException, int, Predicate <int>, int>
                              (distributedArray.FindLastIndex, -1, IsEqual0));

            Assert.IsTrue(ExceptionManager.IsThrowFuncException
                          <ArgumentOutOfRangeException, int, int, Predicate <int>, int>
                              (distributedArray.FindLastIndex, distributedArray.Count - 1
                              , distributedArray.Count + 1, IsEqual0));
            Assert.IsTrue(ExceptionManager.IsThrowFuncException
                          <ArgumentOutOfRangeException, int, int, Predicate <int>, int>
                              (distributedArray.FindLastIndex, distributedArray.Count + 1
                              , 1, IsEqual0));
            Assert.IsTrue(ExceptionManager.IsThrowFuncException
                          <ArgumentOutOfRangeException, int, int, Predicate <int>, int>
                              (distributedArray.FindLastIndex, 1, -1, IsEqual0));
        }