示例#1
0
        public void DoubleRange_LengthNotDivisibleByStep_IterationCountMatchesCalculated()
        {
            Random rand = new Random();

            Tuple <double, double> rangeParams = RestrictedRandomRange();
            double start  = rangeParams.Item1;
            double length = rangeParams.Item2;
            double end    = start + length;
            // note that the number of steps is limited to 1000 or fewer
            double step = length / (rand.Next(4, 1000) + (rand.NextDouble() * 0.8 + 0.1));

            //ensure that step size is not a factor of the length of the range
            if (length % step == 0)
            {
                double offset = (rand.NextDouble() * 0.8 + 0.1) * step;
                start  += offset;
                length += offset;
            }

            DoubleRange doubleRange = new DoubleRange(start, end, step);

            Assert.AreEqual(
                Math.Ceiling(length / step),
                doubleRange.Count(),
                "Iteration count should be Ceil((start-end)/step)");
        }
示例#2
0
        public void DoubleRange_StepGreaterThanLength_IterationCountMatchesCalculated()
        {
            Random rand = new Random();

            Tuple <double, double> rangeParams = RestrictedRandomRange();
            double start  = rangeParams.Item1;
            double length = rangeParams.Item2;
            double end    = start + length;
            double step   = length * (2 - rand.NextDouble());

            DoubleRange doubleRange = new DoubleRange(start, end, step);

            Assert.AreEqual(
                1,
                doubleRange.Count(),
                "Iteration count should be one if the step is larger than the range");
        }
        public void DoubleRange_StepGreaterThanLength_IterationCountMatchesCalculated()
        {
            Random rand = new Random();

            Tuple<double, double> rangeParams = RestrictedRandomRange();
            double start = rangeParams.Item1;
            double length = rangeParams.Item2;
            double end = start + length;
            double step = length * (2 - rand.NextDouble());

            DoubleRange doubleRange = new DoubleRange(start, end, step);

            Assert.AreEqual(
                1,
                doubleRange.Count(),
                "Iteration count should be one if the step is larger than the range");
        }
        public void DoubleRange_LengthNotDivisibleByStep_IterationCountMatchesCalculated()
        {
            Random rand = new Random();

            Tuple<double, double> rangeParams = RestrictedRandomRange();
            double start = rangeParams.Item1;
            double length = rangeParams.Item2;
            double end = start + length;
            // note that the number of steps is limited to 1000 or fewer
            double step = length / (rand.Next(4, 1000) + (rand.NextDouble() * 0.8 + 0.1));

            //ensure that step size is not a factor of the length of the range
            if (length % step == 0)
            {
                double offset = (rand.NextDouble() * 0.8 + 0.1) * step;
                start += offset;
                length += offset;
            }

            DoubleRange doubleRange = new DoubleRange(start, end, step);

            Assert.AreEqual(
                Math.Ceiling(length / step),
                doubleRange.Count(),
                "Iteration count should be Ceil((start-end)/step)");
        }