Skip to content

Commit

Permalink
Make Interval.Horizon do its job
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelCourtney committed Oct 4, 2023
1 parent a491c5a commit cd6a244
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ public record AbsoluteInterval(
public Interval evaluate(final SimulationResults results, final Interval bounds, final EvaluationEnvironment environment) {
final Duration relativeStart = start
.map(instant -> Duration.of(results.planStart.until(instant, ChronoUnit.MICROS), Duration.MICROSECOND))
.orElse(Duration.MIN_VALUE);
.orElse(results.bounds.start);
final Duration relativeEnd = end
.map(instant -> Duration.of(results.planStart.until(instant, ChronoUnit.MICROS), Duration.MICROSECOND))
.orElse(Duration.MAX_VALUE);
.orElse(results.bounds.end);
return Interval.between(
relativeStart,
startInclusivity.orElse(Interval.Inclusivity.Inclusive),
startInclusivity.orElse(start.isPresent() ? Interval.Inclusivity.Inclusive : results.bounds.startInclusivity),
relativeEnd,
endInclusivity.orElse(Interval.Inclusivity.Inclusive)
endInclusivity.orElse(end.isPresent() ? Interval.Inclusivity.Inclusive : results.bounds.endInclusivity)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,24 @@ public void testSpansFromInterval() {
assertEquals(expected, result);
}

@Test
public void testHorizonInterval() {
final var simResults = new SimulationResults(
Instant.EPOCH, Interval.between(0, Inclusive, 20, Exclusive, SECONDS),
List.of(),
Map.of(),
Map.of()
);

final var interval = new AbsoluteInterval(Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty());

final var result = interval.evaluate(simResults);

final var expected = Interval.between(0, Inclusive, 20, Exclusive, SECONDS);

assertEquals(expected, result);
}

@Test
public void testShiftByBoundsAdjustment() {
final var simResults = new SimulationResults(
Expand Down

0 comments on commit cd6a244

Please sign in to comment.