clean up FlightEventsTest
This commit is contained in:
parent
7fd390e4d3
commit
b36950651e
@ -32,6 +32,10 @@ public class FlightEventsTest extends BaseTestCase {
|
|||||||
@Test
|
@Test
|
||||||
public void testSingleStage() throws SimulationException {
|
public void testSingleStage() throws SimulationException {
|
||||||
final Rocket rocket = TestRockets.makeEstesAlphaIII();
|
final Rocket rocket = TestRockets.makeEstesAlphaIII();
|
||||||
|
final AxialStage stage = rocket.getStage(0);
|
||||||
|
final InnerTube motorMountTube = (InnerTube) stage.getChild(1).getChild(2);
|
||||||
|
final Parachute parachute = (Parachute) stage.getChild(1).getChild(3);
|
||||||
|
|
||||||
final Simulation sim = new Simulation(rocket);
|
final Simulation sim = new Simulation(rocket);
|
||||||
sim.getOptions().setISAAtmosphere(true);
|
sim.getOptions().setISAAtmosphere(true);
|
||||||
sim.getOptions().setTimeStep(0.05);
|
sim.getOptions().setTimeStep(0.05);
|
||||||
@ -43,40 +47,23 @@ public class FlightEventsTest extends BaseTestCase {
|
|||||||
final int branchCount = sim.getSimulatedData().getBranchCount();
|
final int branchCount = sim.getSimulatedData().getBranchCount();
|
||||||
assertEquals(" Single stage simulation invalid branch count ", 1, branchCount);
|
assertEquals(" Single stage simulation invalid branch count ", 1, branchCount);
|
||||||
|
|
||||||
final FlightEvent.Type[] expectedEventTypes = {FlightEvent.Type.LAUNCH, FlightEvent.Type.IGNITION, FlightEvent.Type.LIFTOFF,
|
final FlightEvent[] expectedEvents = new FlightEvent[] {
|
||||||
FlightEvent.Type.LAUNCHROD, FlightEvent.Type.BURNOUT, FlightEvent.Type.EJECTION_CHARGE, FlightEvent.Type.RECOVERY_DEVICE_DEPLOYMENT,
|
new FlightEvent(FlightEvent.Type.LAUNCH, 0.0, rocket),
|
||||||
FlightEvent.Type.APOGEE, FlightEvent.Type.GROUND_HIT, FlightEvent.Type.SIMULATION_END};
|
new FlightEvent(FlightEvent.Type.IGNITION, 0.0, motorMountTube),
|
||||||
final double[] expectedEventTimes = {0.0, 0.0, 0.1275, 0.13, 2.0, 2.0, 2.001, 2.48338}; // Ground hit time is too variable, so don't include it
|
new FlightEvent(FlightEvent.Type.LIFTOFF, 0.1275, null),
|
||||||
final AxialStage stage = rocket.getStage(0);
|
new FlightEvent(FlightEvent.Type.LAUNCHROD, 0.13, null),
|
||||||
final InnerTube motorMountTube = (InnerTube) stage.getChild(1).getChild(2);
|
new FlightEvent(FlightEvent.Type.BURNOUT, 2.0, motorMountTube),
|
||||||
final Parachute parachute = (Parachute) stage.getChild(1).getChild(3);
|
new FlightEvent(FlightEvent.Type.EJECTION_CHARGE, 2.0, stage),
|
||||||
final RocketComponent[] expectedSources = {rocket, motorMountTube, null, null, motorMountTube,
|
new FlightEvent(FlightEvent.Type.RECOVERY_DEVICE_DEPLOYMENT, 2.001, parachute),
|
||||||
stage, parachute, rocket, null, null};
|
new FlightEvent(FlightEvent.Type.APOGEE, 2.48338, rocket),
|
||||||
|
new FlightEvent(FlightEvent.Type.GROUND_HIT, 1200, null),
|
||||||
|
new FlightEvent(FlightEvent.Type.SIMULATION_END, 1200, null)
|
||||||
|
};
|
||||||
|
// final double[] expectedEventTimes = {0.0, 0.0, 0.1275, 0.13, 2.0, 2.0, 2.001, 2.48338}; // Ground hit time is too variable, so don't include it
|
||||||
|
// final RocketComponent[] expectedSources = {rocket, motorMountTube, null, null, motorMountTube,
|
||||||
|
// stage, parachute, rocket, null, null};
|
||||||
|
|
||||||
// Test event count
|
checkEvents(expectedEvents, sim, 0);
|
||||||
FlightDataBranch branch = sim.getSimulatedData().getBranch(0);
|
|
||||||
List<FlightEvent> eventList = branch.getEvents();
|
|
||||||
List<FlightEvent.Type> eventTypes = eventList.stream().map(FlightEvent::getType).collect(Collectors.toList());
|
|
||||||
assertEquals(" Single stage simulation invalid number of events ", expectedEventTypes.length, eventTypes.size());
|
|
||||||
|
|
||||||
// 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] + " not found in single stage simulation ",
|
|
||||||
expectedEventTypes[i], eventTypes.get(i));
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -156,29 +143,34 @@ public class FlightEventsTest extends BaseTestCase {
|
|||||||
throw new IllegalStateException("Invalid branch number " + b);
|
throw new IllegalStateException("Invalid branch number " + b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
checkEvents(expectedEvents, sim, b);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkEvents(FlightEvent[] expectedEvents, Simulation sim, int branchNo) {
|
||||||
|
|
||||||
|
FlightEvent[] actualEvents = sim.getSimulatedData().getBranch(branchNo).getEvents().toArray(new FlightEvent[0]);
|
||||||
|
|
||||||
// Test event count
|
// Test event count
|
||||||
final FlightDataBranch branch = sim.getSimulatedData().getBranch(b);
|
assertEquals("Branch " + branchNo + " invalid number of events ", expectedEvents.length, actualEvents.length);
|
||||||
final FlightEvent[] events = branch.getEvents().toArray(new FlightEvent[0]);
|
|
||||||
assertEquals(" Multi-stage simulation, branch " + b + " invalid number of events ", expectedEvents.length, events.length);
|
|
||||||
|
|
||||||
// Test that all expected events are present, in the right order, at the right time, from the right sources
|
// 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++) {
|
for (int i = 0; i < actualEvents.length; i++) {
|
||||||
final FlightEvent expected = expectedEvents[i];
|
final FlightEvent expected = expectedEvents[i];
|
||||||
final FlightEvent actual = events[i];
|
final FlightEvent actual = actualEvents[i];
|
||||||
assertSame("Branch " + b + " FlightEvent " + i + " type " + expected.getType() + " not found; FlightEvent " + actual.getType() + " found instead",
|
assertSame("Branch " + branchNo + " FlightEvent " + i + " type " + expected.getType() + " not found; FlightEvent " + actual.getType() + " found instead",
|
||||||
expected.getType(), actual.getType());
|
expected.getType(), actual.getType());
|
||||||
|
|
||||||
if (1200 != expected.getTime()) {
|
if (1200 != expected.getTime()) {
|
||||||
// Tumbling can have a very large time error, so implement a more course epsilon (otherwise unit tests just keep failing...)
|
// event times that are dependent on simulation step time shouldn't be held to tighter bounds than that
|
||||||
double epsilon = actual.getType() == FlightEvent.Type.TUMBLE || actual.getType() == FlightEvent.Type.APOGEE ? 0.05 : EPSILON;
|
double epsilon = actual.getType() == FlightEvent.Type.TUMBLE || actual.getType() == FlightEvent.Type.APOGEE ? sim.getOptions().getTimeStep() : EPSILON;
|
||||||
assertEquals("Branch " + b + " FlightEvent " + i + " type " + expected.getType() + " has wrong time ",
|
assertEquals("Branch " + branchNo + " FlightEvent " + i + " type " + expected.getType() + " has wrong time ",
|
||||||
expected.getTime(), actual.getTime(), epsilon);
|
expected.getTime(), actual.getTime(), epsilon);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test that the event sources are correct
|
// Test that the event sources are correct
|
||||||
assertEquals("Branch " + b + " FlightEvent " + i + " type " + expected.getType() + " has wrong source ",
|
assertEquals("Branch " + branchNo + " FlightEvent " + i + " type " + expected.getType() + " has wrong source ",
|
||||||
expected.getSource(), actual.getSource());
|
expected.getSource(), actual.getSource());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user