Skip to content

Commit

Permalink
Implement Windows.split tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelCourtney committed Jul 21, 2022
1 parent d84dd1f commit 94be979
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import gov.nasa.jpl.aerie.constraints.tree.RealParameter;
import gov.nasa.jpl.aerie.constraints.tree.RealResource;
import gov.nasa.jpl.aerie.constraints.tree.RealValue;
import gov.nasa.jpl.aerie.constraints.tree.Split;
import gov.nasa.jpl.aerie.constraints.tree.StartOf;
import gov.nasa.jpl.aerie.constraints.tree.Times;
import gov.nasa.jpl.aerie.constraints.tree.Transition;
Expand Down Expand Up @@ -490,6 +491,29 @@ public void testParseInvert() {
assertEquivalent(expected, result);
}

@Test
public void testParseSplit() {
final var json = Json
.createObjectBuilder()
.add("kind", "WindowsExpressionSplit")
.add("windows", Json
.createObjectBuilder()
.add("kind", "WindowsExpressionActivityWindow")
.add("alias", "A"))
.add("numberOfSubWindows", 3)
.build();

final var result = windowsExpressionP.parse(json).getSuccessOrThrow();

final var expected =
new Split(
new ActivityWindow("A"),
3
);

assertEquivalent(expected, result);
}

@Test
public void testForEachActivity() {
final var json = Json
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
import static gov.nasa.jpl.aerie.constraints.Assertions.assertEquivalent;
import static gov.nasa.jpl.aerie.constraints.time.Window.Inclusivity.Exclusive;
import static gov.nasa.jpl.aerie.constraints.time.Window.Inclusivity.Inclusive;
import static gov.nasa.jpl.aerie.merlin.protocol.types.Duration.MICROSECOND;
import static gov.nasa.jpl.aerie.merlin.protocol.types.Duration.MICROSECONDS;
import static gov.nasa.jpl.aerie.merlin.protocol.types.Duration.MILLISECONDS;
import static gov.nasa.jpl.aerie.merlin.protocol.types.Duration.SECONDS;
import static org.junit.jupiter.api.Assertions.fail;

Expand Down Expand Up @@ -50,6 +51,36 @@ public void testNot() {
assertEquivalent(expected, result);
}

@Test
public void testSplit() {
final var simResults = new SimulationResults(
Window.between(0, 20, SECONDS),
List.of(),
Map.of(),
Map.of()
);

final var windows = new Windows();
windows.add(Window.between(0, Inclusive, 5, Exclusive, SECONDS));
windows.add(Window.between(10000000, Exclusive, 15000001, Exclusive, MICROSECONDS));
windows.add(Window.at(20, SECONDS));

final var result = new Split(Supplier.of(windows), 3).evaluate(simResults, Map.of());

final var expected = new Windows();
expected.add(Window.between(0, Inclusive, 1666666, Exclusive, MICROSECONDS));
expected.add(Window.between(1666666, Exclusive, 3333332, Exclusive, MICROSECONDS));
expected.add(Window.between(3333332, Exclusive, 5000000, Exclusive, MICROSECONDS));

expected.add(Window.between(10000000, Exclusive, 11666667, Exclusive, MICROSECONDS));
expected.add(Window.between(11666667, Exclusive, 13333334, Exclusive, MICROSECONDS));
expected.add(Window.between(13333334, Exclusive, 15000001, Exclusive, MICROSECONDS));

expected.add(Window.at(20, SECONDS));

assertEquivalent(expected, result);
}

@Test
public void testAnd() {
final var simResults = new SimulationResults(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,44 @@ export default () => {
);
}

@Test
void testSplit() {
checkSuccessfulCompilation(
"""
export default () => {
return Real.Resource("state of charge").lessThan(0.3).split(4)
}
""",
new ViolationsOf(
new Split(
new LessThan(new RealResource("state of charge"), new RealValue(0.3)),
4
)
)
);
}

@Test
void testSplitArgumentError() {
checkFailedCompilation(
"""
export default () => {
return Real.Resource("state of charge").lessThan(0.3).split(0)
}
""",
".split numberOfSubWindows cannot be less than 1, but was: 0"
);

checkFailedCompilation(
"""
export default () => {
return Real.Resource("state of charge").lessThan(0.3).split(-2)
}
""",
".split numberOfSubWindows cannot be less than 1, but was: -2"
);
}

@Test
void testViolations() {
checkSuccessfulCompilation(
Expand Down

0 comments on commit 94be979

Please sign in to comment.