Esempio n. 1
0
        public static void LastIndexOf()
        {
            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, 4096);

            Assert.AreEqual(distributedArray.LastIndexOf(5000), 13192);
            Assert.AreEqual(distributedArray.LastIndexOf(5000, 4999, 5000), -1);
            Assert.AreEqual(distributedArray.LastIndexOf(128000), -1);
            Assert.AreEqual(distributedArray.LastIndexOf(5000, 5001, 1000), 5000);

            var emptyArray = new BigArray <int>();

            Assert.AreEqual(emptyArray.LastIndexOf(0), -1);

            //Exceptions
            Assert.IsTrue(ExceptionManager.IsThrowFuncException
                          <ArgumentOutOfRangeException, int, int, int>
                              (distributedArray.LastIndexOf, 0, distributedArray.Count));
            Assert.IsTrue(ExceptionManager.IsThrowFuncException
                          <ArgumentOutOfRangeException, int, int, int>
                              (distributedArray.LastIndexOf, 0, -1));

            Assert.IsTrue(ExceptionManager.IsThrowFuncException
                          <ArgumentOutOfRangeException, int, int, int, int>
                              (distributedArray.LastIndexOf, 0, 0, 2));
            Assert.IsTrue(ExceptionManager.IsThrowFuncException
                          <ArgumentOutOfRangeException, int, int, int, int>
                              (distributedArray.LastIndexOf, 0, distributedArray.Count, 1));
            Assert.IsTrue(ExceptionManager.IsThrowFuncException
                          <ArgumentOutOfRangeException, int, int, int, int>
                              (distributedArray.LastIndexOf, 0, 2, -1));
        }