| 1 | #include "test_aircraftPerformance.hxx" |
| 2 | |
| 3 | #include "test_suite/FGTestApi/testGlobals.hxx" |
| 4 | #include "test_suite/FGTestApi/NavDataCache.hxx" |
| 5 | |
| 6 | #include <simgear/misc/strutils.hxx> |
| 7 | |
| 8 | #include <Main/fg_props.hxx> |
| 9 | #include <Aircraft/AircraftPerformance.hxx> |
| 10 | |
| 11 | using namespace flightgear; |
| 12 | |
| 13 | // Set up function for each test. |
| 14 | void AircraftPerformanceTests::setUp() |
| 15 | { |
| 16 | FGTestApi::setUp::initTestGlobals("aircraft-perf"); |
| 17 | FGTestApi::setUp::initNavDataCache(); |
| 18 | } |
| 19 | |
| 20 | |
| 21 | // Clean up after each test. |
| 22 | void AircraftPerformanceTests::tearDown() |
| 23 | { |
| 24 | FGTestApi::tearDown::shutdownTestGlobals(); |
| 25 | } |
| 26 | |
| 27 | void AircraftPerformanceTests::testBasic() |
| 28 | { |
| 29 | fgSetString("/aircraft/performance/icao-category", "C"); |
| 30 | AircraftPerformance ap; |
| 31 | |
| 32 | CPPUNIT_ASSERT_DOUBLES_EQUAL(ap.groundSpeedForAltitudeKnots(1000), 152, 1e-3); |
| 33 | CPPUNIT_ASSERT_DOUBLES_EQUAL(ap.groundSpeedForAltitudeKnots(8000), 224, 1e-3); |
| 34 | CPPUNIT_ASSERT_DOUBLES_EQUAL(ap.groundSpeedForAltitudeKnots(20000), 491, 1e-3); |
| 35 | CPPUNIT_ASSERT_DOUBLES_EQUAL(ap.groundSpeedForAltitudeKnots(35000), 461, 1e-3); |
| 36 | CPPUNIT_ASSERT_DOUBLES_EQUAL(ap.groundSpeedForAltitudeKnots(38000), 458, 1e-3); |
| 37 | CPPUNIT_ASSERT_DOUBLES_EQUAL(ap.groundSpeedForAltitudeKnots(40000), 458, 1e-3); |
| 38 | |
| 39 | CPPUNIT_ASSERT_DOUBLES_EQUAL(ap.timeBetween(3000, 6000), 100, 1); |
| 40 | CPPUNIT_ASSERT_DOUBLES_EQUAL(ap.distanceNmBetween(3000, 6000), 5.430, 1e-3); |
| 41 | |
| 42 | CPPUNIT_ASSERT_DOUBLES_EQUAL(ap.timeBetween(36000, 34000), 100, 1); |
| 43 | CPPUNIT_ASSERT_DOUBLES_EQUAL(ap.distanceNmBetween(36000, 34000), 12.805, 1e-1); |
| 44 | |
| 45 | CPPUNIT_ASSERT_DOUBLES_EQUAL(ap.timeBetween(15000, 20000), 300, 1); |
| 46 | CPPUNIT_ASSERT_DOUBLES_EQUAL(ap.distanceNmBetween(15000, 18000), 14.270, 1); |
| 47 | |
| 48 | CPPUNIT_ASSERT_DOUBLES_EQUAL(ap.timeBetween(2000, 25000), 1191.6, 1); |
| 49 | CPPUNIT_ASSERT_DOUBLES_EQUAL(ap.distanceNmBetween(2000, 25000), 123.06, 1); |
| 50 | |
| 51 | CPPUNIT_ASSERT_DOUBLES_EQUAL(ap.timeBetween(36000, 3000), 1666.6, 1); |
| 52 | CPPUNIT_ASSERT_DOUBLES_EQUAL(ap.distanceNmBetween(36000, 3000), 162.02, 1); |
| 53 | |
| 54 | CPPUNIT_ASSERT_DOUBLES_EQUAL(251.5, ap.timeToCruise(32.0, 350000), 1); |
| 55 | CPPUNIT_ASSERT_DOUBLES_EQUAL(503.0, ap.timeToCruise(64.0, 380000), 1); |
| 56 | |
| 57 | CPPUNIT_ASSERT_DOUBLES_EQUAL(1553.7, ap.turnRadiusMForAltitude(4000), 1); |
| 58 | CPPUNIT_ASSERT_DOUBLES_EQUAL(3322.4, ap.turnRadiusMForAltitude(16000), 1); |
| 59 | CPPUNIT_ASSERT_DOUBLES_EQUAL(4602.6, ap.turnRadiusMForAltitude(30000), 1); |
| 60 | CPPUNIT_ASSERT_DOUBLES_EQUAL(4475.5, ap.turnRadiusMForAltitude(38000), 1); |
| 61 | } |
| 62 | |
| 63 | void AircraftPerformanceTests::testAltitudeGradient() |
| 64 | { |
| 65 | fgSetString("/aircraft/performance/icao-category", "E"); |
| 66 | AircraftPerformance ap; |
| 67 | CPPUNIT_ASSERT_DOUBLES_EQUAL(8332, ap.computePreviousAltitude(10000, 6000), 1); |
| 68 | |
| 69 | CPPUNIT_ASSERT_DOUBLES_EQUAL(3260, ap.computeNextAltitude(4000, 2000), 1); |
| 70 | |
| 71 | |
| 72 | } |
| 73 |