[TestMethod] // ReSharper disable once InconsistentNaming public void GetEnumerator_LengthNotDivisibleByStep_IterationCountMatchesCalculated() { Period length = RandomPeriod(MinPeriod, MaxPeriod, false); LocalTime start = RandomLocalTime(MinLocalTime, MaxLocalTime - length); LocalTime end = start + length; // note that the number of steps is limited to 1000 or fewer int steps = Random.Next(4, 1000); Period step = PeriodDivideApprox(length, steps); //ensure that step size is not a factor of the length of the range if (length.TicksFrom(start) % step.TicksFrom(start) == 0) { start += RandomPeriod(MinPeriod, step - MinPeriod, false); } LocalTimeRange localRange = new LocalTimeRange(start, end, step); long ticksA = start.TicksTo(end); long ticksB = step.TicksFrom(start); Assert.AreEqual( (ticksA / ticksB) + 1, localRange.Count(), "Iteration count should be (start-end)/step +1"); }
[TestMethod] // ReSharper disable once InconsistentNaming public void GetEnumerator_LengthDivisibleByStep_IterationCountMatchesCalculated() { Period length = RandomPeriod(MinPeriod, MaxPeriod, false); LocalTime start = RandomLocalTime(MinLocalTime, MaxLocalTime - length); LocalTime end = start + length; // note that the number of steps is limited to 1000 or fewer Period step = PeriodDivideApprox(length, Random.Next(4, 1000)); //ensure that step size is a factor of the length of the range start += Period.FromTicks(length.TicksFrom(start) % step.TicksFrom(start)); LocalTimeRange localRange = new LocalTimeRange(start, end, step); long ticksA = start.TicksTo(end); long ticksB = step.TicksFrom(start); // Range endpoint is inclusive, so must take longo account this extra iteration Assert.AreEqual( (ticksA / ticksB) + 1, localRange.Count(), "Iteration count should be (end-start)/step + 1 where endpoint is included"); }