From b84de6857542ab7f09c1b04cc878e7a9d20cf205 Mon Sep 17 00:00:00 2001 From: Daniel_M_Williams Date: Sun, 24 Dec 2017 14:45:50 -0500 Subject: [PATCH] [fix][test] Fixed RocketTest, FlightConfigurationTest --- .../rocketcomponent/FlightConfiguration.java | 4 - .../net/sf/openrocket/util/TestRockets.java | 307 ++++-------------- .../FlightConfigurationTest.java | 49 ++- .../rocketcomponent/RocketTest.java | 40 ++- 4 files changed, 138 insertions(+), 262 deletions(-) diff --git a/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java b/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java index 34d40d313..5807e8f34 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java +++ b/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java @@ -399,16 +399,12 @@ public class FlightConfiguration implements FlightConfigurableParameter> generating bounds for configuration: %s (%d)(%s)", getName(), this.instanceNumber, getId() )); - BoundingBox bounds = new BoundingBox(); for (RocketComponent component : this.getActiveComponents()) { BoundingBox componentBounds = new BoundingBox( component.getComponentBounds() ); bounds.compare( componentBounds ); - -// System.err.println(String.format(" [%s] %s >> %s", component.getName(), componentBounds.toString(), bounds.toString() )); } cachedLength = bounds.span().x; diff --git a/core/src/net/sf/openrocket/util/TestRockets.java b/core/src/net/sf/openrocket/util/TestRockets.java index b122ba421..5e7731e41 100644 --- a/core/src/net/sf/openrocket/util/TestRockets.java +++ b/core/src/net/sf/openrocket/util/TestRockets.java @@ -27,6 +27,7 @@ import net.sf.openrocket.rocketcomponent.DeploymentConfiguration.DeployEvent; import net.sf.openrocket.rocketcomponent.EngineBlock; import net.sf.openrocket.rocketcomponent.ExternalComponent; import net.sf.openrocket.rocketcomponent.ExternalComponent.Finish; +import net.sf.openrocket.rocketcomponent.FinSet; import net.sf.openrocket.rocketcomponent.FinSet.CrossSection; import net.sf.openrocket.rocketcomponent.FlightConfiguration; import net.sf.openrocket.rocketcomponent.FlightConfigurationId; @@ -400,11 +401,14 @@ public class TestRockets { return values[rnd.nextInt(values.length)]; } - public final static String ESTES_ALPHA_III_FCID_1="test_config #1: A8-0"; - public final static String ESTES_ALPHA_III_FCID_2="test_config #2: B4-3"; - public final static String ESTES_ALPHA_III_FCID_3="test_config #3: C6-3"; - public final static String ESTES_ALPHA_III_FCID_4="test_config #4: C6-5"; - public final static String ESTES_ALPHA_III_FCID_5="test_config #5: C6-7"; + final static FlightConfigurationId ESTES_ALPHA_III_FCID[] = { + null, // treat the array as 1-indexed. + new FlightConfigurationId("test_config #1: A8-0"), + new FlightConfigurationId("test_config #2: B4-3"), + new FlightConfigurationId("test_config #3: C6-3"), + new FlightConfigurationId("test_config #4: C6-5"), + new FlightConfigurationId("test_config #5: C6-7"), + }; // This is a Estes Alpha III // http://www.rocketreviews.com/alpha-iii---estes-221256.html @@ -413,11 +417,11 @@ public class TestRockets { public static final Rocket makeEstesAlphaIII(){ Rocket rocket = new Rocket(); FlightConfigurationId fcid[] = new FlightConfigurationId[5]; - fcid[0] = rocket.createFlightConfiguration( new FlightConfigurationId( ESTES_ALPHA_III_FCID_1 )); - fcid[1] = rocket.createFlightConfiguration( new FlightConfigurationId( ESTES_ALPHA_III_FCID_2 )); - fcid[2] = rocket.createFlightConfiguration( new FlightConfigurationId( ESTES_ALPHA_III_FCID_3 )); - fcid[3] = rocket.createFlightConfiguration( new FlightConfigurationId( ESTES_ALPHA_III_FCID_4 )); - fcid[4] = rocket.createFlightConfiguration( new FlightConfigurationId( ESTES_ALPHA_III_FCID_5 )); + fcid[0] = rocket.createFlightConfiguration( ESTES_ALPHA_III_FCID[1] ); + fcid[1] = rocket.createFlightConfiguration( ESTES_ALPHA_III_FCID[2] ); + fcid[2] = rocket.createFlightConfiguration( ESTES_ALPHA_III_FCID[3] ); + fcid[3] = rocket.createFlightConfiguration( ESTES_ALPHA_III_FCID[4] ); + fcid[4] = rocket.createFlightConfiguration( ESTES_ALPHA_III_FCID[5] ); rocket.setName("Estes Alpha III / Code Verification Rocket"); @@ -555,250 +559,73 @@ public class TestRockets { // This is an extra stage tacked onto the end of an Estes Alpha III // http://www.rocketreviews.com/alpha-iii---estes-221256.html - // This function is used for unit, integration tests, DO NOT CHANGE (without updating tests). + // + // This function is used for unit, integration tests, DO NOT CHANGE WITHOUT UPDATING TESTS public static final Rocket makeBeta(){ - Rocket rocket = new Rocket(); + Rocket rocket = makeEstesAlphaIII(); rocket.setName("Kit-bash Beta"); - AxialStage sustainerStage = new AxialStage(); - sustainerStage.setName("Sustainer Stage"); - rocket.addChild(sustainerStage); - FlightConfigurationId fcid[] = new FlightConfigurationId[5]; - for( int i=0; i< fcid.length; ++i){ - fcid[i] = new FlightConfigurationId(); - rocket.createFlightConfiguration(fcid[i]); - } - - double noseconeLength = 0.07; - double noseconeRadius = 0.012; - NoseCone nosecone = new NoseCone(Transition.Shape.OGIVE, noseconeLength, noseconeRadius); - nosecone.setAftShoulderLength(0.025); - nosecone.setAftShoulderRadius(0.012); - nosecone.setName("Nose Cone"); - sustainerStage.addChild(nosecone); - double bodytubeLength = 0.20; - double bodytubeRadius = 0.012; - double bodyTubeThickness = 0.0003; - BodyTube bodytube = new BodyTube(bodytubeLength, bodytubeRadius, bodyTubeThickness); - bodytube.setName("Body Tube"); - sustainerStage.addChild(bodytube); + AxialStage sustainerStage = (AxialStage)rocket.getChild(0); + sustainerStage.setName( "Sustainer Stage"); + BodyTube sustainerBody = (BodyTube)sustainerStage.getChild(1); + final double sustainerRadius = sustainerBody.getAftRadius(); + final double sustainerThickness = sustainerBody.getThickness(); - TrapezoidFinSet finset; + AxialStage boosterStage = new AxialStage(); + boosterStage.setName("Booster Stage"); + rocket.addChild( boosterStage ); { - int finCount = 3; - double finRootChord = .05; - double finTipChord = .03; - double finSweep = 0.02; - double finHeight = 0.05; - finset = new TrapezoidFinSet(finCount, finRootChord, finTipChord, finSweep, finHeight); - finset.setThickness( 0.0032); - finset.setRelativePosition(Position.BOTTOM); - finset.setName("3 Fin Set"); - bodytube.addChild(finset); - - LaunchLug lug = new LaunchLug(); - lug.setName("Launch Lugs"); - lug.setRelativePosition(Position.TOP); - lug.setAxialOffset(0.111); - lug.setLength(0.050); - lug.setOuterRadius(0.0022); - lug.setInnerRadius(0.0020); - bodytube.addChild(lug); - - InnerTube inner = new InnerTube(); - inner.setRelativePosition(Position.TOP); - inner.setAxialOffset(0.133); - inner.setLength(0.07); - inner.setOuterRadius(0.009); - inner.setThickness(0.0003); - inner.setMotorMount(true); - inner.setName("Motor Mount Tube"); - bodytube.addChild(inner); - + BodyTube boosterBody = new BodyTube(0.06, sustainerRadius, sustainerThickness); + boosterBody.setName("Booster Body"); + boosterStage.addChild( boosterBody); { - // MotorBlock - EngineBlock thrustBlock= new EngineBlock(); - thrustBlock.setRelativePosition(Position.TOP); - thrustBlock.setAxialOffset(0.0); - thrustBlock.setLength(0.005); - thrustBlock.setOuterRadius(0.009); - thrustBlock.setThickness(0.0008); - thrustBlock.setName("Engine Block"); - inner.addChild(thrustBlock); - inner.setMotorMount( true); + TubeCoupler coupler = new TubeCoupler(); + coupler.setName("Coupler"); + coupler.setOuterRadiusAutomatic(true); + coupler.setThickness( sustainerThickness ); + coupler.setLength(0.03); + coupler.setRelativePosition(Position.TOP); + coupler.setAxialOffset(-0.015); + boosterBody.addChild(coupler); - { - MotorConfiguration motorConfig = new MotorConfiguration(inner,fcid[0]); - Motor mtr = TestRockets.generateMotor_A8_18mm(); - motorConfig.setEjectionDelay(0.0); - motorConfig.setMotor( mtr); - inner.setMotorConfig( motorConfig, fcid[0]); - } - { - MotorConfiguration motorConfig = new MotorConfiguration(inner,fcid[1]); - Motor mtr = TestRockets.generateMotor_B4_18mm(); - motorConfig.setEjectionDelay(3.0); - motorConfig.setMotor( mtr); - inner.setMotorConfig( motorConfig, fcid[1]); - } - { - MotorConfiguration motorConfig = new MotorConfiguration(inner,fcid[2]); - Motor mtr = TestRockets.generateMotor_C6_18mm(); - motorConfig.setEjectionDelay(3.0); - motorConfig.setMotor( mtr); - inner.setMotorConfig( motorConfig, fcid[2]); - } - { - MotorConfiguration motorConfig = new MotorConfiguration(inner,fcid[3]); - Motor mtr = TestRockets.generateMotor_C6_18mm(); - motorConfig.setEjectionDelay(5.0); - motorConfig.setMotor( mtr); - inner.setMotorConfig( motorConfig, fcid[3]); - } - { - MotorConfiguration motorConfig = new MotorConfiguration(inner,fcid[4]); - Motor mtr = TestRockets.generateMotor_C6_18mm(); - motorConfig.setEjectionDelay(7.0); - motorConfig.setMotor( mtr); - inner.setMotorConfig( motorConfig, fcid[4]); - } - } - - // parachute - Parachute chute = new Parachute(); - chute.setRelativePosition(Position.TOP); - chute.setName("Parachute"); - chute.setAxialOffset(0.028); - chute.setOverrideMass(0.002); - chute.setMassOverridden(true); - bodytube.addChild(chute); - - // bulkhead x2 - CenteringRing centerings = new CenteringRing(); - centerings.setName("Centering Rings"); - centerings.setRelativePosition(Position.TOP); - centerings.setAxialOffset(0.14); - centerings.setLength(0.006); - centerings.setInstanceCount(2); - centerings.setInstanceSeparation(0.035); - bodytube.addChild(centerings); - } - - Material material = Application.getPreferences().getDefaultComponentMaterial(null, Material.Type.BULK); - nosecone.setMaterial(material); - bodytube.setMaterial(material); - finset.setMaterial(material); - - { - AxialStage boosterStage = new AxialStage(); - boosterStage.setName("Booster"); - - BodyTube boosterTube = new BodyTube(0.06, bodytubeRadius, bodyTubeThickness); - boosterStage.addChild(boosterTube); - - TubeCoupler coupler = new TubeCoupler(); - coupler.setName("Interstage"); - coupler.setOuterRadiusAutomatic(true); - coupler.setThickness( bodyTubeThickness); - coupler.setLength(0.03); - coupler.setRelativePosition(Position.TOP); - coupler.setAxialOffset(-1.5); - boosterTube.addChild(coupler); - - int finCount = 3; - double finRootChord = .05; - double finTipChord = .03; - double finSweep = 0.02; - double finHeight = 0.05; - finset = new TrapezoidFinSet(finCount, finRootChord, finTipChord, finSweep, finHeight); - finset.setThickness( 0.0032); - finset.setRelativePosition(Position.BOTTOM); - finset.setAxialOffset(1); - finset.setName("Booster Fins"); - boosterTube.addChild(finset); - - // Motor mount - InnerTube boosterMMT = new InnerTube(); - boosterMMT.setName("Booster MMT"); - boosterMMT.setAxialOffset(0.005); - boosterMMT.setRelativePosition(Position.BOTTOM); - boosterMMT.setOuterRadius(0.019 / 2); - boosterMMT.setInnerRadius(0.018 / 2); - boosterMMT.setLength(0.075); - boosterTube.addChild(boosterMMT); - - rocket.addChild(boosterStage); + int finCount = 3; + double finRootChord = .05; + double finTipChord = .03; + double finSweep = 0.02; + double finHeight = 0.05; + FinSet finset = new TrapezoidFinSet(finCount, finRootChord, finTipChord, finSweep, finHeight); + finset.setName("Booster Fins"); + finset.setThickness( 0.0032); + finset.setRelativePosition(Position.BOTTOM); + finset.setAxialOffset(0.); + boosterBody.addChild(finset); - boosterMMT.setMotorMount(true); - { - MotorConfiguration motorConfig= new MotorConfiguration(boosterMMT,fcid[0]); - Motor mtr = generateMotor_D21_18mm(); - motorConfig.setMotor(mtr); - boosterMMT.setMotorConfig( motorConfig, fcid[0]); + // Motor mount + InnerTube boosterMMT = new InnerTube(); + boosterMMT.setName("Booster MMT"); + boosterMMT.setAxialOffset(0.005); + boosterMMT.setRelativePosition(Position.BOTTOM); + boosterMMT.setOuterRadius(0.019 / 2); + boosterMMT.setInnerRadius(0.018 / 2); + boosterMMT.setLength(0.05); + boosterMMT.setMotorMount(true); + { + MotorConfiguration motorConfig= new MotorConfiguration(boosterMMT, ESTES_ALPHA_III_FCID[1] ); + Motor mtr = generateMotor_D21_18mm(); + motorConfig.setMotor(mtr); + boosterMMT.setMotorConfig( motorConfig, ESTES_ALPHA_III_FCID[1]); + } + boosterBody.addChild(boosterMMT); } - } + + rocket.setSelectedConfiguration( ESTES_ALPHA_III_FCID[1] ); rocket.getSelectedConfiguration().setAllStages(); - rocket.setSelectedConfiguration( fcid[0] ); rocket.enableEvents(); + return rocket; } - - public static Rocket makeSmallFlyable() { - double noseconeLength = 0.10, noseconeRadius = 0.01; - double bodytubeLength = 0.20, bodytubeRadius = 0.01, bodytubeThickness = 0.001; - - int finCount = 3; - @SuppressWarnings("unused") - double finRootChord = 0.04, finTipChord = 0.05, finSweep = 0.01, finThickness = 0.003, finHeight = 0.03; - - Rocket rocket; - AxialStage stage; - NoseCone nosecone; - BodyTube bodytube; - TrapezoidFinSet finset; - - rocket = new Rocket(); - stage = new AxialStage(); - stage.setName("Stage1"); - - nosecone = new NoseCone(Transition.Shape.ELLIPSOID, noseconeLength, noseconeRadius); - bodytube = new BodyTube(bodytubeLength, bodytubeRadius, bodytubeThickness); - - finset = new TrapezoidFinSet(finCount, finRootChord, finTipChord, finSweep, finHeight); - - // Stage construction - rocket.addChild(stage); - - // Component construction - stage.addChild(nosecone); - stage.addChild(bodytube); - - bodytube.addChild(finset); - - Material material = Application.getPreferences().getDefaultComponentMaterial(null, Material.Type.BULK); - nosecone.setMaterial(material); - bodytube.setMaterial(material); - finset.setMaterial(material); - - FlightConfiguration config = rocket.getSelectedConfiguration(); - FlightConfigurationId fcid = config.getFlightConfigurationID(); - - ThrustCurveMotor motor = getTestMotor(); - MotorConfiguration instance = new MotorConfiguration( bodytube, fcid ); - instance.setMotor( motor); - instance.setEjectionDelay(5); - - bodytube.setMotorConfig( instance, fcid); - bodytube.setMotorOverhang(0.005); - - config.setAllStages(); - rocket.enableEvents(); - return rocket; - } - - public static Rocket makeBigBlue() { Rocket rocket; AxialStage stage; @@ -1592,7 +1419,7 @@ public class TestRockets { public static OpenRocketDocument makeTestRocket_v107_withSimulationExtension(String script) { - Rocket rocket = makeSmallFlyable(); + Rocket rocket = makeEstesAlphaIII(); OpenRocketDocument document = OpenRocketDocumentFactory.createDocumentFromRocket(rocket); Simulation sim = new Simulation(rocket); ScriptingExtension ext = new ScriptingExtension(); diff --git a/core/test/net/sf/openrocket/rocketcomponent/FlightConfigurationTest.java b/core/test/net/sf/openrocket/rocketcomponent/FlightConfigurationTest.java index b7007a7cf..19e502124 100644 --- a/core/test/net/sf/openrocket/rocketcomponent/FlightConfigurationTest.java +++ b/core/test/net/sf/openrocket/rocketcomponent/FlightConfigurationTest.java @@ -20,7 +20,7 @@ public class FlightConfigurationTest extends BaseTestCase { */ @Test public void testEmptyRocket() { - Rocket r1 = TestRockets.makeSmallFlyable(); + Rocket r1 = TestRockets.makeEstesAlphaIII(); FlightConfiguration config = r1.getSelectedConfiguration(); FlightConfiguration configClone = config.clone(); @@ -28,17 +28,36 @@ public class FlightConfigurationTest extends BaseTestCase { assertTrue(config.getRocket() == configClone.getRocket()); } - /** - * Test flight configuration ID methods - */ + + @Test + public void testFlightConfigurationRocketLength() { + Rocket rocket = TestRockets.makeBeta(); + FlightConfiguration config = rocket.getEmptyConfiguration(); + rocket.setSelectedConfiguration( config.getId() ); + + config.setAllStages(); + + // preconditions + assertThat("active stage count doesn't match", config.getActiveStageCount(), equalTo(2)); + + final double expectedLength = 0.33; + final double calculatedLength = config.getLength(); + assertEquals("source config length doesn't match: ", expectedLength, calculatedLength, EPSILON); + + double expectedReferenceLength = 0.024; + assertEquals("source config reference length doesn't match: ", expectedReferenceLength, config.getReferenceLength(), EPSILON); + + double expectedReferenceArea = Math.pow(expectedReferenceLength/2,2)*Math.PI; + double actualReferenceArea = config.getReferenceArea(); + assertEquals("source config reference area doesn't match: ", expectedReferenceArea, actualReferenceArea, EPSILON); + } + + @Test public void testCloneBasic() { Rocket rkt1 = TestRockets.makeBeta(); FlightConfiguration config1 = rkt1.getSelectedConfiguration(); -// final String treedump = rkt1.toDebugTree(); -// System.err.println("treedump: \n" + treedump); - // preconditions config1.setAllStages(); int expectedStageCount = 2; @@ -48,15 +67,14 @@ public class FlightConfigurationTest extends BaseTestCase { int actualMotorCount = config1.getActiveMotors().size(); assertThat("active motor count doesn't match", actualMotorCount, equalTo(expectedMotorCount)); double expectedLength = 0.33; - double actualLength = config1.getLength(); - assertEquals("source config length doesn't match: ", expectedLength, actualLength, EPSILON); + assertEquals("source config length doesn't match: ", expectedLength, config1.getLength(), EPSILON); double expectedReferenceLength = 0.024; - double actualReferenceLength = config1.getReferenceLength(); - assertEquals("source config reference length doesn't match: ", expectedReferenceLength, actualReferenceLength, EPSILON); + assertEquals("source config reference length doesn't match: ", expectedReferenceLength, config1.getReferenceLength(), EPSILON); double expectedReferenceArea = Math.pow(expectedReferenceLength/2,2)*Math.PI; 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 ^^^^ @@ -68,12 +86,9 @@ public class FlightConfigurationTest extends BaseTestCase { 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); + assertEquals("source config length doesn't match: ", expectedLength, config2.getLength(), EPSILON); + assertEquals("source config reference length doesn't match: ", expectedReferenceLength, config2.getReferenceLength(), EPSILON); + assertEquals("source config reference area doesn't match: ", expectedReferenceArea, config2.getReferenceArea(), EPSILON); } diff --git a/core/test/net/sf/openrocket/rocketcomponent/RocketTest.java b/core/test/net/sf/openrocket/rocketcomponent/RocketTest.java index f65a3c234..e49fa5637 100644 --- a/core/test/net/sf/openrocket/rocketcomponent/RocketTest.java +++ b/core/test/net/sf/openrocket/rocketcomponent/RocketTest.java @@ -14,6 +14,8 @@ import net.sf.openrocket.util.BaseTestCase.BaseTestCase; public class RocketTest extends BaseTestCase { + final double EPSILON = MathUtil.EPSILON; + @Test public void testCopyIndependence() { Rocket rkt1 = TestRockets.makeEstesAlphaIII(); @@ -54,7 +56,6 @@ public class RocketTest extends BaseTestCase { @Test public void testEstesAlphaIII(){ - final double EPSILON = MathUtil.EPSILON; Rocket rocket = TestRockets.makeEstesAlphaIII(); // String treeDump = rocket.toDebugTree(); @@ -141,4 +142,41 @@ public class RocketTest extends BaseTestCase { } } + @Test + public void testBeta(){ + Rocket rocket = TestRockets.makeBeta(); + + AxialStage boosterStage= (AxialStage)rocket.getChild(1); + + Coordinate expLoc; + Coordinate actLoc; + Coordinate actLocs[]; + { + BodyTube body = (BodyTube)boosterStage.getChild(0); + Coordinate[] bodyLocs = body.getComponentLocations(); + expLoc = new Coordinate(0.27, 0, 0); + assertThat(body.getName()+" not positioned correctly: ", bodyLocs[0], equalTo(expLoc)); + + { + TubeCoupler coupler = (TubeCoupler)body.getChild(0); + actLocs = coupler.getComponentLocations(); + expLoc = new Coordinate(0.255, 0, 0); + assertThat(coupler.getName()+" not positioned correctly: ", actLocs[0], equalTo(expLoc) ); + + FinSet fins = (FinSet)body.getChild(1); + actLocs = fins.getComponentLocations(); + assertThat(fins.getName()+" have incorrect count: ", fins.getInstanceCount(), equalTo(3)); + { // fin #1 + expLoc = new Coordinate(0.28, 0.012, 0); + assertThat(fins.getName()+" not positioned correctly: ", actLocs[0], equalTo(expLoc)); + } + + InnerTube mmt = (InnerTube)body.getChild(2); + actLoc = mmt.getComponentLocations()[0]; + expLoc = new Coordinate(0.285, 0, 0); + assertThat(mmt.getName()+" not positioned correctly: ", actLoc, equalTo( expLoc )); + } + } + } + }