public static void Calculate_WithAirspeedEqualToThresholdAndNoNormalForcePresent_ReturnsExpectedFlightPathAngleRate(AircraftData aircraftData) { // Setup const double heightThreshold = 0.01; var random = new Random(21); var aircraftState = new AircraftState(aircraftData.MaximumPitchAngle, random.NextAngle(), 100, heightThreshold - random.NextDouble(), random.NextDouble()); Angle angleOfAttack = aircraftState.PitchAngle - aircraftState.FlightPathAngle; // Precondition double lift = AerodynamicsHelper.CalculateLift(aircraftData.AerodynamicsData, angleOfAttack, airDensity, aircraftState.TrueAirspeed); double takeOffWeightNewton = aircraftData.TakeOffWeight * 1000; // N Assert.IsTrue(lift > takeOffWeightNewton); var calculator = new TestTakeOffDynamicsCalculator(aircraftData, airDensity, gravitationalAcceleration); // Call AircraftAccelerations accelerations = calculator.Calculate(aircraftState); // Assert double expectedRate = (gravitationalAcceleration * (lift - takeOffWeightNewton)) / (takeOffWeightNewton * aircraftState.TrueAirspeed); Assert.AreEqual(expectedRate, accelerations.FlightPathRate.Radians, tolerance); }
public void GivenAircraftStateResultsIntoInvalidCalculationException_WhenCalculateCalled_ThenCalculatorExceptionThrown() { // Given var random = new Random(21); AircraftData aircraftData = AircraftDataTestFactory.CreateRandomAircraftData(); var calculator = new TestTakeOffDynamicsCalculator(aircraftData, random.NextDouble(), random.NextDouble()); var state = new AircraftState(aircraftData.AerodynamicsData.ZeroLiftAngleOfAttack - Angle.FromRadians(1), new Angle(), random.NextDouble(), random.NextDouble(), random.NextDouble()); // When TestDelegate call = () => calculator.Calculate(state); // Then var exception = Assert.Throws <CalculatorException>(call); Exception innerException = exception.InnerException; Assert.IsInstanceOf <InvalidCalculationException>(innerException); Assert.AreEqual(innerException.Message, exception.Message); }
public void Calculate_AircraftStateNull_ThrowsArgumentNullException() { // Setup var random = new Random(21); AircraftData aircraftData = AircraftDataTestFactory.CreateRandomAircraftData(); var calculator = new TestTakeOffDynamicsCalculator(aircraftData, random.NextDouble(), random.NextDouble()); // Call TestDelegate call = () => calculator.Calculate(null); // Assert var exception = Assert.Throws <ArgumentNullException>(call); Assert.AreEqual("aircraftState", exception.ParamName); }
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); double thrust = random.NextDouble() * 1000; double drag = random.NextDouble() * 100; double frictionCoefficient = random.NextDouble(); var calculator = new TestTakeOffDynamicsCalculator(aircraftData, airDensity, gravitationalAcceleration) { Thrust = thrust, Drag = drag, RollDrag = frictionCoefficient }; // Call AircraftAccelerations accelerations = calculator.Calculate(aircraftState); // Assert double horizontalWeightComponent = takeOffWeightNewton * Math.Sin(aircraftState.FlightPathAngle.Radians); double groundDrag = frictionCoefficient * (aircraftData.TakeOffWeight * 1000 - lift); double expectedAcceleration = (gravitationalAcceleration * (thrust - drag - groundDrag - horizontalWeightComponent)) / takeOffWeightNewton; Assert.AreEqual(expectedAcceleration, accelerations.TrueAirSpeedRate, tolerance); }
public static void Calculate_WithAircraftStateSpeedHigherThanRotationSpeedAndPitchAngleAtMaximumPitch_ReturnsExpectedZeroPitchRate(AircraftData aircraftData) { // Setup double rotationSpeed = GetRotationSpeed(aircraftData); var random = new Random(21); var aircraftState = new AircraftState(aircraftData.MaximumPitchAngle, random.NextAngle(), rotationSpeed + random.NextDouble(), random.NextDouble(), random.NextDouble()); var calculator = new TestTakeOffDynamicsCalculator(aircraftData, airDensity, random.NextDouble()); // Call AircraftAccelerations accelerations = calculator.Calculate(aircraftState); // Assert Assert.Zero(accelerations.PitchRate.Degrees); }
public static void Calculate_Always_SendsCorrectInput() { // Setup var random = new Random(21); AircraftData aircraftData = AircraftDataTestFactory.CreateRandomAircraftData(); var calculator = new TestTakeOffDynamicsCalculator(aircraftData, random.NextDouble(), random.NextDouble()); Angle angleOfAttack = AerodynamicsDataTestHelper.GetValidAngleOfAttack(aircraftData.AerodynamicsData); var state = new AircraftState(angleOfAttack, new Angle(), random.NextDouble(), random.NextDouble(), random.NextDouble()); // Call calculator.Calculate(state); // Assert Assert.AreSame(state, calculator.CalculateDragInput); }
public static void Calculate_WithAircraftStateAlways_ReturnsExpectedClimbRate() { // Setup var random = new Random(21); AircraftData aircraftData = AircraftDataTestFactory.CreateRandomAircraftData(); Angle angleOfAttack = AerodynamicsDataTestHelper.GetValidAngleOfAttack(aircraftData.AerodynamicsData); var aircraftState = new AircraftState(angleOfAttack, new Angle(), random.NextDouble(), random.NextDouble(), random.NextDouble()); var calculator = new TestTakeOffDynamicsCalculator(aircraftData, random.NextDouble(), random.NextDouble()); // Call AircraftAccelerations accelerations = calculator.Calculate(aircraftState); // Assert double expectedClimbRate = aircraftState.TrueAirspeed * Math.Sin(aircraftState.FlightPathAngle.Radians); Assert.AreEqual(expectedClimbRate, accelerations.ClimbRate, tolerance); }
public void Calculate_WithAircraftStateAndSpeedHigherThanRotationSpeedAndPitch_ReturnsExpectedPitchRate(AircraftData aircraftData) { // Setup var random = new Random(21); double rotationSpeed = GetRotationSpeed(aircraftData); double pitchAngle = aircraftData.MaximumPitchAngle.Degrees - random.NextDouble(); var aircraftState = new AircraftState(Angle.FromDegrees(pitchAngle), random.NextAngle(), rotationSpeed + random.NextDouble(), random.NextDouble(), random.NextDouble()); var calculator = new TestTakeOffDynamicsCalculator(aircraftData, airDensity, random.NextDouble()); // Call AircraftAccelerations accelerations = calculator.Calculate(aircraftState); // Assert Angle expectedPitchRate = aircraftData.PitchAngleGradient; Assert.AreEqual(expectedPitchRate, accelerations.PitchRate); }
public static void Calculate_WithAirspeedLowerThanThreshold_ReturnsExpectedZeroRate() { // Setup var random = new Random(21); AircraftData aircraftData = AircraftDataTestFactory.CreateRandomAircraftData(); Angle angleOfAttack = AerodynamicsDataTestHelper.GetValidAngleOfAttack(aircraftData.AerodynamicsData); var aircraftState = new AircraftState(angleOfAttack, new Angle(), random.NextDouble(), random.NextDouble(), random.NextDouble()); // Precondition Assert.IsTrue(aircraftState.TrueAirspeed < 1); var calculator = new TestTakeOffDynamicsCalculator(aircraftData, random.NextDouble(), random.NextDouble()); // Call AircraftAccelerations accelerations = calculator.Calculate(aircraftState); // Assert Assert.Zero(accelerations.FlightPathRate.Degrees); }