From 2a35aa4dda93d7c6d49a6651f35531f3b2f4c740 Mon Sep 17 00:00:00 2001 From: JoelCourtney Date: Fri, 1 Sep 2023 15:40:25 -0700 Subject: [PATCH] Add ast test --- .../jpl/aerie/constraints/tree/ASTTests.java | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) 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 8a0fdc264c..37193bd08c 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 @@ -33,6 +33,7 @@ import static gov.nasa.jpl.aerie.constraints.time.Interval.at; import static gov.nasa.jpl.aerie.constraints.time.Interval.interval; import static gov.nasa.jpl.aerie.merlin.protocol.types.Duration.MICROSECONDS; +import static gov.nasa.jpl.aerie.merlin.protocol.types.Duration.MILLISECOND; import static gov.nasa.jpl.aerie.merlin.protocol.types.Duration.SECONDS; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertIterableEquals; @@ -1126,6 +1127,43 @@ public void testShiftWindowsEdgesBoundsAdjustment() { assertIterableEquals(expected2, result2); } + @Test + public void testRollingThreshold() { + final var simResults = new SimulationResults( + Instant.EPOCH, Interval.between(0, 20, SECONDS), + List.of(), + Map.of(), + Map.of() + ); + + final var spans = new Spans( + Interval.between(0, 1, SECONDS), + Interval.between(2, 3, SECONDS), + Interval.between(4, 5, SECONDS), + + Interval.between(14, 15, SECONDS), + Interval.between(16, 17, SECONDS), + Interval.between(18, 19, SECONDS) + ); + + final var result1 = new RollingThreshold( + Supplier.of(spans), + Supplier.of(Duration.of(10, SECONDS)), + Supplier.of(Duration.of(2500, MILLISECOND)), + RollingThreshold.RollingThresholdAlgorithm.Hull + ).evaluate(simResults); + + final var expected = new ConstraintResult( + List.of( + new Violation(List.of(Interval.between(0, 5, SECONDS)), List.of()), + new Violation(List.of(Interval.between(14, 19, SECONDS)), List.of()) + ), + List.of() + ); + + assertEquals(expected, result1); + } + /** * An expression that yields the same aliased object every time it is evaluated. */