Fixed TestRocketOptimizationFunction unit tests
This commit is contained in:
parent
53b20eb999
commit
711f71e2c8
@ -1,6 +1,5 @@
|
||||
package net.sf.openrocket.document;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.EventListener;
|
||||
import java.util.EventObject;
|
||||
import java.util.List;
|
||||
@ -13,7 +12,6 @@ import net.sf.openrocket.aerodynamics.BarrowmanCalculator;
|
||||
import net.sf.openrocket.aerodynamics.WarningSet;
|
||||
import net.sf.openrocket.formatting.RocketDescriptor;
|
||||
import net.sf.openrocket.masscalc.MassCalculator;
|
||||
import net.sf.openrocket.motor.MotorConfiguration;
|
||||
import net.sf.openrocket.rocketcomponent.FlightConfiguration;
|
||||
import net.sf.openrocket.rocketcomponent.FlightConfigurationId;
|
||||
import net.sf.openrocket.rocketcomponent.Rocket;
|
||||
@ -147,6 +145,10 @@ public class Simulation implements ChangeSource, Cloneable {
|
||||
this.name = name;
|
||||
|
||||
this.options = options;
|
||||
|
||||
FlightConfigurationId fcid = rocket.getSelectedConfiguration().getFlightConfigurationID();
|
||||
options.setFlightConfigurationId(fcid);
|
||||
|
||||
options.addChangeListener(new ConditionListener());
|
||||
|
||||
if (extensions != null) {
|
||||
@ -280,6 +282,13 @@ public class Simulation implements ChangeSource, Cloneable {
|
||||
status = Status.OUTDATED;
|
||||
}
|
||||
}
|
||||
|
||||
// if the id hasn't been set yet, skip.
|
||||
if ( options.getId().hasError() ){
|
||||
log.warn(" simulationOptions lacks a valid id. Skipping.");
|
||||
status = Status.CANT_RUN;
|
||||
return status;
|
||||
}
|
||||
|
||||
FlightConfiguration config = rocket.getFlightConfiguration(options.getId());
|
||||
|
||||
|
@ -568,7 +568,9 @@ public class Rocket extends RocketComponent {
|
||||
|
||||
public FlightConfiguration createFlightConfiguration( final FlightConfigurationId fcid) {
|
||||
checkState();
|
||||
if( fcid.hasError() ){
|
||||
if( null == fcid ){
|
||||
throw new NullPointerException("Attempted to create a flightConfiguration from a null key!");
|
||||
}else if( fcid.hasError() ){
|
||||
throw new NullPointerException("Attempted to create a flightConfiguration from an error key!");
|
||||
}else if( configSet.containsKey(fcid)){
|
||||
return this.configSet.get(fcid);
|
||||
@ -815,6 +817,7 @@ public class Rocket extends RocketComponent {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
buf.append(String.format("====== Dumping %d Configurations from rocket: \n", this.getConfigurationCount(), this.getName()));
|
||||
final String fmt = " [%-12s]: %s\n";
|
||||
buf.append(String.format(fmt, " *SELECTED* ", selectedConfiguration.getName() ));
|
||||
for( FlightConfiguration config : this.configSet.values() ){
|
||||
String shortKey = config.getId().toShortKey();
|
||||
if( this.selectedConfiguration.equals( config)){
|
||||
|
@ -51,7 +51,7 @@ public class SimulationOptions implements ChangeSource, Cloneable {
|
||||
protected final Preferences preferences = Application.getPreferences();
|
||||
|
||||
private final Rocket rocket;
|
||||
private FlightConfigurationId configId = new FlightConfigurationId();
|
||||
private FlightConfigurationId configId = FlightConfigurationId.ERROR_FCID;
|
||||
|
||||
/*
|
||||
* NOTE: When adding/modifying parameters, they must also be added to the
|
||||
@ -439,7 +439,6 @@ public class SimulationOptions implements ChangeSource, Cloneable {
|
||||
if (this.rocket == src.rocket) {
|
||||
this.configId = src.configId;
|
||||
} else {
|
||||
|
||||
if (src.rocket.hasMotors(src.configId)) {
|
||||
// First check for exact match:
|
||||
if (this.rocket.containsFlightConfigurationID(src.configId)) {
|
||||
@ -462,7 +461,7 @@ public class SimulationOptions implements ChangeSource, Cloneable {
|
||||
this.configId = matchID;
|
||||
}
|
||||
} else {
|
||||
this.configId = null;
|
||||
this.configId = FlightConfigurationId.ERROR_FCID;
|
||||
}
|
||||
}
|
||||
|
||||
@ -588,7 +587,7 @@ public class SimulationOptions implements ChangeSource, Cloneable {
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
if (configId == null)
|
||||
if (configId.hasError())
|
||||
return rocket.hashCode();
|
||||
return rocket.hashCode() + configId.hashCode();
|
||||
}
|
||||
|
@ -3,6 +3,15 @@ package net.sf.openrocket.optimization.rocketoptimization;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.jmock.Expectations;
|
||||
import org.jmock.Mockery;
|
||||
import org.jmock.auto.Mock;
|
||||
import org.jmock.integration.junit4.JMock;
|
||||
import org.jmock.integration.junit4.JUnit4Mockery;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import net.sf.openrocket.document.Simulation;
|
||||
import net.sf.openrocket.optimization.general.OptimizationException;
|
||||
import net.sf.openrocket.optimization.general.Point;
|
||||
@ -13,14 +22,6 @@ import net.sf.openrocket.unit.Value;
|
||||
import net.sf.openrocket.util.Pair;
|
||||
import net.sf.openrocket.util.BaseTestCase.BaseTestCase;
|
||||
|
||||
import org.jmock.Expectations;
|
||||
import org.jmock.Mockery;
|
||||
import org.jmock.auto.Mock;
|
||||
import org.jmock.integration.junit4.JMock;
|
||||
import org.jmock.integration.junit4.JUnit4Mockery;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
|
||||
@RunWith(JMock.class)
|
||||
public class TestRocketOptimizationFunction extends BaseTestCase {
|
||||
@ -222,12 +223,13 @@ public class TestRocketOptimizationFunction extends BaseTestCase {
|
||||
|
||||
|
||||
@Test
|
||||
public void testNewSimulationInstance() {
|
||||
public void testNewSimulationNames() {
|
||||
final Rocket rocket = new Rocket();
|
||||
rocket.setName("Foobar");
|
||||
final Simulation simulation = new Simulation(rocket);
|
||||
simulation.setName("MySim");
|
||||
|
||||
|
||||
RocketOptimizationFunction function = new RocketOptimizationFunction(simulation,
|
||||
parameter, goal, domain, modifier1, modifier2);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user