public void GetEnumerator_LengthDivisibleByStep_IterationCountMatchesCalculated() { Duration length = RandomDuration(MinDuration, MaxDuration); Instant start = RandomInstant(TestMinInstant, TestMaxInstant - length); Instant 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); InstantRange instantRange = new InstantRange(start, end, step); // Range endpoint is inclusive, so must take longo account this extra iteration Assert.AreEqual( length.Ticks / step.Ticks + 1, instantRange.Count(), "Iteration count should be (end-start)/step + 1 where endpoint is included"); }
public void GetEnumerator_LengthNotDivisibleByStep_IterationCountMatchesCalculated() { Duration length = RandomDuration(MinDuration, MaxDuration); Instant start = RandomInstant(TestMinInstant, TestMaxInstant - length); Instant 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 - start; } InstantRange instantRange = new InstantRange(start, end, step); Assert.AreEqual( length.Ticks / step.Ticks + 1, instantRange.Count(), "Iteration count should be (start-end)/step +1"); }