Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Interval.Horizon #1154

Merged
merged 1 commit into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading