Esempio n. 1
0
        public void LongRange_LengthNotDivisibleByStep_IterationCountMatchesCalculated()
        {
            long length = RandomLong(1, long.MaxValue);
            long start  = RandomLong(long.MinValue, long.MaxValue - length);
            long end    = start + length;
            // note that the number of steps is limited to 1000 or fewer
            long step = length / RandomLong(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 += RandomLong(1, step - 1);
                length = end - start;
            }

            LongRange longRange = new LongRange(start, end, step);

            Assert.AreEqual(length / step + 1, longRange.Count(), "Iteration count should be (start-end)/step +1");
        }
Esempio n. 2
0
        public void LongRange_LengthDivisibleByStep_IterationCountMatchesCalculated()
        {
            long length = RandomLong(1, long.MaxValue);
            long start  = RandomLong(long.MinValue, long.MaxValue - length);
            long end    = start + length;
            // note that the number of steps is limited to 1000 or fewer
            long step = length / RandomLong(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;

            LongRange longRange = new LongRange(start, end, step);

            // Range endpoint is inclusive, so must take into account this extra iteration
            Assert.AreEqual(
                length / step + 1,
                longRange.Count(),
                "Iteration count should be (end-start)/step + 1 where endpoint is included");
        }