Esempio n. 1
0
        public void IntRange_LengthNotDivisibleByStep_IterationCountMatchesCalculated()
        {
            int length = Random.Next(1, int.MaxValue);
            int start  = Random.Next(int.MinValue, int.MaxValue - length);
            int end    = start + length;
            // note that the number of steps is limited to 1000 or fewer
            int step = length / Random.Next(4, Math.Max(4, Math.Min(length / 2, 1000)));

            // In case range length is under 4, ensure the step is at least 2
            if (step < 2)
            {
                step = 2;
            }

            //ensure that step size is not a factor of the length of the range
            if (length % step == 0)
            {
                start += Random.Next(1, step - 1);
                length = end - start;
            }

            IntRange intRange = new IntRange(start, end, step);

            Assert.AreEqual(length / step + 1, intRange.Count(), "Iteration count should be (start-end)/step +1");
        }
Esempio n. 2
0
        public void IntRange_LengthDivisibleByStep_IterationCountMatchesCalculated()
        {
            int length = Random.Next(1, int.MaxValue);
            int start  = Random.Next(int.MinValue, int.MaxValue - length);
            int end    = start + length;
            // note that the number of steps is limited to 1000 or fewer
            int step = length / Random.Next(4, Math.Max(4, Math.Min(length / 2, 1000)));

            // In case range length is under 4, ensure the step is at least 1
            if (step < 1)
            {
                step = 1;
            }

            //ensure that step size is a factor of the length of the range
            start += length % step;

            IntRange intRange = new IntRange(start, end, step);

            // Range endpoint is inclusive, so must take into account this extra iteration
            Assert.AreEqual(
                length / step + 1,
                intRange.Count(),
                "Iteration count should be (end-start)/step + 1 where endpoint is included");
        }
Esempio n. 3
0
        public void IntRange_LengthDivisibleByStep_IterationCountMatchesCalculated()
        {
            int length = Random.Next(1, int.MaxValue);
            int start = Random.Next(int.MinValue, int.MaxValue - length);
            int end = start + length;
            // note that the number of steps is limited to 1000 or fewer
            int step = length / Random.Next(4, Math.Max(4, Math.Min(length / 2, 1000)));

            // In case range length is under 4, ensure the step is at least 1
            if (step < 1) step = 1;

            //ensure that step size is a factor of the length of the range
            start += length % step;

            IntRange intRange = new IntRange(start, end, step);

            // Range endpoint is inclusive, so must take into account this extra iteration
            Assert.AreEqual(
                length / step + 1,
                intRange.Count(),
                "Iteration count should be (end-start)/step + 1 where endpoint is included");
        }
Esempio n. 4
0
        public void IntRange_LengthNotDivisibleByStep_IterationCountMatchesCalculated()
        {
            int length = Random.Next(1, int.MaxValue);
            int start = Random.Next(int.MinValue, int.MaxValue - length);
            int end = start + length;
            // note that the number of steps is limited to 1000 or fewer
            int step = length / Random.Next(4, Math.Max(4, Math.Min(length / 2, 1000)));

            // In case range length is under 4, ensure the step is at least 2
            if (step < 2) step = 2;

            //ensure that step size is not a factor of the length of the range
            if (length % step == 0)
            {
                start += Random.Next(1, step - 1);
                length = end - start;
            }

            IntRange intRange = new IntRange(start, end, step);

            Assert.AreEqual(length / step + 1, intRange.Count(), "Iteration count should be (start-end)/step +1");
        }
Esempio n. 5
0
        public IList <long> Generate(IntRange range)
        {
            var result = GetEnumerator().Skip(range.Start - 1).Take(range.Count() + 1).ToList();

            return(result);
        }