android/GlueIOIOPort: fix spurious errors after IOIO baud rate change
[xcsoar.git] / test / src / test_cruiseefficiency.cpp
blob21a06761b94c1079f17ae95510b364294d3a1aa7
1 /* Copyright_License {
3 XCSoar Glide Computer - http://www.xcsoar.org/
4 Copyright (C) 2000-2013 The XCSoar Project
5 A detailed list of copyright holders can be found in the file "AUTHORS".
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 #include "harness_flight.hpp"
24 #include "harness_wind.hpp"
26 static bool
27 test_cruise_efficiency(int test_num, int n_wind)
29 // tests functionality of cruise efficiency calculations
31 double ce0, ce1, ce2, ce3, ce4, ce5, ce6;
33 autopilot_parms.SetIdeal();
35 TestFlightResult result = test_flight(test_num, n_wind);
36 ce0 = result.calc_cruise_efficiency;
38 // wandering
39 autopilot_parms.SetRealistic();
40 result = test_flight(test_num, n_wind);
41 ce1 = result.calc_cruise_efficiency;
42 // cruise efficiency of this should be lower than nominal
43 if (ce0 <= ce1 || verbose)
44 printf("# calc cruise efficiency %g\n", result.calc_cruise_efficiency);
46 ok(ce0 > ce1, GetTestName("ce wandering", test_num, n_wind), 0);
48 // flying too slow
49 autopilot_parms.SetIdeal();
50 result = test_flight(test_num, n_wind, 0.8);
51 ce2 = result.calc_cruise_efficiency;
52 // cruise efficiency of this should be lower than nominal
53 if (ce0 <= ce2 || verbose)
54 printf("# calc cruise efficiency %g\n", result.calc_cruise_efficiency);
56 ok(ce0 > ce2, GetTestName("ce speed slow", test_num, n_wind), 0);
58 // flying too fast
59 autopilot_parms.SetIdeal();
60 result = test_flight(test_num, n_wind, 1.2);
61 ce3 = result.calc_cruise_efficiency;
62 // cruise efficiency of this should be lower than nominal
63 if (ce0 <= ce3 || verbose)
64 printf("# calc cruise efficiency %g\n", result.calc_cruise_efficiency);
66 ok(ce0 > ce3, GetTestName("ce speed fast", test_num, n_wind), 0);
68 // higher than expected cruise sink
69 autopilot_parms.sink_factor = fixed(1.2);
70 result = test_flight(test_num, n_wind);
71 ce4 = result.calc_cruise_efficiency;
72 if (ce0 <= ce4 || verbose)
73 printf("# calc cruise efficiency %g\n", result.calc_cruise_efficiency);
75 ok(ce0 > ce4, GetTestName("ce high sink", test_num, n_wind), 0);
76 // cruise efficiency of this should be lower than nominal
77 autopilot_parms.sink_factor = fixed(1.0);
79 // slower than expected climb
80 autopilot_parms.climb_factor = fixed(0.8);
81 result = test_flight(test_num, n_wind);
82 ce5 = result.calc_cruise_efficiency;
83 if (ce0 <= ce5 || verbose)
84 printf("# calc cruise efficiency %g\n", result.calc_cruise_efficiency);
86 ok(ce0 > ce5, GetTestName("ce slow climb", test_num, n_wind), 0);
87 // cruise efficiency of this should be lower than nominal
88 autopilot_parms.climb_factor = fixed(1.0);
90 // lower than expected cruise sink;
91 autopilot_parms.sink_factor = fixed(0.8);
92 result = test_flight(test_num, n_wind);
93 ce6 = result.calc_cruise_efficiency;
94 if (ce0 >= ce6 || verbose)
95 printf("# calc cruise efficiency %g\n", result.calc_cruise_efficiency);
97 ok(ce0 < ce6, GetTestName("ce low sink", test_num, n_wind), 0);
98 // cruise efficiency of this should be greater than nominal
99 autopilot_parms.sink_factor = fixed(1.0);
101 bool retval = (ce0 > ce1) && (ce0 > ce2) && (ce0 > ce3) && (ce0 > ce4)
102 && (ce0 > ce5) && (ce0 < ce6);
103 if (verbose || !retval) {
104 printf("# ce nominal %g\n", ce0);
105 printf("# ce wandering %g\n", ce1);
106 printf("# ce speed slow %g\n", ce2);
107 printf("# ce speed fast %g\n", ce3);
108 printf("# ce high sink %g\n", ce4);
109 printf("# ce slow climb %g\n", ce5);
110 printf("# ce low sink %g\n", ce6);
112 return retval;
116 main(int argc, char** argv)
118 // default arguments
119 autopilot_parms.SetIdeal();
121 if (!ParseArgs(argc, argv))
122 return 0;
124 unsigned i = rand() % NUM_WIND;
125 plan_tests(6);
127 // tests whether cruise efficiency is calculated correctly
128 test_cruise_efficiency(3, i);
130 return exit_status();