10 #include <QElapsedTimer>
21 using namespace swift::config;
23 using namespace swift::misc::aviation;
24 using namespace swift::misc::physical_quantities;
25 using namespace swift::misc::network;
26 using namespace swift::misc::geo;
27 using namespace swift::misc::math;
38 void defaultConstructor();
41 void allGndFlagsAndTakeOff()
const;
44 void allNotGndFlagsAndTouchdown()
const;
56 void sortOrder()
const;
59 void altitudeCorrection();
68 void isGfEqualAirborne();
70 void isGfEqualOnGround();
88 void CTestAircraftSituation::defaultConstructor()
92 QVERIFY2(sit.
isNull(),
"Situation should be null");
93 QVERIFY2(!sit.
isOnGround(),
"Should not be on ground");
99 void CTestAircraftSituation::allGndFlagsAndTakeOff()
const
102 situations.
setOnGroundInfo({ COnGroundInfo::OnGround, COnGroundInfo::NotSetGroundDetails });
104 QVERIFY2(change.isConstOnGround(),
"Expect const on ground");
105 QVERIFY(!change.isConstNotOnGround());
106 QVERIFY(!change.isJustTakingOff());
107 QVERIFY(!change.isJustTouchingDown());
108 QVERIFY(change.wasConstOnGround());
109 QVERIFY(!change.wasConstNotOnGround());
113 f.
setOnGroundInfo({ COnGroundInfo::NotOnGround, COnGroundInfo::NotSetGroundDetails });
117 QVERIFY2(change2.isJustTakingOff(),
"Expect just take off");
118 QVERIFY(!change2.isJustTouchingDown());
119 QVERIFY(change.wasConstOnGround());
120 QVERIFY(!change.wasConstNotOnGround());
123 void CTestAircraftSituation::allNotGndFlagsAndTouchdown()
const
126 situations.
setOnGroundInfo({ COnGroundInfo::NotOnGround, COnGroundInfo::NotSetGroundDetails });
128 QVERIFY2(change.isConstNotOnGround(),
"Expect const not on ground");
129 QVERIFY(!change.isConstOnGround());
130 QVERIFY(!change.isJustTakingOff());
131 QVERIFY(!change.isJustTouchingDown());
132 QVERIFY(!change.wasConstOnGround());
133 QVERIFY(change.wasConstNotOnGround());
137 f.
setOnGroundInfo({ COnGroundInfo::OnGround, COnGroundInfo::NotSetGroundDetails });
141 QVERIFY2(change2.isJustTouchingDown(),
"Expect just touchdown");
142 QVERIFY(!change2.isJustTakingOff());
143 QVERIFY(!change.wasConstOnGround());
144 QVERIFY(change.wasConstNotOnGround());
147 void CTestAircraftSituation::ascending()
153 void CTestAircraftSituation::descending()
159 void CTestAircraftSituation::rotateUp()
163 QVERIFY2(!change.isRotatingUp(),
"Do not expect rotate up");
171 QVERIFY2(change2.isRotatingUp(),
"Expect rotate up");
174 void CTestAircraftSituation::sortOrder()
const
185 void CTestAircraftSituation::altitudeCorrection()
190 CAltitude alt(100, CAltitude::MeanSeaLevel, CLengthUnit::ft());
196 QVERIFY2(corAlt == alt,
"Expect same altitude");
204 QVERIFY2(corAlt == alt,
"Still expect same altitude");
207 const CLength cg(3, CLengthUnit::m());
210 QVERIFY2(correction == CAircraftSituation::Underflow,
"Expect underflow correction");
211 QVERIFY2(corAlt > alt,
"Expect corrected altitude");
212 QVERIFY2((corAlt - cg) == alt,
"Expect correction by CG");
216 cg2.switchUnit(CLengthUnit::m());
217 situation.
setCG(cg2);
219 QVERIFY2(correction == CAircraftSituation::Underflow,
"Expect underflow correction");
220 QVERIFY2(corAlt2 == corAlt,
"Expect same value for corrected altitude");
223 alt =
CAltitude(-1000, CAltitude::MeanSeaLevel, CLengthUnit::ft());
224 ep.setGeodeticHeight(alt);
228 QVERIFY2(correction == CAircraftSituation::Underflow,
"Expect underflow correction");
229 QVERIFY2(corAlt > alt,
"Expect corrected altitude");
230 QVERIFY2((corAlt - cg) == alt,
"Expect correction by CG");
233 alt =
CAltitude(1000, CAltitude::MeanSeaLevel, CLengthUnit::ft());
235 ep.setGeodeticHeight(alt);
236 ep.addAltitudeOffset(
CLength(-100, CLengthUnit::ft()));
239 QVERIFY2(corAlt == alt,
"Expect same altitude, no overflow since not on gnd.");
241 situation.
setOnGroundInfo({ COnGroundInfo::OnGround, COnGroundInfo::InFromNetwork });
244 QVERIFY2(correction == CAircraftSituation::DraggedToGround,
"Expect dragged to gnd.");
245 QVERIFY2(corAlt < alt,
"Expect corrected altitude dragged to gnd.");
246 QVERIFY2(corAlt == (ep.getAltitude() + cg),
"Expect correction by CG");
249 void CTestAircraftSituation::sortHint()
251 constexpr
int Lists = 50000;
252 constexpr
int Loops = 20;
257 for (
int i = 0; i < Lists; ++i)
261 listOfLists1.
back().detach();
262 listOfLists2.
back().detach();
263 listOfLists2.
back().setAdjustedSortHint(CAircraftSituationList::AdjustedTimestampLatestFirst);
269 for (
int i = 0; i < Loops; ++i)
282 for (
int i = 0; i < Loops; ++i)
292 const double ratio =
static_cast<double>(hint.second) /
static_cast<double>(noHint.second);
295 qDebug() <<
"Access without hint" << noHint.first <<
"ms (CPU time" << noHint.second <<
"ms)";
296 qDebug() <<
"Access with hint" << hint.first <<
"ms (CPU time" << hint.second <<
"ms)";
297 qDebug() <<
"Access ratio" << ratio;
307 if (ratio <= 1.1) {
return; }
311 QSKIP(
"Skipped sort hint on MacOS");
319 const bool ok = hint <= noHint;
334 const qint64 os = CFsdSetup::c_positionTimeOffsetMsec;
335 CAltitude alt(10000, CAltitude::MeanSeaLevel, CLengthUnit::m());
338 for (
int i = 0; i < 10; i++)
341 const qint64 cTs = ts - i * os;
342 s.setMSecsSinceEpoch(cTs);
343 s.setTimeOffsetMs(os);
345 altitude.addValueSameUnit(-100 * i);
346 s.setAltitude(altitude);
355 CAltitude alt(0, CAltitude::MeanSeaLevel, CLengthUnit::m());
362 alt.addValueSameUnit(100);
364 return newSituations;
374 const double pitch = CMathUtils::randomDouble(1.5);
376 s.setPitch(
CAngle(pitch, CAngleUnit::deg()));
379 average = average / newSituations.
size();
384 return newSituations;
387 void CTestAircraftSituation::isGfLanding()
390 QVERIFY2(CAircraftSituation::isGfLanding(1.0, 0.0),
"Should be landing");
391 QVERIFY2(!CAircraftSituation::isGfLanding(0.0, 1.0),
"Should be landing");
392 QVERIFY2(!CAircraftSituation::isGfLanding(1.0, 0.9),
"Should be landing");
393 QVERIFY2(!CAircraftSituation::isGfLanding(0.5, 0.5),
"Should be landing");
396 void CTestAircraftSituation::isGfStarting()
398 QVERIFY2(CAircraftSituation::isGfStarting(0.0, 1.0),
"Should be starting");
399 QVERIFY2(!CAircraftSituation::isGfStarting(1.0, 0.0),
"Should be starting");
400 QVERIFY2(!CAircraftSituation::isGfStarting(0.9, 1.0),
"Should be starting");
401 QVERIFY2(!CAircraftSituation::isGfStarting(0.5, 0.5),
"Should be starting");
404 void CTestAircraftSituation::isGfEqualAirborne()
406 QVERIFY2(CAircraftSituation::isGfEqualAirborne(0.0, 0.0),
"Should be airborne");
407 QVERIFY2(!CAircraftSituation::isGfEqualAirborne(1.0, 1.0),
"Should be airborne");
408 QVERIFY2(!CAircraftSituation::isGfEqualAirborne(0.0, 0.1),
"Should be airborne");
409 QVERIFY2(!CAircraftSituation::isGfEqualAirborne(0.5, 0.5),
"Should be airborne");
412 void CTestAircraftSituation::isGfEqualOnGround()
414 QVERIFY2(CAircraftSituation::isGfEqualOnGround(1.0, 1.0),
"Should be ground");
415 QVERIFY2(!CAircraftSituation::isGfEqualOnGround(0.0, 0.0),
"Should be ground");
416 QVERIFY2(!CAircraftSituation::isGfEqualOnGround(1.0, 0.9),
"Should be ground");
417 QVERIFY2(!CAircraftSituation::isGfEqualOnGround(0.5, 0.5),
"Should be on ground");
420 const CLength &CTestAircraftSituation::cg()
422 static const CLength cg(2.0, CLengthUnit::m());
430 #include "testaircraftsituation.moc"
CAircraftSituation and CAircraftSituationChange tests.
static constexpr bool isRunningOnMacOSPlatform()
Running on MacOS platform?
static bool isLocalDeveloperDebugBuild()
Local build for developers.
Generic sequential container with value semantics.
size_type size() const
Returns number of elements in the sequence.
void push_back(const T &value)
Appends an element at the end of the sequence.
reference front()
Access the first element.
void push_front(const T &value)
Insert as first element.
reference back()
Access the last element.
void reverse()
In-place reverse.
void pop_front()
Removes an element at the front of the sequence.
void addMsecs(qint64 ms)
Add the given number of milliseconds to the timestamp.
bool isSortedLatestLast() const
Is completely sorted: latest last.
qint64 getAdjustedMSecsSinceEpoch() const
Timestamp with offset added for interpolation.
bool isSortedAdjustedLatestFirst() const
Is completely sorted: latest last.
bool isSortedAdjustedLatestLast() const
Is completely sorted: latest last.
void sortAdjustedLatestFirst()
Sort by adjusted timestamp.
Value object about changes in situations.
Value object encapsulating information of an aircraft's situation.
void setCG(const physical_quantities::CLength &cg)
Set CG.
bool setGroundElevation(const aviation::CAltitude &altitude, GndElevationInfo info, bool transferred=false)
Elevation of the ground directly beneath at the given situation.
AltitudeCorrection
How was altitude corrected?
bool isOnGroundInfoAvailable() const
On ground info available?
void setAltitude(const CAltitude &altitude)
Set altitude.
bool isOnGround() const
Is on ground?
CAltitude getCorrectedAltitude(bool enableDragToGround=true, AltitudeCorrection *correction=nullptr) const
Get altitude under consideration of ground elevation and ground flag.
void setOnGroundInfo(const aviation::COnGroundInfo &info)
Set the on ground info.
void setPitch(const physical_quantities::CAngle &pitch)
Set pitch.
virtual bool isNull() const
Null situation.
bool isOnGroundFromNetwork() const
On ground by network flag?
bool isOnGroundFromParts() const
On ground by parts?
List of aircraft situations.
bool isConstDescending(bool alreadySortedLatestFirst=false) const
Constantly descending?
void setOnGroundInfo(const COnGroundInfo &info)
Set on ground.
bool isSortedAdjustedLatestFirstWithoutNullPositions() const
Latest first and no null positions?
bool isConstAscending(bool alreadySortedLatestFirst=false) const
Constantly ascending?
Altitude as used in aviation, can be AGL or MSL altitude.
Plane of same elevation, can be a single point or larger area (e.g. airport)
Physical unit angle (radians, degrees)
Physical unit length (length)
Free functions in swift::misc.
int getThreadCpuTimeMs()
Get the time in milliseconds that the CPU has spent executing the current thread.
qint64 currentSecsSinceEpoch()
qint64 elapsed() const const
QVERIFY2(condition, message)
SWIFTTEST_MAIN(MiscTest::CTestAircraftSituation)
main