update unit tests
This commit is contained in:
parent
68bdd7ff2c
commit
435b2bfcad
@ -1104,6 +1104,26 @@ public class TestRockets {
|
||||
return rocket;
|
||||
}
|
||||
|
||||
// Several simulations need the Falcon9Heavy, but with fins added to the
|
||||
// core stage (without them, there is a simulation exception at stage separation
|
||||
// This method is intended to add those fins to the F9H, but will in fact
|
||||
// add them to the second stage of a rocket
|
||||
public static void addCoreFins(Rocket rocket) {
|
||||
final int bodyFinCount = 4;
|
||||
final double bodyFinRootChord = 0.05;
|
||||
final double bodyFinTipChord = bodyFinRootChord;
|
||||
final double bodyFinHeight = 0.025;
|
||||
final double bodyFinSweep = 0.0;
|
||||
final AxialMethod bodyFinAxialMethod = AxialMethod.BOTTOM;
|
||||
final double bodyFinAxialOffset = 0.0;
|
||||
|
||||
final TrapezoidFinSet finSet = new TrapezoidFinSet(bodyFinCount, bodyFinRootChord, bodyFinTipChord, bodyFinSweep, bodyFinHeight);
|
||||
finSet.setName("Body Tube FinSet");
|
||||
finSet.setAxialMethod(bodyFinAxialMethod);
|
||||
|
||||
rocket.getChild(1).getChild(0).addChild(finSet);
|
||||
}
|
||||
|
||||
// This is a simple four-fin rocket with large endplates on the
|
||||
// fins, for testing CG and CP calculations with fins on pods.
|
||||
// not a complete rocket (no motor mount nor recovery system)
|
||||
|
@ -148,9 +148,13 @@ public class DisableStageTest extends BaseTestCase {
|
||||
@Test
|
||||
public void testBooster1() {
|
||||
//// Test disabling the stage
|
||||
Rocket rocketRemoved = TestRockets.makeFalcon9Heavy(); // Rocket with the last stage removed
|
||||
Rocket rocketDisabled = TestRockets.makeFalcon9Heavy(); // Rocket with the last stage disabled
|
||||
|
||||
Rocket rocketRemoved = TestRockets.makeFalcon9Heavy(); // Rocket with the last stage removed
|
||||
TestRockets.addCoreFins(rocketRemoved);
|
||||
|
||||
Rocket rocketDisabled = TestRockets.makeFalcon9Heavy(); // Rocket with the last stage disabled
|
||||
TestRockets.addCoreFins(rocketDisabled);
|
||||
|
||||
FlightConfigurationId fcid = new FlightConfigurationId(TestRockets.FALCON_9H_FCID_1);
|
||||
int stageNr = 2; // Stage 2 is the Parallel Booster Stage
|
||||
rocketRemoved.getChild(1).getChild(0).removeChild(0); // Remove the Parallel Booster Stage
|
||||
@ -171,6 +175,8 @@ public class DisableStageTest extends BaseTestCase {
|
||||
|
||||
//// Test re-enableing the stage.
|
||||
Rocket rocketOriginal = TestRockets.makeFalcon9Heavy();
|
||||
TestRockets.addCoreFins(rocketOriginal);
|
||||
|
||||
Simulation simOriginal = new Simulation(rocketOriginal);
|
||||
simOriginal.setFlightConfigurationId(fcid);
|
||||
simOriginal.getOptions().setISAAtmosphere(true);
|
||||
@ -188,7 +194,10 @@ public class DisableStageTest extends BaseTestCase {
|
||||
public void testBooster2() {
|
||||
//// Test disabling the stage
|
||||
Rocket rocketRemoved = TestRockets.makeFalcon9Heavy(); // Rocket with the last stage removed
|
||||
TestRockets.addCoreFins(rocketRemoved);
|
||||
|
||||
Rocket rocketDisabled = TestRockets.makeFalcon9Heavy(); // Rocket with the last stage disabled
|
||||
TestRockets.addCoreFins(rocketDisabled);
|
||||
|
||||
FlightConfigurationId fid = new FlightConfigurationId(TestRockets.FALCON_9H_FCID_1);
|
||||
int stageNr = 1; // Stage 1 is the Parallel Booster Stage's parent stage
|
||||
@ -225,6 +234,8 @@ public class DisableStageTest extends BaseTestCase {
|
||||
|
||||
//// Test re-enableing the stage.
|
||||
Rocket rocketOriginal = TestRockets.makeFalcon9Heavy();
|
||||
TestRockets.addCoreFins(rocketOriginal);
|
||||
|
||||
Simulation simOriginal = new Simulation(rocketOriginal);
|
||||
simOriginal.setFlightConfigurationId(fid);
|
||||
simOriginal.getOptions().setISAAtmosphere(true);
|
||||
|
@ -85,6 +85,8 @@ public class FlightEventsTest extends BaseTestCase {
|
||||
@Test
|
||||
public void testMultiStage() throws SimulationException {
|
||||
final Rocket rocket = TestRockets.makeFalcon9Heavy();
|
||||
TestRockets.addCoreFins(rocket);
|
||||
|
||||
final Simulation sim = new Simulation(rocket);
|
||||
sim.getOptions().setISAAtmosphere(true);
|
||||
sim.getOptions().setTimeStep(0.05);
|
||||
@ -98,32 +100,49 @@ public class FlightEventsTest extends BaseTestCase {
|
||||
final int branchCount = sim.getSimulatedData().getBranchCount();
|
||||
assertEquals(" Multi-stage simulation invalid branch count", 3, branchCount);
|
||||
|
||||
final AxialStage coreStage = rocket.getStage(1);
|
||||
final ParallelStage boosterStage = (ParallelStage) rocket.getStage(2);
|
||||
final InnerTube boosterMotorTubes = (InnerTube) boosterStage.getChild(1).getChild(0);
|
||||
final BodyTube coreBody = (BodyTube) coreStage.getChild(0);
|
||||
|
||||
// events whose time is too variable to check are given a time of 1200
|
||||
for (int b = 0; b < 3; b++) {
|
||||
final FlightEvent.Type[] expectedEventTypes;
|
||||
final double[] expectedEventTimes;
|
||||
FlightEvent[] expectedEvents;
|
||||
final RocketComponent[] expectedSources;
|
||||
switch (b) {
|
||||
case 0:
|
||||
expectedEventTypes = new FlightEvent.Type[]{FlightEvent.Type.LAUNCH, FlightEvent.Type.IGNITION, FlightEvent.Type.IGNITION,
|
||||
FlightEvent.Type.LIFTOFF, FlightEvent.Type.LAUNCHROD, FlightEvent.Type.APOGEE,
|
||||
FlightEvent.Type.BURNOUT, FlightEvent.Type.EJECTION_CHARGE, FlightEvent.Type.STAGE_SEPARATION,
|
||||
FlightEvent.Type.BURNOUT, FlightEvent.Type.EJECTION_CHARGE, FlightEvent.Type.STAGE_SEPARATION,
|
||||
FlightEvent.Type.TUMBLE, FlightEvent.Type.GROUND_HIT, FlightEvent.Type.SIMULATION_END};
|
||||
expectedEventTimes = new double[]{0.0, 0.0, 0.0, 0.1225, 0.125, 1.735, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0}; // Tumble and ground hit time are too variable, so don't include it
|
||||
final AxialStage coreStage = rocket.getStage(1);
|
||||
final ParallelStage boosterStage = (ParallelStage) rocket.getStage(2);
|
||||
final InnerTube boosterMotorTubes = (InnerTube) boosterStage.getChild(1).getChild(0);
|
||||
final BodyTube coreBody = (BodyTube) coreStage.getChild(0);
|
||||
expectedSources = new RocketComponent[]{rocket, boosterMotorTubes, coreBody, null, null, rocket,
|
||||
boosterMotorTubes, boosterStage, boosterStage, coreBody, coreStage, coreStage,
|
||||
null, null, null};
|
||||
expectedEvents = new FlightEvent[] {
|
||||
new FlightEvent(FlightEvent.Type.LAUNCH, 0.0, rocket),
|
||||
new FlightEvent(FlightEvent.Type.IGNITION, 0.0, boosterMotorTubes),
|
||||
new FlightEvent(FlightEvent.Type.IGNITION, 0.0, coreBody),
|
||||
new FlightEvent(FlightEvent.Type.LIFTOFF, 0.1225, null),
|
||||
new FlightEvent(FlightEvent.Type.LAUNCHROD, 0.125, null),
|
||||
new FlightEvent(FlightEvent.Type.APOGEE, 1.86, rocket),
|
||||
new FlightEvent(FlightEvent.Type.BURNOUT, 2.0, boosterMotorTubes),
|
||||
new FlightEvent(FlightEvent.Type.EJECTION_CHARGE, 2.0, boosterStage),
|
||||
new FlightEvent(FlightEvent.Type.STAGE_SEPARATION, 2.0, boosterStage),
|
||||
new FlightEvent(FlightEvent.Type.BURNOUT, 2.0, coreBody),
|
||||
new FlightEvent(FlightEvent.Type.EJECTION_CHARGE, 2.0, coreStage),
|
||||
new FlightEvent(FlightEvent.Type.STAGE_SEPARATION, 2.0, coreStage),
|
||||
new FlightEvent(FlightEvent.Type.TUMBLE, 2.4127, null),
|
||||
new FlightEvent(FlightEvent.Type.GROUND_HIT, 1200, null),
|
||||
new FlightEvent(FlightEvent.Type.SIMULATION_END, 1200, null)
|
||||
};
|
||||
break;
|
||||
case 1:
|
||||
expectedEvents = new FlightEvent[] {
|
||||
new FlightEvent(FlightEvent.Type.STAGE_SEPARATION, 2.0, coreStage),
|
||||
new FlightEvent(FlightEvent.Type.GROUND_HIT, 1200, null),
|
||||
new FlightEvent(FlightEvent.Type.SIMULATION_END, 1200, null)
|
||||
};
|
||||
break;
|
||||
case 2:
|
||||
expectedEventTypes = new FlightEvent.Type[]{FlightEvent.Type.TUMBLE, FlightEvent.Type.GROUND_HIT,
|
||||
FlightEvent.Type.SIMULATION_END};
|
||||
expectedEventTimes = new double[]{}; // Tumble and ground hit time are too variable, so don't include it
|
||||
expectedSources = new RocketComponent[]{null, null, null};
|
||||
expectedEvents = new FlightEvent[] {
|
||||
new FlightEvent(FlightEvent.Type.STAGE_SEPARATION, 2.0, boosterStage),
|
||||
new FlightEvent(FlightEvent.Type.TUMBLE, 3.551, null),
|
||||
new FlightEvent(FlightEvent.Type.GROUND_HIT, 1200, null),
|
||||
new FlightEvent(FlightEvent.Type.SIMULATION_END, 1200, null)
|
||||
};
|
||||
break;
|
||||
default:
|
||||
throw new IllegalStateException("Invalid branch number " + b);
|
||||
@ -131,28 +150,28 @@ public class FlightEventsTest extends BaseTestCase {
|
||||
|
||||
// Test event count
|
||||
final FlightDataBranch branch = sim.getSimulatedData().getBranch(b);
|
||||
final List<FlightEvent> eventList = branch.getEvents();
|
||||
final List<FlightEvent.Type> eventTypes = eventList.stream().map(FlightEvent::getType).collect(Collectors.toList());
|
||||
assertEquals(" Multi-stage simulation, branch " + b + " invalid number of events", expectedEventTypes.length, eventTypes.size());
|
||||
final FlightEvent[] events = (FlightEvent[]) branch.getEvents().toArray(new FlightEvent[0]);
|
||||
for (int i = 0; i < events.length; i++) {
|
||||
System.out.println("branch " + b + " index " + i + " event " + events[i]);
|
||||
}
|
||||
assertEquals(" Multi-stage simulation, branch " + b + " invalid number of events", expectedEvents.length, events.length);
|
||||
|
||||
// Test that all expected events are present, and in the right order
|
||||
for (int i = 0; i < expectedEventTypes.length; i++) {
|
||||
assertSame(" Flight type " + expectedEventTypes[i] + ", branch " + b + " not found in multi-stage simulation",
|
||||
expectedEventTypes[i], eventTypes.get(i));
|
||||
}
|
||||
// Test that all expected events are present, in the right order, at the right time, from the right sources
|
||||
for (int i = 0; i < events.length; i++) {
|
||||
final FlightEvent expected = expectedEvents[i];
|
||||
final FlightEvent actual = events[i];
|
||||
assertSame("Branch " + b + " FlightEvent " + i + " type " + expected.getType() + " not found; FlightEvent " + actual.getType() + " found instead",
|
||||
expected.getType(), actual.getType());
|
||||
|
||||
// Test that the event times are correct
|
||||
for (int i = 0; i < expectedEventTimes.length; i++) {
|
||||
assertEquals(" Flight type " + expectedEventTypes[i] + " has wrong time",
|
||||
expectedEventTimes[i], eventList.get(i).getTime(), EPSILON);
|
||||
}
|
||||
if (1200 != expected.getTime()) {
|
||||
assertEquals("Branch " + b + " FlightEvent " + i + " type " + expected.getType() + " has wrong time",
|
||||
expected.getTime(), actual.getTime(), EPSILON);
|
||||
}
|
||||
|
||||
// Test that the event sources are correct
|
||||
for (int i = 0; i < expectedSources.length; i++) {
|
||||
assertEquals(" Flight type " + expectedEventTypes[i] + " has wrong source",
|
||||
expectedSources[i], eventList.get(i).getSource());
|
||||
// Test that the event sources are correct
|
||||
assertEquals("Branch " + b + " FlightEvent " + i + " type " + expected.getType() + " has wrong source",
|
||||
expected.getSource(), actual.getSource());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user