From c3e87bb1383b9d7393a32331f5dc8815e2ec0cc3 Mon Sep 17 00:00:00 2001 From: JoePfeiffer Date: Sat, 18 Mar 2023 10:49:26 -0600 Subject: [PATCH] Add unit test for railbutton drag when velocity is 0 --- .../aerodynamics/BarrowmanCalculatorTest.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/core/test/net/sf/openrocket/aerodynamics/BarrowmanCalculatorTest.java b/core/test/net/sf/openrocket/aerodynamics/BarrowmanCalculatorTest.java index 09b2ba1bc..a3ec7c07b 100644 --- a/core/test/net/sf/openrocket/aerodynamics/BarrowmanCalculatorTest.java +++ b/core/test/net/sf/openrocket/aerodynamics/BarrowmanCalculatorTest.java @@ -26,6 +26,7 @@ import net.sf.openrocket.rocketcomponent.Transition; import net.sf.openrocket.rocketcomponent.TrapezoidFinSet; import net.sf.openrocket.startup.Application; import net.sf.openrocket.util.Coordinate; +import net.sf.openrocket.util.MathUtil; import net.sf.openrocket.util.TestRockets; public class BarrowmanCalculatorTest { @@ -499,7 +500,8 @@ public class BarrowmanCalculatorTest { } /** - * Tests railbutton drag. Really is testing instancing more than actual drag calculations + * Tests railbutton drag. Really is testing instancing more than actual drag calculations, and making + * sure we don't divide by 0 when not moving */ @Test public void testRailButtonDrag() { @@ -519,6 +521,8 @@ public class BarrowmanCalculatorTest { final FlightConfiguration config = rocket.getSelectedConfiguration(); final FlightConditions conditions = new FlightConditions(config); final BarrowmanCalculator calc = new BarrowmanCalculator(); + + // part 1: instancing // Put two individual railbuttons and get their CD final RailButton button1 = new RailButton(); @@ -548,7 +552,16 @@ public class BarrowmanCalculatorTest { final double pairCD = pairForces.getCD(); assertEquals("two individual railbuttons should have same CD as a pair", individualCD, pairCD, EPSILON); + + // part 2: test at Mach 0 + conditions.setMach(MathUtil.EPSILON); + final AerodynamicForces epsForces = calc.getAerodynamicForces(config, conditions, warnings); + final double epsCD = epsForces.getCD(); + + conditions.setMach(0); + final AerodynamicForces zeroForces = calc.getAerodynamicForces(config, conditions, warnings); + final double zeroCD = zeroForces.getCD(); + assertEquals("drag at mach 0 should equal drag at mach MathUtil.EPSILON", epsCD, zeroCD, EPSILON); } - }