public void Constructor_EndBeforeStart_ThrowsArgumentOutOfRangeException() { Duration length = RandomDuration(MinDuration, MaxDuration); Instant start = RandomInstant(TestMinInstant + length, TestMaxInstant); Instant end = start - length; InstantRange instantRange = new InstantRange(start, end); }
public void Step_StepIsLargerThanRange_MatchesThatGivenWithTimeStripped() { Instant start, end; Duration step; InstantRange InstantRange = GenerateinstantRangeWithStepLargerThanRange(out start, out end, out step); Assert.AreEqual(step, InstantRange.Step, "Step amount field must match the value supplied."); }
public void End_StepSmallerThanRange_MatchesThatGivenWithTimeStripped() { Instant start, end; Duration step; InstantRange InstantRange = GenerateInstantRangeWithStepSmallerThanRange(out start, out end, out step); Assert.AreEqual(end, InstantRange.End, "End point field must match the value supplied."); }
public void ToString_IsNotBlank() { Duration length = RandomDuration(MinDuration + MinDuration, MaxDuration); Instant start = RandomInstant(TestMinInstant, TestMaxInstant - length); Instant end = start + length; Duration step = RandomDuration(MinDuration, length - MinDuration); InstantRange instantRange = new InstantRange(start, end, step); Assert.AreNotEqual("", instantRange.ToString(), "String representation of range must not be an empty string"); }
public void ToString_HasCorrectFormat() { Duration length = RandomDuration(MinDuration + MinDuration, MaxDuration); Instant start = RandomInstant(TestMinInstant, TestMaxInstant - length); Instant end = start + length; Duration step = RandomDuration(MinDuration, length - MinDuration); InstantRange instantRange = new InstantRange(start, end, step); Assert.AreEqual($"{start} - {end}", instantRange.ToString()); }
public void Constructor_WithoutStepParam_DeltaLessThanHour_StepDefaultsToOneMinute() { Duration length = RandomDuration(Duration.FromMinutes(1), Duration.FromHours(1)); Trace.WriteLine(length); Instant start = RandomInstant(TestMinInstant, TestMaxInstant - length); Instant end = start + length; InstantRange instantRange = new InstantRange(start, end); Assert.AreEqual(start, instantRange.Start, "Starting point field must match the value supplied"); Assert.AreEqual(end, instantRange.End, "End point field must match the value supplied"); Assert.AreEqual(Duration.FromMinutes(1), instantRange.Step, "Step amount must default to one minute"); }
public void Constructor_WithoutStepParam_DeltaGreaterThanDay_StepDefaultsToOneDay() { Duration length = RandomDuration(Duration.FromStandardDays(1), MaxDuration); Trace.WriteLine(length); Instant start = RandomInstant(TestMinInstant, TestMaxInstant - length); Instant end = start + length; InstantRange instantRange = new InstantRange(start, end); Assert.AreEqual(start, instantRange.Start, "Starting point field must match the value supplied"); Assert.AreEqual(end, instantRange.End, "End point field must match the value supplied"); Assert.AreEqual(Duration.FromStandardDays(1), instantRange.Step, "Step amount must default to one day"); }
public void GetEnumerator_ValuesStayWithinRange() { Duration length = RandomDuration(MinDuration, MaxDuration); Instant start = RandomInstant(TestMinInstant, TestMaxInstant - length); Instant end = start + length; // note that the number of steps is limited to 100 or fewer Duration step = Duration.FromTicks(length.Ticks / Random.Next(4, 100)); InstantRange instantRange = new InstantRange(start, end, step); foreach (Instant d in instantRange) { Assert.IsTrue(d >= start, "Value from iterator must by equal or above start parameter"); Assert.IsTrue(d <= end, "Value from iterator must be equal or below end parameter"); } }
public void GetEnumerator_UsingLargestPossibleParameters_IteratesSuccessfully() { // Step chosen to avoid an unfeasible number of iterations InstantRange instantRange = new InstantRange( TestMinInstant, TestMaxInstant, Duration.FromTicks(MaxDuration.Ticks / 16)); bool iterated = false; foreach (Instant d in instantRange) { iterated = true; } Assert.AreEqual(true, iterated, "When iterating across full range, at least one value should be returned"); }
public void ToString_DoesDependOnTimeComponents() { Duration length = RandomDuration(MinDuration + MinDuration, MaxDuration); Instant start = RandomInstant(TestMinInstant, TestMaxInstant - length); Instant end = start + length; Duration step = RandomDuration(MinDuration, length - MinDuration); InstantRange instantRange = new InstantRange(start, end, step); InstantRange instantRangeWithTime = new InstantRange( start + RandomTimeOffset(), end + RandomTimeOffset(), step); Assert.AreNotEqual( instantRange.ToString(), instantRangeWithTime.ToString(), "String representation of range should depend on the time components"); }
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"); }
public void GetEnumerator_Iterating_DifferenceBetweenIterationsMatchesStepSize() { Duration length = RandomDuration(MinDuration, MaxDuration); Instant start = RandomInstant(TestMinInstant, TestMaxInstant - length); Instant end = start + length; // note that the number of steps is limited to 100 or fewer Duration step = Duration.FromTicks(length.Ticks / Random.Next(4, 100)); InstantRange instantRange = new InstantRange(start, end, step); Instant?previous = null; foreach (Instant d in instantRange) { if (previous.HasValue) { Assert.AreEqual( d - previous, step, "Difference between iteration values should match the step value supplied"); } previous = d; } }
public void GetEnumerator_Iterating_DifferenceBetweenIterationsMatchesStepSize() { Duration length = RandomDuration(MinDuration, MaxDuration); Instant start = RandomInstant(TestMinInstant, TestMaxInstant - length); Instant end = start + length; // note that the number of steps is limited to 100 or fewer Duration step = Duration.FromTicks(length.Ticks / Random.Next(4, 100)); InstantRange instantRange = new InstantRange(start, end, step); Instant? previous = null; foreach (Instant d in instantRange) { if (previous.HasValue) { Assert.AreEqual( d - previous, step, "Difference between iteration values should match the step value supplied"); } previous = d; } }
public void GetEnumerator_UsingLargestPossibleParameters_IteratesSuccessfully() { // Step chosen to avoid an unfeasible number of iterations InstantRange instantRange = new InstantRange( TestMinInstant, TestMaxInstant, Duration.FromTicks(MaxDuration.Ticks / 16)); bool iterated = false; foreach (Instant d in instantRange) iterated = true; Assert.AreEqual(true, iterated, "When iterating across full range, at least one value should be returned"); }