Renderer, ...: use PixelRect::GetCenter()
[xcsoar.git] / test / src / TestGlidePolar.cpp
blob9b88a11c5d1a9c67850e46eb8db535ed1e18a5bd
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 "TestUtil.hpp"
24 #include "GlideSolvers/GlidePolar.hpp"
25 #include "Units/System.hpp"
27 #include <cstdio>
29 class GlidePolarTest
31 GlidePolar polar;
33 public:
34 void Run();
36 private:
37 void Init();
38 void TestBasic();
39 void TestBallast();
40 void TestBugs();
41 void TestMC();
44 void
45 GlidePolarTest::Init()
47 // Polar 1 from PolarStore (206 Hornet)
48 polar.SetCoefficients(PolarCoefficients(fixed(0.0022032), fixed(-0.08784),
49 fixed(1.47)), false);
51 polar.SetReferenceMass(fixed(318), false);
52 polar.SetDryMass(fixed(318), false);
53 polar.SetBallastRatio(fixed(100) / polar.reference_mass);
55 polar.SetWingArea(fixed(9.8));
57 // No ballast and no bugs on the wings
58 polar.ballast = fixed(0);
59 polar.bugs = fixed(1);
61 // MC zero
62 polar.mc = fixed(0);
64 polar.SetVMax(Units::ToSysUnit(fixed(200), Unit::KILOMETER_PER_HOUR), false);
67 void
68 GlidePolarTest::TestBasic()
70 polar.Update();
72 ok1(equals(polar.polar.a, polar.ideal_polar.a));
73 ok1(equals(polar.polar.b, polar.ideal_polar.b));
74 ok1(equals(polar.polar.c, polar.ideal_polar.c));
76 ok1(equals(polar.SinkRate(Units::ToSysUnit(fixed(80), Unit::KILOMETER_PER_HOUR)), 0.606));
77 ok1(equals(polar.SinkRate(Units::ToSysUnit(fixed(120), Unit::KILOMETER_PER_HOUR)), 0.99));
78 ok1(equals(polar.SinkRate(Units::ToSysUnit(fixed(160), Unit::KILOMETER_PER_HOUR)), 1.918));
80 ok1(equals(polar.GetSMax(), polar.SinkRate(polar.GetVMax())));
82 ok1(equals(polar.GetVMin(), 19.934640523));
83 ok1(equals(polar.GetSMin(), polar.SinkRate(polar.GetVMin())));
84 ok1(equals(polar.GetVTakeoff(), polar.GetVMin() / 2));
86 ok1(equals(polar.GetVBestLD(), 25.830434162));
87 ok1(equals(polar.GetSBestLD(), polar.SinkRate(polar.GetVBestLD())));
88 ok1(equals(polar.GetBestLD(), polar.GetVBestLD() / polar.GetSBestLD()));
90 ok1(equals(polar.GetTotalMass(), 318));
91 ok1(equals(polar.GetWingLoading(), 32.448979592));
92 ok1(equals(polar.GetBallast(), 0));
93 ok1(equals(polar.GetBallastLitres(), 0));
94 ok1(polar.IsBallastable());
95 ok1(!polar.HasBallast());
98 void
99 GlidePolarTest::TestBallast()
101 polar.SetBallast(fixed(0.25));
103 ok1(equals(polar.GetBallastLitres(), 25));
104 ok1(equals(polar.GetBallast(), 0.25));
106 polar.SetBallastLitres(fixed(50));
108 ok1(equals(polar.GetBallastLitres(), 50));
109 ok1(equals(polar.GetBallast(), 0.5));
110 ok1(equals(polar.GetTotalMass(), 368));
111 ok1(equals(polar.GetWingLoading(), 37.551020408));
112 ok1(polar.HasBallast());
114 fixed loading_factor = sqrt(polar.GetTotalMass() / polar.reference_mass);
115 ok1(equals(polar.polar.a, polar.ideal_polar.a / loading_factor));
116 ok1(equals(polar.polar.b, polar.ideal_polar.b));
117 ok1(equals(polar.polar.c, polar.ideal_polar.c * loading_factor));
119 ok1(equals(polar.SinkRate(Units::ToSysUnit(fixed(80), Unit::KILOMETER_PER_HOUR)),
120 0.640739));
121 ok1(equals(polar.SinkRate(Units::ToSysUnit(fixed(120), Unit::KILOMETER_PER_HOUR)),
122 0.928976));
123 ok1(equals(polar.SinkRate(Units::ToSysUnit(fixed(160), Unit::KILOMETER_PER_HOUR)),
124 1.722908));
126 ok1(equals(polar.GetVMin(), 21.44464));
127 ok1(equals(polar.GetVBestLD(), 27.78703));
129 polar.SetBallast(fixed(0));
130 ok1(!polar.HasBallast());
133 void
134 GlidePolarTest::TestBugs()
136 polar.SetBugs(fixed(0.75));
137 ok1(equals(polar.GetBugs(), 0.75));
139 ok1(equals(polar.polar.a, polar.ideal_polar.a * 4 / 3));
140 ok1(equals(polar.polar.b, polar.ideal_polar.b * 4 / 3));
141 ok1(equals(polar.polar.c, polar.ideal_polar.c * 4 / 3));
143 ok1(equals(polar.SinkRate(Units::ToSysUnit(fixed(80), Unit::KILOMETER_PER_HOUR)),
144 0.808));
145 ok1(equals(polar.SinkRate(Units::ToSysUnit(fixed(120), Unit::KILOMETER_PER_HOUR)),
146 1.32));
147 ok1(equals(polar.SinkRate(Units::ToSysUnit(fixed(160), Unit::KILOMETER_PER_HOUR)),
148 2.557333));
150 ok1(equals(polar.GetVMin(), 19.93464));
151 ok1(equals(polar.GetVBestLD(), 25.83043));
153 polar.SetBugs(fixed(1));
156 void
157 GlidePolarTest::TestMC()
159 polar.SetMC(fixed(1));
160 ok1(equals(polar.GetVBestLD(), 33.482780452));
162 polar.SetMC(fixed(0));
163 ok1(equals(polar.GetVBestLD(), 25.830434162));
166 void
167 GlidePolarTest::Run()
169 Init();
170 TestBasic();
171 TestBallast();
172 TestBugs();
173 TestMC();
176 int main(int argc, char **argv)
178 plan_tests(46);
180 GlidePolarTest test;
181 test.Run();
183 return exit_status();