public void GetEnumerator_LengthNotDivisibleByStep_CountMatchesCalculated() { TimeSpan length = RandomDuration(1, MaxDays); DateTime start = RandomDate(DateTime.MinValue, DateTime.MaxValue - length); DateTime end = start + length; // note that the number of steps is limited to 1000 or fewer int step = length.Days / Random.Next(4, Math.Max(4, Math.Min(length.Days / 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.Days % step == 0) { start += RandomDuration(1, step - 1); length = end - start; } DateRange dateRange = new DateRange(start, end, step); Assert.AreEqual(length.Days / step + 1, dateRange.Count(), "Iteration count should be (start-end)/step +1"); }
public void GetEnumerator_LengthDivisibleByStep_CountMatchesCalculated() { TimeSpan length = RandomDuration(1, MaxDays); DateTime start = RandomDate(DateTime.MinValue, DateTime.MaxValue - length); DateTime end = start + length; // note that the number of steps is limited to 1000 or fewer int step = length.Days / Random.Next(4, Math.Max(4, Math.Min(length.Days / 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 += TimeSpan.FromDays(length.Days % step); DateRange dateRange = new DateRange(start, end, step); // Range endpoint is inclusive, so must take longo account this extra iteration Assert.AreEqual( length.Days / step + 1, dateRange.Count(), "Iteration count should be (end-start)/step + 1 where endpoint is included"); }
public void date_range_iteration_includes_zero_interval() { var startDate = DateTime.SpecifyKind(new DateTime(2010, 02, 09), DateTimeKind.Utc); var endDate = DateTime.SpecifyKind(new DateTime(2010, 02, 09), DateTimeKind.Utc); var ob = new DateRange(startDate, endDate); var expected = (endDate - startDate).Days; // we exclude the last day var actual = ob.Count(); Assert.That(actual, Is.EqualTo(expected)); }
public void date_range_is_iterable() { var startDate = DateTime.SpecifyKind(new DateTime(2010, 02, 09), DateTimeKind.Utc); var endDate = DateTime.SpecifyKind(new DateTime(2010, 02, 10), DateTimeKind.Utc); var ob = new DateRange(startDate, endDate); var expected = (endDate - startDate).Days; var actual = ob.Count(); Assert.That(actual, Is.EqualTo(expected)); }
public void GetEnumerator_LengthNotDivisibleByStep_CountMatchesCalculated() { TimeSpan length = RandomDuration(1, MaxDays); DateTime start = RandomDate(DateTime.MinValue, DateTime.MaxValue - length); DateTime end = start + length; // note that the number of steps is limited to 1000 or fewer int step = length.Days / Random.Next(4, Math.Max(4, Math.Min(length.Days / 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.Days % step == 0) { start += RandomDuration(1, step - 1); length = end - start; } DateRange dateRange = new DateRange(start, end, step); Assert.AreEqual(length.Days / step + 1, dateRange.Count(), "Iteration count should be (start-end)/step +1"); }
public void GetEnumerator_LengthDivisibleByStep_CountMatchesCalculated() { TimeSpan length = RandomDuration(1, MaxDays); DateTime start = RandomDate(DateTime.MinValue, DateTime.MaxValue - length); DateTime end = start + length; // note that the number of steps is limited to 1000 or fewer int step = length.Days / Random.Next(4, Math.Max(4, Math.Min(length.Days / 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 += TimeSpan.FromDays(length.Days % step); DateRange dateRange = new DateRange(start, end, step); // Range endpoint is inclusive, so must take longo account this extra iteration Assert.AreEqual( length.Days / step + 1, dateRange.Count(), "Iteration count should be (end-start)/step + 1 where endpoint is included"); }