Exemple #1
0
        [TestMethod] // ReSharper disable once InconsistentNaming
        public void GetEnumerator_LengthDivisibleByStep_IterationCountMatchesCalculated()
        {
            Duration      length = RandomDuration(MinDuration, MaxDuration);
            ZonedDateTime start  = RandomZonedDateTime(TestMinZonedDateTime, TestMaxZonedDateTime - length);
            ZonedDateTime end    = start + length;
            // note that the number of steps is limited to 1000 or fewer
            Duration step = Duration.FromTicks(length.Ticks / Random.Next(4, 1000));

            //ensure that step size is a factor of the length of the range
            start += Duration.FromTicks(length.Ticks % step.Ticks);

            ZonedDateTimeRange zonedDateTimeRange = new ZonedDateTimeRange(start, end, step);

            // Range endpoint is inclusive, so must take longo account this extra iteration
            Assert.AreEqual(
                length.Ticks / step.Ticks + 1,
                zonedDateTimeRange.Count(),
                "Iteration count should be (end-start)/step + 1 where endpoint is included");
        }
Exemple #2
0
        [TestMethod] // ReSharper disable once InconsistentNaming
        public void GetEnumerator_LengthNotDivisibleByStep_IterationCountMatchesCalculated()
        {
            Duration      length = RandomDuration(MinDuration, MaxDuration);
            ZonedDateTime start  = RandomZonedDateTime(TestMinZonedDateTime, TestMaxZonedDateTime - length);
            ZonedDateTime end    = start + length;
            // note that the number of steps is limited to 1000 or fewer
            Duration step = Duration.FromTicks(length.Ticks / Random.Next(4, 1000));

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

            ZonedDateTimeRange zonedDateTimeRange = new ZonedDateTimeRange(start, end, step);

            Assert.AreEqual(
                length.Ticks / step.Ticks + 1,
                zonedDateTimeRange.Count(),
                "Iteration count should be (start-end)/step +1");
        }
        [TestMethod] // ReSharper disable once InconsistentNaming
        public void GetEnumerator_LengthNotDivisibleByStep_IterationCountMatchesCalculated()
        {
            Duration length = RandomDuration(MinDuration, MaxDuration);
            ZonedDateTime start = RandomZonedDateTime(TestMinZonedDateTime, TestMaxZonedDateTime - length);
            ZonedDateTime end = start + length;
            // note that the number of steps is limited to 1000 or fewer
            Duration step = Duration.FromTicks(length.Ticks / Random.Next(4, 1000));

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

            ZonedDateTimeRange zonedDateTimeRange = new ZonedDateTimeRange(start, end, step);

            Assert.AreEqual(
                length.Ticks / step.Ticks + 1,
                zonedDateTimeRange.Count(),
                "Iteration count should be (start-end)/step +1");
        }
        [TestMethod] // ReSharper disable once InconsistentNaming
        public void GetEnumerator_LengthDivisibleByStep_IterationCountMatchesCalculated()
        {
            Duration length = RandomDuration(MinDuration, MaxDuration);
            ZonedDateTime start = RandomZonedDateTime(TestMinZonedDateTime, TestMaxZonedDateTime - length);
            ZonedDateTime end = start + length;
            // note that the number of steps is limited to 1000 or fewer
            Duration step = Duration.FromTicks(length.Ticks / Random.Next(4, 1000));

            //ensure that step size is a factor of the length of the range
            start += Duration.FromTicks(length.Ticks % step.Ticks);

            ZonedDateTimeRange zonedDateTimeRange = new ZonedDateTimeRange(start, end, step);

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