Skip to content

Commit

Permalink
Test simulation input directives invariance
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelCourtney committed Nov 23, 2024
1 parent b97f551 commit c2e20c2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public boolean validateGrowingDuration() {
@EffectModel
@ControllableDuration(parameterName = "growingDuration")
public void run(final Mission mission) {
final var rate = this.quantity() / (double) this.growingDuration().in(Duration.SECONDS);
final var rate = this.quantity() / (double) this.growingDuration().ratioOver(Duration.SECOND);
mission.fruit.rate.add(rate);
delay(this.growingDuration());
mission.fruit.rate.add(-rate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,35 @@ public void simResultMarkedNotStaleAfterRollback_SimulateThenCommit() {

assertFalse(simResults.isStale());
}

@Test
void simulationInputDirectivesDontChange() {
plan.create(
"BiteBanana",
new DirectiveStart.Absolute(Duration.MINUTE),
Map.of("biteSize", SerializedValue.of(1))
);

final var expectedDirectives = plan.directives();
final var simResults = plan.simulate();

plan.create(
"GrowBanana",
new DirectiveStart.Absolute(Duration.HOUR),
Map.of(
"growingDuration", SerializedValue.of(10000),
"quantity", SerializedValue.of(1)
)
);

assertIterableEquals(expectedDirectives, simResults.inputDirectives());
assertNotEquals(plan.directives(), simResults.inputDirectives());

plan.commit();

assertIterableEquals(expectedDirectives, simResults.inputDirectives());
assertNotEquals(plan.directives(), simResults.inputDirectives());

assertIterableEquals(plan.directives(), plan.simulate().inputDirectives());
}
}

0 comments on commit c2e20c2

Please sign in to comment.