private static IEnumerable <TestCaseData> GetNegativeVelocityTestCases() { var random = new Random(21); AerodynamicsData aerodynamicsData = AerodynamicsDataTestFactory.CreateAerodynamicsData(); Angle angleOfAttack = random.NextAngle(); double liftCoefficient = random.NextDouble(); double density = random.NextDouble(); double invalidVelocity = -random.NextDouble(); yield return(new TestCaseData(new Action(() => AerodynamicsHelper.CalculateLift(aerodynamicsData, angleOfAttack, density, invalidVelocity))) .SetName("CalculateLift")); yield return(new TestCaseData(new Action(() => AerodynamicsHelper.CalculateDragWithEngineFailure(aerodynamicsData, liftCoefficient, density, invalidVelocity))) .SetName("CalculateDragWithEngineFailure")); yield return(new TestCaseData(new Action(() => AerodynamicsHelper.CalculateDragWithoutEngineFailure(aerodynamicsData, liftCoefficient, density, invalidVelocity))) .SetName("CalculateDragWithoutEngineFailure")); }
private static IEnumerable <TestCaseData> GetInvalidDensityTestCases() { var random = new Random(21); AerodynamicsData aerodynamicsData = AerodynamicsDataTestFactory.CreateAerodynamicsData(); Angle angleOfAttack = random.NextAngle(); double liftCoefficient = random.NextDouble(); double invalidDensity = -random.NextDouble(); double velocity = random.NextDouble(); double takeOffWeight = random.NextDouble(); yield return(new TestCaseData(new Action(() => AerodynamicsHelper.CalculateLift(aerodynamicsData, angleOfAttack, invalidDensity, velocity))) .SetName("CalculateLift - Negative")); yield return(new TestCaseData(new Action(() => AerodynamicsHelper.CalculateLift(aerodynamicsData, angleOfAttack, 0, velocity))) .SetName("CalculateLift - Zero")); yield return(new TestCaseData(new Action(() => AerodynamicsHelper.CalculateDragWithEngineFailure(aerodynamicsData, liftCoefficient, invalidDensity, velocity))) .SetName("CalculateDragWithEngineFailure - Negative")); yield return(new TestCaseData(new Action(() => AerodynamicsHelper.CalculateDragWithEngineFailure(aerodynamicsData, liftCoefficient, 0, velocity))) .SetName("CalculateDragWithEngineFailure - Zero")); yield return(new TestCaseData(new Action(() => AerodynamicsHelper.CalculateDragWithoutEngineFailure(aerodynamicsData, liftCoefficient, invalidDensity, velocity))) .SetName("CalculateDragWithoutEngineFailure - Negative")); yield return(new TestCaseData(new Action(() => AerodynamicsHelper.CalculateDragWithoutEngineFailure(aerodynamicsData, liftCoefficient, 0, velocity))) .SetName("CalculateDragWithoutEngineFailure - Zero")); yield return(new TestCaseData(new Action(() => AerodynamicsHelper.CalculateStallSpeed(aerodynamicsData, takeOffWeight, invalidDensity))) .SetName("CalculateStallSpeed - Negative")); yield return(new TestCaseData(new Action(() => AerodynamicsHelper.CalculateStallSpeed(aerodynamicsData, takeOffWeight, 0))) .SetName("CalculateStallSpeed - Zero")); }
protected override double CalculateAerodynamicDragForce(AircraftState state) { double liftCoefficient = AerodynamicsHelper.CalculateLiftCoefficient(AerodynamicsData, CalculateAngleOfAttack(state)); return(AerodynamicsHelper.CalculateDragWithoutEngineFailure(AerodynamicsData, liftCoefficient, Density, state.TrueAirspeed)); }
public static void CalculateDragWithoutEngineFailure_WithValidParameters_ReturnsExpectedValues(AerodynamicsData aerodynamicsData) { // Setup var random = new Random(21); double liftCoefficient = random.NextDouble(); double velocity = random.NextDouble(); // Call double drag = AerodynamicsHelper.CalculateDragWithoutEngineFailure(aerodynamicsData, liftCoefficient, airDensity, velocity); // Assert double expectedDrag = CalculateExpectedDrag(aerodynamicsData, liftCoefficient, airDensity, velocity, false); Assert.AreEqual(expectedDrag, drag, tolerance); }
public static void CalculateDragWithoutEngineFailure_AerodynamicsDataNull_ThrowsArgumentNullException() { // Setup var random = new Random(21); // Call TestDelegate call = () => AerodynamicsHelper.CalculateDragWithoutEngineFailure(null, random.NextDouble(), random.NextDouble(), random.NextDouble()); // Assert var exception = Assert.Throws <ArgumentNullException>(call); Assert.AreEqual("aerodynamicsData", exception.ParamName); }
public static void CalculateDragWithoutEngineFailure_InvalidLiftCoefficient_ThrowsInvalidCalculationException(AerodynamicsData aerodynamicsData, double invalidLiftCoefficient) { // Setup var random = new Random(21); // Call TestDelegate call = () => AerodynamicsHelper.CalculateDragWithoutEngineFailure(aerodynamicsData, invalidLiftCoefficient, random.NextDouble(), random.NextDouble()); // Assert var exception = Assert.Throws <InvalidCalculationException>(call); Assert.AreEqual("Lift coefficient must be in the range of [0, CLMax].", exception.Message); }
public static void Calculate_WithAircraftStateHeightSmallerThanThresholdAndLiftSmallerThanTakeOffWeight_ReturnsExpectedTrueAirspeedRate(AircraftData aircraftData) { // Setup const double airspeed = 10.0; const double threshold = 0.01; var random = new Random(21); var aircraftState = new AircraftState(aircraftData.MaximumPitchAngle, random.NextAngle(), airspeed, threshold - random.NextDouble(), random.NextDouble()); Angle angleOfAttack = aircraftState.PitchAngle - aircraftState.FlightPathAngle; // Precondition double lift = AerodynamicsHelper.CalculateLift(aircraftData.AerodynamicsData, angleOfAttack, airDensity, airspeed); double takeOffWeightNewton = aircraftData.TakeOffWeight * 1000; // N Assert.IsTrue(lift < takeOffWeightNewton); var calculator = new NormalTakeOffDynamicsCalculator(aircraftData, airDensity, gravitationalAcceleration); // Call AircraftAccelerations accelerations = calculator.Calculate(aircraftState); // Assert double liftCoefficient = AerodynamicsHelper.CalculateLiftCoefficient(aircraftData.AerodynamicsData, angleOfAttack); double normalForce = takeOffWeightNewton - lift; double dragForce = AerodynamicsHelper.CalculateDragWithoutEngineFailure(aircraftData.AerodynamicsData, liftCoefficient, airDensity, airspeed) + normalForce * aircraftData.RollingResistanceCoefficient; double thrustForce = aircraftData.NrOfEngines * aircraftData.MaximumThrustPerEngine * 1000; double horizontalWeightComponent = takeOffWeightNewton * Math.Sin(aircraftState.FlightPathAngle.Radians); double expectedAcceleration = (gravitationalAcceleration * (thrustForce - dragForce - horizontalWeightComponent)) / takeOffWeightNewton; Assert.AreEqual(expectedAcceleration, accelerations.TrueAirSpeedRate, tolerance); }