コード例 #1
0
            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);
            }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
            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);
            }
コード例 #5
0
            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);
            }
コード例 #6
0
        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);
        }
コード例 #7
0
        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);
        }
コード例 #8
0
            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);
            }
コード例 #9
0
            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);
            }