Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature activity type value mappers #1294

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
updated test for activity behavior
  • Loading branch information
amgreer99 committed Jan 23, 2024
commit 078193ea80950a9df772479aef7d7a82ebb05df6
Original file line number Diff line number Diff line change
@@ -1,36 +1,22 @@
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.MINUTE;
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)
@@ -48,18 +34,48 @@ public void testDefaultSimulationDoesNotThrow() {
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")))))));
SerializedValue.of(Map.of("id",
SerializedValue.of(2),
"pickBananaActivity",
SerializedValue.of(Map.of("quantity",
SerializedValue.of(10))))),
"pickBananaQuantityOverride", SerializedValue.of(3),
"biteBananaActivity", SerializedValue.of(List.of(SerializedValue.of(Map.of("biteSize",
SerializedValue.of(7.0))),
SerializedValue.of(Map.of("biteSize",
SerializedValue.of(1.0))))),
"peelBananaActivity", SerializedValue.of(Map.of("peelDirection",
SerializedValue.of("fromStem")))))));

final var simulationDuration = duration(5, SECONDS);

final var simulationResults = SimulationUtility.simulate(schedule, simulationDuration);
var simulationResults = SimulationUtility.simulate(schedule, simulationDuration);

// verify results
// 1. Plant count decreased by 3 (200 -> 197) from the pickBananaActivity call using pickBananaQuantityOverride
var finalPlantCount = simulationResults.discreteProfiles.get("/plant").getValue().get(simulationResults.discreteProfiles.get("/plant").getValue().size()-1).dynamics().asInt().orElseThrow();
assert(finalPlantCount == 197);

System.out.println(simulationResults.discreteProfiles);
System.out.println(simulationResults.realProfiles);
// 2. Verify first bite banana activity ran, decrementing "/fruit" by 7 (from 4 to -3) in total and setting flag to flag B
var finalFruitCount = simulationResults.realProfiles.get("/fruit").getValue().get(simulationResults.realProfiles.get("/fruit").getValue().size()-1).dynamics().initial;
var finalFlagState = simulationResults.discreteProfiles.get("/flag").getValue().get(simulationResults.discreteProfiles.get("/flag").getValue().size()-1).dynamics().asString().orElseThrow();

assert(finalFruitCount == 4.0 - 7.0);
assert(finalFlagState == "B");

// 3. Verify second bite banana activity ran, decrementing "/fruit" by 1 (from -3 to -4) in total and setting flag to flag A
simulationResults = SimulationUtility.simulate(schedule, duration(35, MINUTE));
finalFruitCount = simulationResults.realProfiles.get("/fruit").getValue().get(simulationResults.realProfiles.get("/fruit").getValue().size()-1).dynamics().initial;
finalFlagState = simulationResults.discreteProfiles.get("/flag").getValue().get(simulationResults.discreteProfiles.get("/flag").getValue().size()-1).dynamics().asString().orElseThrow();
assert(finalFruitCount == 4.0 - 8.0);
assert(finalFlagState == "A");

simulationResults = SimulationUtility.simulate(schedule, duration(65, MINUTE));
// 4. Verify peel banana activity ran educing frruit by 1.0 and peel by 1.0 to -5.0 and 3.0 respectively
finalFruitCount = simulationResults.realProfiles.get("/fruit").getValue().get(simulationResults.realProfiles.get("/fruit").getValue().size()-1).dynamics().initial;
var finalPeelState = simulationResults.discreteProfiles.get("/peel").getValue().get(simulationResults.discreteProfiles.get("/peel").getValue().size()-1).dynamics().asReal().orElseThrow();
assert(finalFruitCount == 4.0 - 9.0);
assert(finalPeelState == 3.0);
}

}