From 0c47f2eba3bb6982a75b6217124ea9794914b6c3 Mon Sep 17 00:00:00 2001 From: Daniel_M_Williams Date: Sun, 3 May 2020 13:10:10 -0400 Subject: [PATCH] [fix] adjusted RocketTest unit tests to match auto-radius across stages. --- .../net/sf/openrocket/util/TestRockets.java | 12 +- .../rocketcomponent/RocketTest.java | 103 ++++++++++++++---- 2 files changed, 89 insertions(+), 26 deletions(-) diff --git a/core/src/net/sf/openrocket/util/TestRockets.java b/core/src/net/sf/openrocket/util/TestRockets.java index 9acc221a1..f03845045 100644 --- a/core/src/net/sf/openrocket/util/TestRockets.java +++ b/core/src/net/sf/openrocket/util/TestRockets.java @@ -551,7 +551,7 @@ public class TestRockets { } } - // This is an extra stage tacked onto the end of an Estes Alpha III + // 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 @@ -586,7 +586,7 @@ public class TestRockets { double finRootChord = .05; double finTipChord = .03; double finSweep = 0.02; - double finHeight = 0.05; + double finHeight = 0.03; FinSet finset = new TrapezoidFinSet(finCount, finRootChord, finTipChord, finSweep, finHeight); finset.setName("Booster Fins"); finset.setThickness( 0.0032); @@ -611,6 +611,14 @@ public class TestRockets { } boosterBody.addChild(boosterMMT); } + + // Tail Cone + Transition boosterTail = new Transition(); + boosterTail.setForeRadius(0.012); + boosterTail.setAftRadius(0.01); + boosterTail.setLength(0.005); + boosterTail.setName("Booster Tail Cone"); + boosterStage.addChild( boosterTail); } rocket.setSelectedConfiguration( TEST_FCID_1 ); diff --git a/core/test/net/sf/openrocket/rocketcomponent/RocketTest.java b/core/test/net/sf/openrocket/rocketcomponent/RocketTest.java index 7e0a631f5..484ad05ac 100644 --- a/core/test/net/sf/openrocket/rocketcomponent/RocketTest.java +++ b/core/test/net/sf/openrocket/rocketcomponent/RocketTest.java @@ -5,6 +5,7 @@ import static org.hamcrest.CoreMatchers.not; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThat; +import net.sf.openrocket.rocketcomponent.position.AxialMethod; import org.junit.Test; import net.sf.openrocket.rocketcomponent.position.AngleMethod; @@ -55,29 +56,6 @@ public class RocketTest extends BaseTestCase { //ComponentCompare.assertDeepEquality(r1, r2); } - @Test - public void testAutoAlphaIII() { - Rocket rocket = TestRockets.makeEstesAlphaIII(); - - AxialStage stage = (AxialStage) rocket.getChild(0); - - BodyTube body = (BodyTube)stage.getChild(1); - final double expRadius = 0.012; - double actRadius = body.getOuterRadius(); - assertEquals(" radius match: ", expRadius, actRadius, EPSILON); - - body.setOuterRadiusAutomatic(true); - actRadius = body.getOuterRadius(); - assertEquals(" radius match: ", expRadius, actRadius, EPSILON); - - final Transition transition = new Transition(); - stage.addChild(transition); - - transition.setForeRadiusAutomatic(true); - actRadius = transition.getForeRadius(); - assertEquals(" trailing transition match: ", expRadius, actRadius, EPSILON); - } - @Test public void testEstesAlphaIII(){ Rocket rocket = TestRockets.makeEstesAlphaIII(); @@ -179,7 +157,84 @@ public class RocketTest extends BaseTestCase { assertThat(locPost.x, equalTo(0.0)); } } - + + @Test + public void testAutoSizePreviousComponent() { + Rocket rocket = TestRockets.makeBeta(); + + final AxialStage sustainer = (AxialStage) rocket.getChild(0); + final AxialStage booster = (AxialStage) rocket.getChild(1); + final double expRadius = 0.012; + + { // test auto-radius within a stage: nose -> body tube + final NoseCone nose = (NoseCone) sustainer.getChild(0); + assertEquals(" radius match: ", expRadius, nose.getAftRadius(), EPSILON); + final BodyTube body = (BodyTube) sustainer.getChild(1); + assertEquals(" radius match: ", expRadius, body.getOuterRadius(), EPSILON); + + body.setOuterRadiusAutomatic(true); + assertEquals(" radius match: ", expRadius, body.getOuterRadius(), EPSILON); + } + { // test auto-radius within a stage: body tube -> trailing transition + final BodyTube body = (BodyTube) booster.getChild(0); + assertEquals(" radius match: ", expRadius, body.getOuterRadius(), EPSILON); + final Transition tailCone = (Transition)booster.getChild(1); + assertEquals(" radius match: ", expRadius, tailCone.getForeRadius(), EPSILON); + + tailCone.setForeRadiusAutomatic(true); + assertEquals(" trailing transition match: ", expRadius, tailCone.getForeRadius(), EPSILON); + } + { // test auto-radius across stages: sustainer body -> booster body + BodyTube sustainerBody = (BodyTube) sustainer.getChild(1); + assertEquals(" radius match: ", expRadius, sustainerBody.getOuterRadius(), EPSILON); + BodyTube boosterBody = (BodyTube) booster.getChild(0); + assertEquals(" radius match: ", expRadius, boosterBody.getOuterRadius(), EPSILON); + + boosterBody.setOuterRadiusAutomatic(true); + assertEquals(" radius match: ", expRadius, boosterBody.getOuterRadius(), EPSILON); + } + } + + @Test + public void testAutoSizeNextComponent() { + Rocket rocket = TestRockets.makeBeta(); + + final AxialStage sustainer = (AxialStage) rocket.getChild(0); + final AxialStage booster = (AxialStage) rocket.getChild(1); + final double expRadius = 0.012; + + { // test auto-radius within a stage: nose <- body tube + System.err.println("## Testing auto-radius: sustainer: nose <- body"); + final NoseCone nose = (NoseCone) sustainer.getChild(0); + assertEquals(" radius match: ", expRadius, nose.getAftRadius(), EPSILON); + final BodyTube body = (BodyTube) sustainer.getChild(1); + assertEquals(" radius match: ", expRadius, body.getOuterRadius(), EPSILON); + + nose.setAftRadiusAutomatic(true); + assertEquals(" radius match: ", expRadius, nose.getAftRadius(), EPSILON); + } + { // test auto-radius within a stage: body tube <- trailing transition + System.err.println("## Testing auto-radius: booster: body <- tail"); + final BodyTube boosterBody = (BodyTube) booster.getChild(0); + assertEquals(" radius match: ", expRadius, boosterBody.getOuterRadius(), EPSILON); + final Transition tailCone = (Transition)booster.getChild(1); + assertEquals(" radius match: ", expRadius, tailCone.getForeRadius(), EPSILON); + + boosterBody.setOuterRadiusAutomatic(true); + assertEquals(" trailing transition match: ", expRadius, boosterBody.getOuterRadius(), EPSILON); + } + { // test auto-radius across stages: sustainer body <- booster body + System.err.println("## Testing auto-radius: booster:body -> sustainer:body"); + BodyTube sustainerBody = (BodyTube) sustainer.getChild(1); + assertEquals(" radius match: ", expRadius, sustainerBody.getOuterRadius(), EPSILON); + BodyTube boosterBody = (BodyTube) booster.getChild(0); + assertEquals(" radius match: ", expRadius, boosterBody.getOuterRadius(), EPSILON); + + sustainerBody.setOuterRadiusAutomatic(true); + assertEquals(" radius match: ", expRadius, sustainerBody.getOuterRadius(), EPSILON); + } + } + @Test public void testBeta(){ Rocket rocket = TestRockets.makeBeta();