[Bugfix] moved ConfigurationTest to FlightConfigurationTest
- in FlightConfiguration: -- adjusted functions to consistently refer to <x>ActiveMotors() -- corresponding functions now act the same way - removed '.release()' calls from FlightConfiguration
This commit is contained in:
parent
af56da4162
commit
bc906c6652
@ -97,7 +97,7 @@ public class RocksimSaver extends RocketSaver {
|
||||
final FlightConfiguration configuration = rocket.getDefaultConfiguration();
|
||||
final double cg = massCalc.getCG(configuration, MassCalculator.MassCalcType.NO_MOTORS).x *
|
||||
RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH;
|
||||
configuration.release();
|
||||
|
||||
int stageCount = rocket.getStageCount();
|
||||
if (stageCount == 3) {
|
||||
result.setStage321CG(cg);
|
||||
|
@ -21,8 +21,8 @@ import net.sf.openrocket.util.StateChangeListener;
|
||||
|
||||
|
||||
/**
|
||||
* A class defining a rocket configuration, including which stages are active.
|
||||
*
|
||||
* A class defining a rocket configuration.
|
||||
* Describes active stages, and active motors.
|
||||
*
|
||||
* @author Sampo Niskanen <sampo.niskanen@iki.fi>
|
||||
* @author Daniel Williams <equipoise@gmail.com>
|
||||
@ -268,13 +268,6 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
|
||||
return getFlightConfigurationID();
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the listener connection to the rocket and listeners of this object.
|
||||
* This configuration may not be used after a call to this method!
|
||||
*/
|
||||
public void release() {
|
||||
}
|
||||
|
||||
//////////////// Listeners ////////////////
|
||||
|
||||
@Override
|
||||
@ -295,7 +288,7 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
|
||||
updateMotors();
|
||||
}
|
||||
|
||||
public void updateStages() {
|
||||
protected void updateStages() {
|
||||
if (this.rocket.getStageCount() == this.stages.size()) {
|
||||
// no changes needed
|
||||
return;
|
||||
@ -418,18 +411,6 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
|
||||
modID++;
|
||||
}
|
||||
|
||||
public Collection<MotorConfiguration> getAllMotors() {
|
||||
return motors.values();
|
||||
}
|
||||
|
||||
public int getMotorCount() {
|
||||
return getAllMotorCount();
|
||||
}
|
||||
|
||||
public int getAllMotorCount(){
|
||||
return motors.size();
|
||||
}
|
||||
|
||||
public Set<MotorInstanceId> getMotorIDs() {
|
||||
return motors.keySet();
|
||||
}
|
||||
@ -443,29 +424,21 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
|
||||
}
|
||||
|
||||
public Collection<MotorConfiguration> getActiveMotors() {
|
||||
List<MotorConfiguration> activeList = new ArrayList<MotorConfiguration>();
|
||||
for( MotorConfiguration inst : this.motors.values() ){
|
||||
if( inst.isActive() ){
|
||||
activeList.add( inst );
|
||||
}
|
||||
}
|
||||
|
||||
return activeList;
|
||||
return motors.values();
|
||||
}
|
||||
|
||||
public void updateMotors() {
|
||||
protected void updateMotors() {
|
||||
this.motors.clear();
|
||||
|
||||
for ( RocketComponent compMount : getActiveComponents() ){
|
||||
if (( compMount instanceof MotorMount )&&( ((MotorMount)compMount).isMotorMount())){
|
||||
MotorMount mount = (MotorMount)compMount;
|
||||
MotorConfiguration sourceInstance = mount.getMotorInstance( fcid);
|
||||
if( sourceInstance.isEmpty()){
|
||||
MotorConfiguration sourceConfig = mount.getMotorInstance( fcid);
|
||||
if( sourceConfig.isEmpty()){
|
||||
continue;
|
||||
}
|
||||
|
||||
this.motors.put( sourceInstance.getID(), sourceInstance);
|
||||
|
||||
|
||||
this.motors.put( sourceConfig.getID(), sourceConfig);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -457,6 +457,11 @@ public class Rocket extends RocketComponent {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(){
|
||||
this.configSet.update();
|
||||
}
|
||||
|
||||
/**
|
||||
* Freezes the rocket structure from firing any events. This may be performed to
|
||||
* combine several actions on the structure into a single large action.
|
||||
|
@ -2102,7 +2102,7 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab
|
||||
"RocketComponent iterator");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public String toDebugName(){
|
||||
return this.getName()+"<"+this.getClass().getSimpleName()+">("+this.getID().substring(0,8)+")";
|
||||
}
|
||||
|
@ -105,7 +105,7 @@ public class BasicEventSimulationEngine implements SimulationEngine {
|
||||
if (!flightData.getWarningSet().isEmpty()) {
|
||||
log.info("Warnings at the end of simulation: " + flightData.getWarningSet());
|
||||
}
|
||||
simulationConfig.release();
|
||||
|
||||
return flightData;
|
||||
}
|
||||
|
||||
|
@ -1,12 +1,10 @@
|
||||
package net.sf.openrocket.rocketcomponent;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.EventObject;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import net.sf.openrocket.motor.Manufacturer;
|
||||
@ -15,56 +13,12 @@ import net.sf.openrocket.motor.MotorConfiguration;
|
||||
import net.sf.openrocket.motor.ThrustCurveMotor;
|
||||
import net.sf.openrocket.rocketcomponent.RocketComponent.Position;
|
||||
import net.sf.openrocket.util.Coordinate;
|
||||
import net.sf.openrocket.util.StateChangeListener;
|
||||
import net.sf.openrocket.util.MathUtil;
|
||||
import net.sf.openrocket.util.BaseTestCase.BaseTestCase;
|
||||
|
||||
public class ConfigurationTest extends BaseTestCase {
|
||||
|
||||
/**
|
||||
* Test change events and modIDs
|
||||
*/
|
||||
@Test
|
||||
public void testChangeEvent() {
|
||||
|
||||
/* Setup */
|
||||
Rocket r1 = makeEmptyRocket();
|
||||
FlightConfiguration config = r1.getDefaultConfiguration();
|
||||
|
||||
StateChangeListener listener1 = new StateChangeListener() {
|
||||
@Override
|
||||
public void stateChanged(EventObject e) {
|
||||
}
|
||||
};
|
||||
|
||||
StateChangeListener listener2 = new StateChangeListener() {
|
||||
@Override
|
||||
public void stateChanged(EventObject e) {
|
||||
}
|
||||
};
|
||||
|
||||
config.addChangeListener(listener1);
|
||||
config.addChangeListener(listener2);
|
||||
|
||||
/* Test */
|
||||
|
||||
// ModID should not change if nothing changed
|
||||
int origModID = config.getModID();
|
||||
int noChangeModID = config.getModID();
|
||||
assertTrue(origModID == noChangeModID);
|
||||
|
||||
|
||||
// After a change event, modID should change
|
||||
config.fireChangeEvent();
|
||||
int changeModID = config.getModID();
|
||||
assertTrue(origModID < changeModID);
|
||||
|
||||
/* Cleanup */
|
||||
config.removeChangeListener(listener1);
|
||||
config.removeChangeListener(listener2);
|
||||
config.release();
|
||||
|
||||
}
|
||||
public class FlightConfigurationTest extends BaseTestCase {
|
||||
|
||||
private final static double EPSILON = MathUtil.EPSILON*1E3;
|
||||
|
||||
/**
|
||||
* Empty rocket (no components) specific configuration tests
|
||||
@ -77,42 +31,90 @@ public class ConfigurationTest extends BaseTestCase {
|
||||
FlightConfiguration configClone = config.clone();
|
||||
|
||||
assertTrue(config.getRocket() == configClone.getRocket());
|
||||
|
||||
config.release();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test flight configuration ID methods
|
||||
*/
|
||||
@Test
|
||||
public void testGeneralMethods() {
|
||||
public void testCloneBasic() {
|
||||
Rocket rkt1 = makeTwoStageMotorRocket();
|
||||
FlightConfiguration config1 = rkt1.getDefaultConfiguration();
|
||||
|
||||
/* Setup */
|
||||
Rocket r1 = makeSingleStageTestRocket();
|
||||
FlightConfiguration config = r1.getDefaultConfiguration();
|
||||
// preconditions
|
||||
config1.setAllStages();
|
||||
int expectedStageCount = 2;
|
||||
int actualStageCount = config1.getActiveStageCount();
|
||||
assertThat("active stage count doesn't match", actualStageCount, equalTo(expectedStageCount));
|
||||
int expectedMotorCount = 2;
|
||||
int actualMotorCount = config1.getActiveMotors().size();
|
||||
assertThat("active motor count doesn't match", actualMotorCount, equalTo(expectedMotorCount));
|
||||
double expectedLength = 176.8698848;
|
||||
double actualLength = config1.getLength();
|
||||
assertEquals("source config length doesn't match: ", expectedLength, actualLength, EPSILON);
|
||||
double expectedReferenceLength = 2.5;
|
||||
double actualReferenceLength = config1.getReferenceLength();
|
||||
assertEquals("source config reference length doesn't match: ", expectedReferenceLength, actualReferenceLength, EPSILON);
|
||||
double expectedReferenceArea = 4.9087385212;
|
||||
double actualReferenceArea = config1.getReferenceArea();
|
||||
assertEquals("source config reference area doesn't match: ", expectedReferenceArea, actualReferenceArea, EPSILON);
|
||||
|
||||
// vvvv test target vvvv
|
||||
FlightConfiguration config2= config1.clone();
|
||||
// ^^^^ test target ^^^^
|
||||
|
||||
/* Test */
|
||||
// postconditions
|
||||
expectedStageCount = 2;
|
||||
actualStageCount = config2.getActiveStageCount();
|
||||
assertThat("active stage count doesn't match", actualStageCount, equalTo(expectedStageCount));
|
||||
expectedMotorCount = 2;
|
||||
actualMotorCount = config2.getActiveMotors().size();
|
||||
assertThat("active motor count doesn't match", actualMotorCount, equalTo(expectedMotorCount));
|
||||
actualLength = config2.getLength();
|
||||
assertEquals("source config length doesn't match: ", expectedLength, actualLength, EPSILON);
|
||||
actualReferenceLength = config2.getReferenceLength();
|
||||
assertEquals("source config reference length doesn't match: ", expectedReferenceLength, actualReferenceLength, EPSILON);
|
||||
actualReferenceArea = config2.getReferenceArea();
|
||||
assertEquals("source config reference area doesn't match: ", expectedReferenceArea, actualReferenceArea, EPSILON);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test flight configuration ID methods
|
||||
*/
|
||||
@Test
|
||||
public void testCloneIndependence() {
|
||||
Rocket rkt1 = makeTwoStageMotorRocket();
|
||||
FlightConfiguration config1 = rkt1.getDefaultConfiguration();
|
||||
int expectedStageCount;
|
||||
int actualStageCount;
|
||||
int expectedMotorCount;
|
||||
int actualMotorCount;
|
||||
|
||||
// general method tests
|
||||
FlightConfiguration configClone = config.clone(); // TODO validate clone worked
|
||||
// test that cloned configurations operate independently:
|
||||
// change #1, test clone #2 -- verify that cloned configurations change independent.
|
||||
config1.setAllStages();
|
||||
// vvvv test target vvvv
|
||||
FlightConfiguration config2 = config1.clone();
|
||||
// ^^^^ test target ^^^^
|
||||
config1.clearAllStages();
|
||||
|
||||
assertFalse(config.getRocket() == null);
|
||||
|
||||
// TODO rocket has no motors! assertTrue(config.hasMotors());
|
||||
// postcondition: config #1
|
||||
expectedStageCount = 0;
|
||||
actualStageCount = config1.getActiveStageCount();
|
||||
assertThat("active stage count doesn't match", actualStageCount, equalTo(expectedStageCount));
|
||||
expectedMotorCount = 0;
|
||||
actualMotorCount = config1.getActiveMotors().size();
|
||||
assertThat("active motor count doesn't match", actualMotorCount, equalTo(expectedMotorCount));
|
||||
|
||||
// rocket info tests
|
||||
double length = config.getLength();
|
||||
double refLength = config.getReferenceLength();
|
||||
double refArea = config.getReferenceArea();
|
||||
|
||||
// TODO validate that the values are correct
|
||||
//log.debug("ConfigurationTest, length: " + String.valueOf(length));
|
||||
//log.debug("ConfigurationTest, refLength: " + String.valueOf(refLength));
|
||||
//log.debug("ConfigurationTest, refArea: " + String.valueOf(refArea));
|
||||
|
||||
/* Cleanup */
|
||||
config.release();
|
||||
// postcondition: config #2
|
||||
expectedStageCount = 2;
|
||||
actualStageCount = config2.getActiveStageCount();
|
||||
assertThat("active stage count doesn't match", actualStageCount, equalTo(expectedStageCount));
|
||||
expectedMotorCount = 2;
|
||||
actualMotorCount = config2.getActiveMotors().size();
|
||||
assertThat("active motor count doesn't match", actualMotorCount, equalTo(expectedMotorCount));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -125,17 +127,10 @@ public class ConfigurationTest extends BaseTestCase {
|
||||
Rocket r1 = makeSingleStageTestRocket();
|
||||
FlightConfiguration config = r1.getDefaultConfiguration();
|
||||
|
||||
/* Test */
|
||||
|
||||
// test cloning of single stage rocket
|
||||
FlightConfiguration configClone = config.clone(); // TODO validate clone worked
|
||||
configClone.release();
|
||||
|
||||
// test explicitly setting only first stage active
|
||||
config.clearAllStages();
|
||||
config.setOnlyStage(0);
|
||||
|
||||
|
||||
//config.dumpConfig();
|
||||
//System.err.println("treedump: \n" + treedump);
|
||||
|
||||
@ -154,9 +149,6 @@ public class ConfigurationTest extends BaseTestCase {
|
||||
// test explicitly setting all stages active
|
||||
config.setAllStages();
|
||||
|
||||
// Cleanup
|
||||
config.release();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -169,10 +161,6 @@ public class ConfigurationTest extends BaseTestCase {
|
||||
Rocket r1 = makeTwoStageTestRocket();
|
||||
FlightConfiguration config = r1.getDefaultConfiguration();
|
||||
|
||||
// test cloning of two stage rocket
|
||||
FlightConfiguration configClone = config.clone(); // TODO validate clone worked
|
||||
configClone.release();
|
||||
|
||||
int expectedStageCount;
|
||||
int stageCount;
|
||||
|
||||
@ -218,9 +206,6 @@ public class ConfigurationTest extends BaseTestCase {
|
||||
config.toggleStage(0);
|
||||
assertThat(" toggle stage #0: ", config.isStageActive(0), equalTo(false));
|
||||
|
||||
// Cleanup
|
||||
config.release();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -237,93 +222,29 @@ public class ConfigurationTest extends BaseTestCase {
|
||||
config.clearAllStages();
|
||||
int expectedMotorCount = 0;
|
||||
int actualMotorCount = config.getActiveMotors().size();
|
||||
assertThat("motor count doesn't match", actualMotorCount, equalTo(expectedMotorCount));
|
||||
assertThat("active motor count doesn't match", actualMotorCount, equalTo(expectedMotorCount));
|
||||
|
||||
config.setOnlyStage(0);
|
||||
expectedMotorCount = 1;
|
||||
actualMotorCount = config.getActiveMotors().size();
|
||||
assertThat("motor count doesn't match: ", actualMotorCount, equalTo(expectedMotorCount));
|
||||
assertThat("active motor count doesn't match: ", actualMotorCount, equalTo(expectedMotorCount));
|
||||
|
||||
config.setOnlyStage(1);
|
||||
expectedMotorCount = 2;
|
||||
expectedMotorCount = 1;
|
||||
actualMotorCount = config.getActiveMotors().size();
|
||||
assertThat("motor count doesn't match: ", actualMotorCount, equalTo(expectedMotorCount));
|
||||
assertThat("active motor count doesn't match: ", actualMotorCount, equalTo(expectedMotorCount));
|
||||
|
||||
config.setAllStages();
|
||||
expectedMotorCount = 3;
|
||||
// {
|
||||
// System.err.println("Booster Stage only: config set detail: "+rkt.getConfigSet().toDebug());
|
||||
// System.err.println("Booster Stage only: config stage detail: "+config.toStageListDetail());
|
||||
// System.err.println("Booster Stage only: config motor detail: "+config.toMotorDetail());
|
||||
// config.enableDebugging();
|
||||
// config.updateMotors();
|
||||
// config.getActiveMotors();
|
||||
// }
|
||||
expectedMotorCount = 2;
|
||||
actualMotorCount = config.getActiveMotors().size();
|
||||
assertThat("motor count doesn't match: ", actualMotorCount, equalTo(expectedMotorCount));
|
||||
|
||||
|
||||
assertThat("active motor count doesn't match: ", actualMotorCount, equalTo(expectedMotorCount));
|
||||
}
|
||||
|
||||
///////////////////// Helper Methods ////////////////////////////
|
||||
//
|
||||
// public void validateStages(Configuration config, int expectedStageCount, BitSet activeStageFlags) {
|
||||
//
|
||||
// // test that getStageCount() returns correct value
|
||||
// int stageCount = config.getStageCount();
|
||||
// assertTrue(stageCount == expectedStageCount);
|
||||
//
|
||||
// // test that getActiveStageCount() and getActiveStages() returns correct values
|
||||
// int expectedActiveStageCount = 0;
|
||||
// for (int i = 0; i < expectedStageCount; i++) {
|
||||
// if (activeStageFlags.get(i)) {
|
||||
// expectedActiveStageCount++;
|
||||
// }
|
||||
// }
|
||||
// assertTrue(config.getActiveStageCount() == expectedActiveStageCount);
|
||||
//
|
||||
// assertTrue("this test is not yet written.", false);
|
||||
// // int[] stages = config.getActiveStages();
|
||||
// //
|
||||
// // assertTrue(stages.length == expectedActiveStageCount);
|
||||
// //
|
||||
// // // test if isHead() detects first stage being active or inactive
|
||||
// // if (activeStageFlags.get(0)) {
|
||||
// // assertTrue(config.isHead());
|
||||
// // } else {
|
||||
// // assertFalse(config.isHead());
|
||||
// // }
|
||||
// //
|
||||
// // // test if isStageActive() detects stage x being active or inactive
|
||||
// // for (int i = 0; i < expectedStageCount; i++) {
|
||||
// // if (activeStageFlags.get(i)) {
|
||||
// // assertTrue(config.isStageActive(i));
|
||||
// // } else {
|
||||
// // assertFalse(config.isStageActive(i));
|
||||
// // }
|
||||
// // }
|
||||
// //
|
||||
// // // test boundary conditions
|
||||
// //
|
||||
// // // stage -1 should not exist, and isStageActive() should throw exception
|
||||
// // boolean IndexOutOfBoundsExceptionFlag = false;
|
||||
// // try {
|
||||
// // assertFalse(config.isStageActive(-1));
|
||||
// // } catch (IndexOutOfBoundsException e) {
|
||||
// // IndexOutOfBoundsExceptionFlag = true;
|
||||
// // }
|
||||
// // assertTrue(IndexOutOfBoundsExceptionFlag);
|
||||
// //
|
||||
// // // n+1 stage should not exist, isStageActive() should return false
|
||||
// // // TODO: isStageActive(stageCount + 1) really should throw IndexOutOfBoundsException
|
||||
// // assertFalse(config.isStageActive(stageCount + 1));
|
||||
//
|
||||
// }
|
||||
|
||||
//////////////////// Test Rocket Creation Methods /////////////////////////
|
||||
|
||||
public static Rocket makeEmptyRocket() {
|
||||
Rocket rocket = new Rocket();
|
||||
rocket.enableEvents();
|
||||
return rocket;
|
||||
}
|
||||
|
||||
@ -464,24 +385,7 @@ public class ConfigurationTest extends BaseTestCase {
|
||||
expectedConfigurationCount = 1;
|
||||
assertThat(" configuration list contains : ", rocket.getConfigSet().size(), equalTo(expectedConfigurationCount));
|
||||
|
||||
//FlightConfigurationID fcid = config.getFlightConfigurationID();
|
||||
// Motor m = Application.getMotorSetDatabase().findMotors(null, null, "L540", Double.NaN, Double.NaN).get(0);
|
||||
// MotorInstance inst = m.getNewInstance();
|
||||
// inner.setMotorInstance( fcid, inst);
|
||||
// inner.setMotorOverhang(0.02);
|
||||
//
|
||||
// //inner.setMotorMount(true);
|
||||
// assertThat(" configuration updates stage Count correctly: ", inner.hasMotor(), equalTo(true));
|
||||
//
|
||||
// final int expectedMotorCount = 1;
|
||||
// assertThat(" configuration updates correctly: ", inner.getMotorCount(), equalTo(expectedMotorCount));
|
||||
//
|
||||
// // Flight configuration
|
||||
// //FlightConfigurationID id = rocket.newFlightConfigurationID();
|
||||
//
|
||||
//
|
||||
// // tube3.setIgnitionEvent(MotorMount.IgnitionEvent.NEVER);
|
||||
|
||||
rocket.enableEvents();
|
||||
return rocket;
|
||||
}
|
||||
|
||||
@ -538,9 +442,10 @@ public class ConfigurationTest extends BaseTestCase {
|
||||
// FlightConfiguration newConfig = new FlightConfiguration(rocket,null);
|
||||
// rocket.setFlightConfiguration( newConfig.getId(), newConfig);
|
||||
|
||||
rocket.enableEvents();
|
||||
return rocket;
|
||||
}
|
||||
|
||||
|
||||
public static Rocket makeTwoStageMotorRocket() {
|
||||
Rocket rocket = makeTwoStageTestRocket();
|
||||
FlightConfigurationId fcid = rocket.getDefaultConfiguration().getId();
|
||||
@ -580,7 +485,9 @@ public class ConfigurationTest extends BaseTestCase {
|
||||
boosterMount.setMotorInstance(fcid, new MotorConfiguration(boosterMotor));
|
||||
boosterMount.setClusterConfiguration( ClusterConfiguration.CONFIGURATIONS[1]); // double-mount
|
||||
}
|
||||
rocket.getConfigSet().update();
|
||||
rocket.enableEvents();
|
||||
return rocket;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -430,7 +430,6 @@ public class DesignReport {
|
||||
c.setBorder(PdfPCell.LEFT);
|
||||
c.setBorderWidthTop(0f);
|
||||
parent.addCell(c);
|
||||
config.release();
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user