-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
139 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 0 additions & 43 deletions
43
.../banananation/src/main/java/gov/nasa/jpl/aerie/banananation/activities/RussianBanana.java
This file was deleted.
Oops, something went wrong.
72 changes: 72 additions & 0 deletions
72
...nation/src/main/java/gov/nasa/jpl/aerie/banananation/activities/RussianNestingBanana.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package gov.nasa.jpl.aerie.banananation.activities; | ||
|
||
import gov.nasa.jpl.aerie.banananation.Mission; | ||
import gov.nasa.jpl.aerie.merlin.framework.annotations.ActivityType; | ||
import gov.nasa.jpl.aerie.merlin.framework.annotations.AutoValueMapper; | ||
import gov.nasa.jpl.aerie.merlin.framework.annotations.Export; | ||
import gov.nasa.jpl.aerie.merlin.protocol.types.Duration; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import static gov.nasa.jpl.aerie.banananation.generated.ActivityActions.call; | ||
import static gov.nasa.jpl.aerie.merlin.framework.ModelActions.delay; | ||
|
||
/** | ||
* RussianNestingBanana nests activity types as parameters inside an activity | ||
* | ||
* This activity tests the use of activity types as parameters and within compound type parameters. There are a few use cases: | ||
* 1. Basic activity type parameter which is passed through and called without parent level modeling | ||
* 2. List of activity types which are just iterated through and called | ||
* 3. Using a parent level parameter to override information in the call to a child from an activity type parameter | ||
* | ||
* @subsystem fruit | ||
* @contact John Doe | ||
*/ | ||
@ActivityType("RussianNestingBanana") | ||
public final class RussianNestingBanana { | ||
|
||
/** Record encapsulating an activity type **/ | ||
@AutoValueMapper.Record | ||
public record pickBananaWithId( | ||
int id, | ||
PickBananaActivity pickBananaActivity | ||
) {} | ||
|
||
/** Record type parameter encapsulating an activity type **/ | ||
@Export.Parameter | ||
public pickBananaWithId pickBananaActivityRecord; | ||
|
||
/** Parent level override parameter, in this case to override call to peel banana | ||
* found in the pickBannaActivityRecord parameter **/ | ||
@Export.Parameter | ||
public int pickBananaQuantityOverride = 0; | ||
|
||
/** List of activity type parameter example **/ | ||
@Export.Parameter | ||
public List<BiteBananaActivity> biteBananaActivity; | ||
|
||
/** Vanilla activity type parameter **/ | ||
@Export.Parameter | ||
public PeelBananaActivity peelBananaActivity; | ||
|
||
|
||
@ActivityType.EffectModel | ||
public void run(final Mission mission) { | ||
// if the pickBananaQuantityOverride is preset use that integer instead of the pickBananaActivityRecord | ||
if(pickBananaQuantityOverride != 0) { | ||
PickBananaActivity pickBananaActivity = pickBananaActivityRecord.pickBananaActivity; | ||
pickBananaActivity.quantity = pickBananaQuantityOverride; | ||
call(mission, pickBananaActivity); | ||
} else { // else use the record type parameter supplied | ||
call(mission, pickBananaActivityRecord.pickBananaActivity()); | ||
} | ||
// call a bite banana for each element in the list of biteBanana activities | ||
for (final var bite : biteBananaActivity) { | ||
call(mission, bite); | ||
delay(Duration.of(30, Duration.MINUTE)); | ||
} | ||
// call peel banana activity | ||
call(mission, peelBananaActivity); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
.../src/test/java/gov/nasa/jpl/aerie/banananation/activities/RussianNestingActivityTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package gov.nasa.jpl.aerie.banananation.activities; | ||
|
||
import gov.nasa.jpl.aerie.banananation.Configuration; | ||
import gov.nasa.jpl.aerie.banananation.Mission; | ||
import gov.nasa.jpl.aerie.banananation.SimulationUtility; | ||
import gov.nasa.jpl.aerie.banananation.generated.GeneratedModelType; | ||
import gov.nasa.jpl.aerie.banananation.generated.activities.ParameterTestActivityMapper; | ||
import gov.nasa.jpl.aerie.banananation.generated.activities.RussianNestingBananaMapper; | ||
import gov.nasa.jpl.aerie.contrib.serialization.mappers.DurationValueMapper; | ||
import gov.nasa.jpl.aerie.merlin.driver.DirectiveTypeRegistry; | ||
import gov.nasa.jpl.aerie.merlin.driver.MissionModelBuilder; | ||
import gov.nasa.jpl.aerie.merlin.driver.SerializedActivity; | ||
import gov.nasa.jpl.aerie.merlin.framework.Registrar; | ||
import gov.nasa.jpl.aerie.merlin.framework.junit.MerlinExtension; | ||
import gov.nasa.jpl.aerie.merlin.protocol.types.InstantiationException; | ||
import gov.nasa.jpl.aerie.merlin.protocol.types.SerializedValue; | ||
import org.apache.commons.lang3.tuple.Pair; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.TestInstance; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
|
||
import java.nio.file.Path; | ||
import java.time.Instant; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static gov.nasa.jpl.aerie.banananation.generated.ActivityActions.call; | ||
import static gov.nasa.jpl.aerie.merlin.protocol.types.Duration.MILLISECONDS; | ||
import static gov.nasa.jpl.aerie.merlin.protocol.types.Duration.SECONDS; | ||
import static gov.nasa.jpl.aerie.merlin.protocol.types.Duration.duration; | ||
import static org.junit.jupiter.api.Assertions.assertArrayEquals; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
@ExtendWith(MerlinExtension.class) | ||
@TestInstance(TestInstance.Lifecycle.PER_CLASS) | ||
public class RussianNestingActivityTest { | ||
private final RussianNestingBananaMapper mapper; | ||
|
||
public RussianNestingActivityTest() { | ||
this.mapper = new RussianNestingBananaMapper(); | ||
} | ||
|
||
@Test | ||
public void testDefaultSimulationDoesNotThrow() { | ||
final var schedule = SimulationUtility.buildSchedule( | ||
Pair.of( | ||
duration(1100, MILLISECONDS), | ||
new SerializedActivity("RussianNestingBanana", | ||
Map.of("pickBananaActivityRecord", | ||
SerializedValue.of(Map.of("id", SerializedValue.of(2), | ||
"pickBananaActivity", SerializedValue.of(Map.of("quantity", SerializedValue.of(10))))) | ||
, "pickBananaQuantityOverride", SerializedValue.of(0), | ||
"biteBananaActivity", SerializedValue.of(List.of()), | ||
"peelBananaActivity", SerializedValue.of(Map.of("peelDirection", SerializedValue.of("fromStem"))))))); | ||
|
||
final var simulationDuration = duration(5, SECONDS); | ||
|
||
final var simulationResults = SimulationUtility.simulate(schedule, simulationDuration); | ||
|
||
System.out.println(simulationResults.discreteProfiles); | ||
System.out.println(simulationResults.realProfiles); | ||
} | ||
|
||
} |