Unit test to see if sim status is saved/loaded properly

This commit is contained in:
JoePfeiffer 2023-03-03 18:23:40 -07:00
parent f98a8749db
commit b6c6a47811

View File

@ -22,6 +22,7 @@ import net.sf.openrocket.database.motor.MotorDatabase;
import net.sf.openrocket.database.motor.ThrustCurveMotorSetDatabase;
import net.sf.openrocket.document.OpenRocketDocument;
import net.sf.openrocket.document.OpenRocketDocumentFactory;
import net.sf.openrocket.document.Simulation;
import net.sf.openrocket.document.StorageOptions;
import net.sf.openrocket.file.GeneralRocketLoader;
import net.sf.openrocket.file.RocketLoadException;
@ -264,7 +265,64 @@ public class OpenRocketSaverTest {
// TODO: fix estimateFileSize so that it's a lot more accurate
}
/**
* Test sim status with/without sim data in file.
*/
@Test
public void TestSimStatus() {
Rocket rocket = TestRockets.makeEstesAlphaIII();
OpenRocketDocument rocketDoc = OpenRocketDocumentFactory.createDocumentFromRocket(rocket);
// Hook up some simulations.
// First sim will not have options set
Simulation sim1 = new Simulation(rocket);
rocketDoc.addSimulation(sim1);
// Second sim has options, but hasn't been simulated
Simulation sim2 = new Simulation(rocket);
sim2.getOptions().setISAAtmosphere(true);
sim2.getOptions().setTimeStep(0.05);
sim2.setFlightConfigurationId(TestRockets.TEST_FCID_0);
rocketDoc.addSimulation(sim2);
// Third sim has been executed
Simulation sim3 = new Simulation(rocket);
sim3.getOptions().setISAAtmosphere(true);
sim3.getOptions().setTimeStep(0.05);
sim3.setFlightConfigurationId(TestRockets.TEST_FCID_0);
try {
sim3.simulate();
} catch (Exception e) {
fail(e.toString());
}
rocketDoc.addSimulation(sim3);
// Fourth sim has been executed, then configuration changed
Simulation sim4 = new Simulation(rocket);
sim4.getOptions().setISAAtmosphere(true);
sim4.getOptions().setTimeStep(0.05);
sim4.setFlightConfigurationId(TestRockets.TEST_FCID_0);
try {
sim4.simulate();
} catch (Exception e) {
fail(e.toString());
}
sim4.getOptions().setTimeStep(0.1);
rocketDoc.addSimulation(sim4);
// save, then load document
StorageOptions options = new StorageOptions();
options.setSaveSimulationData(true);
File file = saveRocket(rocketDoc, options);
OpenRocketDocument rocketDocLoaded = loadRocket(file.getPath());
assertEquals(Simulation.Status.CANT_RUN, rocketDocLoaded.getSimulations().get(0).getStatus());
assertEquals(Simulation.Status.NOT_SIMULATED, rocketDocLoaded.getSimulations().get(1).getStatus());
assertEquals(Simulation.Status.LOADED, rocketDocLoaded.getSimulations().get(2).getStatus());
assertEquals(Simulation.Status.OUTDATED, rocketDocLoaded.getSimulations().get(3).getStatus());
}
////////////////////////////////
// Tests for File Version 1.7 //
@ -276,7 +334,8 @@ public class OpenRocketSaverTest {
assertEquals(108, getCalculatedFileVersion(rocketDoc));
}
////////////////////////////////
/*
* Utility Functions
*/