From 5de7d2b9cee5640a14364a65df49644cdf60324c Mon Sep 17 00:00:00 2001 From: JoelCourtney Date: Wed, 28 Jun 2023 13:52:44 -0700 Subject: [PATCH] Update tests for bounds shifting behavior --- .../jpl/aerie/constraints/tree/ASTTests.java | 73 ++++++++++++++++++- 1 file changed, 71 insertions(+), 2 deletions(-) diff --git a/constraints/src/test/java/gov/nasa/jpl/aerie/constraints/tree/ASTTests.java b/constraints/src/test/java/gov/nasa/jpl/aerie/constraints/tree/ASTTests.java index dece8bca8c..b5dc5e5bdd 100644 --- a/constraints/src/test/java/gov/nasa/jpl/aerie/constraints/tree/ASTTests.java +++ b/constraints/src/test/java/gov/nasa/jpl/aerie/constraints/tree/ASTTests.java @@ -359,7 +359,7 @@ public void testOr() { @Test public void testExpandBy() { final var simResults = new SimulationResults( - Instant.EPOCH, Interval.between(0, 20, SECONDS), + Instant.EPOCH, Interval.between(-100, 200, SECONDS), List.of(), Map.of(), Map.of() @@ -391,7 +391,7 @@ public void testExpandBy() { @Test public void testShrink() { final var simResults = new SimulationResults( - Instant.EPOCH, Interval.between(0, 20, SECONDS), + Instant.EPOCH, Interval.between(-100, 200, SECONDS), List.of(), Map.of(), Map.of() @@ -1054,6 +1054,75 @@ public void testSpansFromInterval() { assertEquals(expected, result); } + @Test + public void testShiftByBoundsAdjustment() { + final var simResults = new SimulationResults( + Instant.EPOCH, Interval.between(0, 20, SECONDS), + List.of(), + Map.of(), + Map.of() + ); + + final var expression = new ShiftBy<>( + new DiscreteValue(SerializedValue.of("strang")), + Supplier.of(Duration.of(10, SECONDS)) + ); + + final var result = expression.evaluate(simResults); + + final var expected = new DiscreteProfile( + Segment.of(Interval.between(0, 20, SECONDS), SerializedValue.of("strang")) + ); + + assertIterableEquals(expected, result); + } + + @Test + public void testShiftWindowsEdgesBoundsAdjustment() { + final var simResults = new SimulationResults( + Instant.EPOCH, Interval.between(0, 20, SECONDS), + List.of(), + Map.of(), + Map.of() + ); + + final var crossingStartOfPlan = new Windows(false).set(Interval.between(-1, 1, SECONDS), true); + + final var result1 = new ShiftWindowsEdges( + Supplier.of(crossingStartOfPlan), + Supplier.of(Duration.ZERO), + Supplier.of(Duration.of(10, SECONDS)) + ).evaluate(simResults); + final var expected1 = new Windows(false).set(Interval.between(-1, 11, SECONDS), true).select(simResults.bounds); + assertIterableEquals(expected1, result1); + + final var result2 = new ShiftWindowsEdges( + Supplier.of(crossingStartOfPlan), + Supplier.of(Duration.of(-10, SECONDS)), + Supplier.of(Duration.ZERO) + ).evaluate(simResults); + final var expected2 = new Windows(false).set(Interval.between(0, 1, SECONDS), true).select(simResults.bounds); + assertIterableEquals(expected2, result2); + + final var crossingEndOfPlan = new Windows(false).set(Interval.between(19, 21, SECONDS), true); + + final var result3 = new ShiftWindowsEdges( + Supplier.of(crossingEndOfPlan), + Supplier.of(Duration.ZERO), + Supplier.of(Duration.of(10, SECONDS)) + ).evaluate(simResults); + final var expected3 = new Windows(false).set(Interval.between(19, 20, SECONDS), true).select(simResults.bounds); + assertIterableEquals(expected3, result3); + + final var result4 = new ShiftWindowsEdges( + Supplier.of(crossingEndOfPlan), + Supplier.of(Duration.of(-10, SECONDS)), + Supplier.of(Duration.ZERO) + ).evaluate(simResults); + final var expected4 = new Windows(false).set(Interval.between(9, 21, SECONDS), true).select(simResults.bounds); + assertIterableEquals(expected2, result2); + } + private static final class Supplier implements Expression { private final T value;