swift
Loading...
Searching...
No Matches
testinterpolatorlinearpbh.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (C) swift Project Community / Contributors
2// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3
7
8#include <QTest>
9
10#include "test.h"
11
14#include "misc/math/mathutils.h"
16
17using namespace swift::misc;
18using namespace swift::misc::aviation;
19using namespace swift::misc::geo;
20using namespace swift::misc::physical_quantities;
21using namespace swift::misc::math;
22using namespace swift::misc::simulation;
23
24namespace MiscTest
25{
29 {
31
32 private slots:
34 static void pbhInterpolatorTestHeading0To120();
35
37 static void pbhInterpolatorTestHeadingM90To30();
38
40 static void pbhInterpolatorTestHeadingM90To170();
41
43 static void pbhInterpolatorTestBank270To30();
44
46 static void pbhInterpolatorTestBank170To190();
47
49 static void pbhInterpolatorTestPitch30ToM30();
50
52 static void pbhInterpolatorTestPitchM30To30();
53
54 private:
55 static constexpr const int m_steps = 10;
56 static constexpr const double m_tfStep = 1.0 / m_steps;
57 };
58
59 void CTestInterpolatorLinearPbh::pbhInterpolatorTestHeading0To120()
60 {
62 CAircraftSituation s2({}, CHeading(120, CHeading::True, CAngleUnit::deg()));
63 CInterpolatorLinearPbh pbh(s1, s2);
64
65 double lastDeg = 0;
66
67 for (int i = 0; i <= m_steps; i++)
68 {
69 pbh.setTimeFraction(m_tfStep * i);
70 const double h = pbh.getHeading().value(CAngleUnit::deg());
71
72 if (i == 0)
73 {
74 QVERIFY2(CMathUtils::epsilonEqualLimits(h, 0.0), "Expect initial heading");
75 }
76 else if (i == m_steps)
77 {
78 QVERIFY2(CMathUtils::epsilonEqualLimits(h, 120.0), "Expect final heading");
79 }
80 else
81 {
82 QVERIFY2(h > lastDeg, "Expect increasing heading");
83 }
84 lastDeg = h;
85 }
86 }
87
88 void CTestInterpolatorLinearPbh::pbhInterpolatorTestHeadingM90To30()
89 {
90 CAircraftSituation s1({}, CHeading(270, CHeading::True, CAngleUnit::deg())); // -90
91 CAircraftSituation s2({}, CHeading(30, CHeading::True, CAngleUnit::deg()));
92 CInterpolatorLinearPbh pbh(s1, s2);
93
94 double lastDeg = 0;
95
96 for (int i = 0; i <= m_steps; i++)
97 {
98 pbh.setTimeFraction(m_tfStep * i);
99 const double h = pbh.getHeading().value(CAngleUnit::deg());
100
101 if (i == 0)
102 {
103 QVERIFY2(CMathUtils::epsilonEqualLimits(h, -90.0), "Expect initial heading");
104 }
105 else if (i == m_steps)
106 {
107 QVERIFY2(CMathUtils::epsilonEqualLimits(h, 30.0), "Expect final heading");
108 }
109 else
110 {
111 QVERIFY2(h > lastDeg, "Expect increasing heading");
112 }
113 lastDeg = h;
114 }
115 }
116
117 void CTestInterpolatorLinearPbh::pbhInterpolatorTestHeadingM90To170()
118 {
119 CAircraftSituation s1({}, CHeading(270, CHeading::True, CAngleUnit::deg())); // -90
120 CAircraftSituation s2({}, CHeading(170, CHeading::True, CAngleUnit::deg()));
121 CInterpolatorLinearPbh pbh(s1, s2);
122
123 double lastDeg = 0;
124
125 for (int i = 0; i <= m_steps; i++)
126 {
127 pbh.setTimeFraction(m_tfStep * i);
128 const double h = CAngle::normalizeDegrees360(pbh.getHeading().value(CAngleUnit::deg()));
129
130 if (i == 0)
131 {
132 QVERIFY2(CMathUtils::epsilonEqualLimits(h, 270.0), "Expect initial heading");
133 }
134 else if (i == m_steps)
135 {
136 QVERIFY2(CMathUtils::epsilonEqualLimits(h, 170.0), "Expect final heading");
137 }
138 else
139 {
140 QVERIFY2(h < lastDeg, "Expect decreasing heading");
141 }
142 lastDeg = h;
143 }
144 }
145
146 void CTestInterpolatorLinearPbh::pbhInterpolatorTestBank270To30()
147 {
148 CAircraftSituation s1({}, CHeading {}, {}, CAngle(270, CAngleUnit::deg()));
149 CAircraftSituation s2({}, CHeading {}, {}, CAngle(30, CAngleUnit::deg()));
150 CInterpolatorLinearPbh pbh(s1, s2);
151
152 double lastDeg = 0;
153
154 for (int i = 0; i <= m_steps; i++)
155 {
156 pbh.setTimeFraction(m_tfStep * i);
157 const double b = pbh.getBank().value(CAngleUnit::deg());
158
159 if (i == 0)
160 {
161 QVERIFY2(CMathUtils::epsilonEqualLimits(b, -90.0), "Expect initial bank"); // -90 as not normalized
162 }
163 else if (i == m_steps)
164 {
165 QVERIFY2(CMathUtils::epsilonEqualLimits(b, 30.0), "Expect final bank");
166 }
167 else
168 {
169 QVERIFY2(b > lastDeg, "Expect increasing bank");
170 }
171 lastDeg = b;
172 }
173 }
174
175 void CTestInterpolatorLinearPbh::pbhInterpolatorTestBank170To190()
176 {
177 CAircraftSituation s1({}, CHeading {}, {}, CAngle(170, CAngleUnit::deg()));
178 CAircraftSituation s2({}, CHeading {}, {}, CAngle(190, CAngleUnit::deg()));
179 CInterpolatorLinearPbh pbh(s1, s2);
180
181 double lastDeg = 0;
182
183 for (int i = 0; i <= m_steps; i++)
184 {
185 pbh.setTimeFraction(m_tfStep * i);
186 const double b = CAngle::normalizeDegrees360(pbh.getBank().value(CAngleUnit::deg()));
187
188 if (i == 0)
189 {
190 QVERIFY2(CMathUtils::epsilonEqualLimits(b, 170.0), "Expect initial bank");
191 }
192 else if (i == m_steps)
193 {
194 QVERIFY2(CMathUtils::epsilonEqualLimits(b, 190.0), "Expect final bank");
195 }
196 else
197 {
198 QVERIFY2(b > lastDeg, "Expect increasing bank");
199 }
200 lastDeg = b;
201 }
202 }
203
204 void CTestInterpolatorLinearPbh::pbhInterpolatorTestPitch30ToM30()
205 {
206 CAircraftSituation s1({}, {}, CAngle(30, CAngleUnit::deg()));
207 CAircraftSituation s2({}, {}, CAngle(-30, CAngleUnit::deg()));
208 CInterpolatorLinearPbh pbh(s1, s2);
209
210 double lastDeg = 0;
211
212 for (int i = 0; i <= m_steps; i++)
213 {
214 pbh.setTimeFraction(m_tfStep * i);
215 const double p = pbh.getPitch().value(CAngleUnit::deg());
216
217 if (i == 0)
218 {
219 QVERIFY2(CMathUtils::epsilonEqualLimits(p, 30.0), "Expect initial pitch");
220 }
221 else if (i == m_steps)
222 {
223 QVERIFY2(CMathUtils::epsilonEqualLimits(p, -30.0), "Expect final pitch");
224 }
225 else
226 {
227 QVERIFY2(p < lastDeg, "Expect decreasing pitch");
228 }
229 lastDeg = p;
230 }
231 }
232
233 void CTestInterpolatorLinearPbh::pbhInterpolatorTestPitchM30To30()
234 {
235 CAircraftSituation s1({}, {}, CAngle(-30, CAngleUnit::deg()));
236 CAircraftSituation s2({}, {}, CAngle(30, CAngleUnit::deg()));
237 CInterpolatorLinearPbh pbh(s1, s2);
238
239 double lastDeg = 0;
240
241 for (int i = 0; i <= m_steps; i++)
242 {
243 pbh.setTimeFraction(m_tfStep * i);
244 const double p = pbh.getPitch().value(CAngleUnit::deg());
245
246 if (i == 0)
247 {
248 QVERIFY2(CMathUtils::epsilonEqualLimits(p, -30.0), "Expect initial pitch");
249 }
250 else if (i == m_steps)
251 {
252 QVERIFY2(CMathUtils::epsilonEqualLimits(p, 30.0), "Expect final pitch");
253 }
254 else
255 {
256 QVERIFY2(p > lastDeg, "Expect increasing pitch");
257 }
258 lastDeg = p;
259 }
260 }
261} // namespace MiscTest
262
265
266#include "testinterpolatorlinearpbh.moc"
267
static double normalizeDegrees360(double degrees, int roundDigits=-1)
Normalize: 0≤ degrees <360.
Definition angle.cpp:122
static CAngleUnit deg()
Degrees.
Definition units.h:276
InterpolatorPBH tests As the PBH interpolator works with time-fractions, the situations are time-inde...
Value object encapsulating information of an aircraft's situation.
Heading as used in aviation, can be true or magnetic heading.
Definition heading.h:41
static bool epsilonEqualLimits(double v1, double v2)
Epsilon safe equal.
Definition mathutils.h:38
Free functions in swift::misc.
QObject(QObject *parent)
Q_OBJECTQ_OBJECT
QVERIFY2(condition, message)
#define SWIFTTEST_MAIN(TestObject)
Implements a main() function that executes all tests in TestObject including instantiating a QCoreApp...
Definition test.h:57