20 using namespace swift::config;
22 using namespace swift::misc::aviation;
23 using namespace swift::misc::physical_quantities;
24 using namespace swift::misc::network;
25 using namespace swift::misc::geo;
26 using namespace swift::misc::math;
37 void defaultConstructor();
40 void allGndFlagsAndTakeOff()
const;
43 void allNotGndFlagsAndTouchdown()
const;
55 void sortOrder()
const;
58 void altitudeCorrection();
67 void isGfEqualAirborne();
69 void isGfEqualOnGround();
87 void CTestAircraftSituation::defaultConstructor()
91 QVERIFY2(sit.
isNull(),
"Situation should be null");
92 QVERIFY2(!sit.
isOnGround(),
"Should not be on ground");
98 void CTestAircraftSituation::allGndFlagsAndTakeOff()
const
101 situations.
setOnGroundInfo({ COnGroundInfo::OnGround, COnGroundInfo::NotSetGroundDetails });
103 QVERIFY2(change.isConstOnGround(),
"Expect const on ground");
104 QVERIFY(!change.isConstNotOnGround());
105 QVERIFY(!change.isJustTakingOff());
106 QVERIFY(!change.isJustTouchingDown());
107 QVERIFY(change.wasConstOnGround());
108 QVERIFY(!change.wasConstNotOnGround());
112 f.
setOnGroundInfo({ COnGroundInfo::NotOnGround, COnGroundInfo::NotSetGroundDetails });
116 QVERIFY2(change2.isJustTakingOff(),
"Expect just take off");
117 QVERIFY(!change2.isJustTouchingDown());
118 QVERIFY(change.wasConstOnGround());
119 QVERIFY(!change.wasConstNotOnGround());
122 void CTestAircraftSituation::allNotGndFlagsAndTouchdown()
const
125 situations.
setOnGroundInfo({ COnGroundInfo::NotOnGround, COnGroundInfo::NotSetGroundDetails });
127 QVERIFY2(change.isConstNotOnGround(),
"Expect const not on ground");
128 QVERIFY(!change.isConstOnGround());
129 QVERIFY(!change.isJustTakingOff());
130 QVERIFY(!change.isJustTouchingDown());
131 QVERIFY(!change.wasConstOnGround());
132 QVERIFY(change.wasConstNotOnGround());
136 f.
setOnGroundInfo({ COnGroundInfo::OnGround, COnGroundInfo::NotSetGroundDetails });
140 QVERIFY2(change2.isJustTouchingDown(),
"Expect just touchdown");
141 QVERIFY(!change2.isJustTakingOff());
142 QVERIFY(!change.wasConstOnGround());
143 QVERIFY(change.wasConstNotOnGround());
146 void CTestAircraftSituation::ascending()
152 void CTestAircraftSituation::descending()
158 void CTestAircraftSituation::rotateUp()
162 QVERIFY2(!change.isRotatingUp(),
"Do not expect rotate up");
170 QVERIFY2(change2.isRotatingUp(),
"Expect rotate up");
173 void CTestAircraftSituation::sortOrder()
const
184 void CTestAircraftSituation::altitudeCorrection()
189 CAltitude alt(100, CAltitude::MeanSeaLevel, CLengthUnit::ft());
195 QVERIFY2(corAlt == alt,
"Expect same altitude");
203 QVERIFY2(corAlt == alt,
"Still expect same altitude");
206 const CLength cg(3, CLengthUnit::m());
209 QVERIFY2(correction == CAircraftSituation::Underflow,
"Expect underflow correction");
210 QVERIFY2(corAlt > alt,
"Expect corrected altitude");
211 QVERIFY2((corAlt - cg) == alt,
"Expect correction by CG");
215 cg2.switchUnit(CLengthUnit::m());
216 situation.
setCG(cg2);
218 QVERIFY2(correction == CAircraftSituation::Underflow,
"Expect underflow correction");
219 QVERIFY2(corAlt2 == corAlt,
"Expect same value for corrected altitude");
222 alt =
CAltitude(-1000, CAltitude::MeanSeaLevel, CLengthUnit::ft());
223 ep.setGeodeticHeight(alt);
227 QVERIFY2(correction == CAircraftSituation::Underflow,
"Expect underflow correction");
228 QVERIFY2(corAlt > alt,
"Expect corrected altitude");
229 QVERIFY2((corAlt - cg) == alt,
"Expect correction by CG");
232 alt =
CAltitude(1000, CAltitude::MeanSeaLevel, CLengthUnit::ft());
234 ep.setGeodeticHeight(alt);
235 ep.addAltitudeOffset(
CLength(-100, CLengthUnit::ft()));
238 QVERIFY2(corAlt == alt,
"Expect same altitude, no overflow since not on gnd.");
240 situation.
setOnGroundInfo({ COnGroundInfo::OnGround, COnGroundInfo::InFromNetwork });
243 QVERIFY2(correction == CAircraftSituation::DraggedToGround,
"Expect dragged to gnd.");
244 QVERIFY2(corAlt < alt,
"Expect corrected altitude dragged to gnd.");
245 QVERIFY2(corAlt == (ep.getAltitude() + cg),
"Expect correction by CG");
248 void CTestAircraftSituation::sortHint()
250 constexpr
int Lists = 50000;
251 constexpr
int Loops = 20;
256 for (
int i = 0; i < Lists; ++i)
260 listOfLists1.
back().detach();
261 listOfLists2.
back().detach();
262 listOfLists2.
back().setAdjustedSortHint(CAircraftSituationList::AdjustedTimestampLatestFirst);
268 for (
int i = 0; i < Loops; ++i)
281 for (
int i = 0; i < Loops; ++i)
291 const double ratio =
static_cast<double>(hint.second) /
static_cast<double>(noHint.second);
294 qDebug() <<
"Access without hint" << noHint.first <<
"ms (CPU time" << noHint.second <<
"ms)";
295 qDebug() <<
"Access with hint" << hint.first <<
"ms (CPU time" << hint.second <<
"ms)";
296 qDebug() <<
"Access ratio" << ratio;
306 if (ratio <= 1.1) {
return; }
310 QSKIP(
"Skipped sort hint on MacOS");
318 const bool ok = hint <= noHint;
332 const qint64 ts = QDateTime::currentSecsSinceEpoch();
333 const qint64 os = CFsdSetup::c_positionTimeOffsetMsec;
334 CAltitude alt(10000, CAltitude::MeanSeaLevel, CLengthUnit::m());
337 for (
int i = 0; i < 10; i++)
340 const qint64 cTs = ts - i * os;
341 s.setMSecsSinceEpoch(cTs);
342 s.setTimeOffsetMs(os);
344 altitude.addValueSameUnit(-100 * i);
345 s.setAltitude(altitude);
354 CAltitude alt(0, CAltitude::MeanSeaLevel, CLengthUnit::m());
361 alt.addValueSameUnit(100);
363 return newSituations;
373 const double pitch = CMathUtils::randomDouble(1.5);
375 s.setPitch(
CAngle(pitch, CAngleUnit::deg()));
378 average = average / newSituations.
size();
383 return newSituations;
386 void CTestAircraftSituation::isGfLanding()
389 QVERIFY2(CAircraftSituation::isGfLanding(1.0, 0.0),
"Should be landing");
390 QVERIFY2(!CAircraftSituation::isGfLanding(0.0, 1.0),
"Should be landing");
391 QVERIFY2(!CAircraftSituation::isGfLanding(1.0, 0.9),
"Should be landing");
392 QVERIFY2(!CAircraftSituation::isGfLanding(0.5, 0.5),
"Should be landing");
395 void CTestAircraftSituation::isGfStarting()
397 QVERIFY2(CAircraftSituation::isGfStarting(0.0, 1.0),
"Should be starting");
398 QVERIFY2(!CAircraftSituation::isGfStarting(1.0, 0.0),
"Should be starting");
399 QVERIFY2(!CAircraftSituation::isGfStarting(0.9, 1.0),
"Should be starting");
400 QVERIFY2(!CAircraftSituation::isGfStarting(0.5, 0.5),
"Should be starting");
403 void CTestAircraftSituation::isGfEqualAirborne()
405 QVERIFY2(CAircraftSituation::isGfEqualAirborne(0.0, 0.0),
"Should be airborne");
406 QVERIFY2(!CAircraftSituation::isGfEqualAirborne(1.0, 1.0),
"Should be airborne");
407 QVERIFY2(!CAircraftSituation::isGfEqualAirborne(0.0, 0.1),
"Should be airborne");
408 QVERIFY2(!CAircraftSituation::isGfEqualAirborne(0.5, 0.5),
"Should be airborne");
411 void CTestAircraftSituation::isGfEqualOnGround()
413 QVERIFY2(CAircraftSituation::isGfEqualOnGround(1.0, 1.0),
"Should be ground");
414 QVERIFY2(!CAircraftSituation::isGfEqualOnGround(0.0, 0.0),
"Should be ground");
415 QVERIFY2(!CAircraftSituation::isGfEqualOnGround(1.0, 0.9),
"Should be ground");
416 QVERIFY2(!CAircraftSituation::isGfEqualOnGround(0.5, 0.5),
"Should be on ground");
419 const CLength &CTestAircraftSituation::cg()
421 static const CLength cg(2.0, CLengthUnit::m());
429 #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.
SWIFTTEST_MAIN(MiscTest::CTestAircraftSituation)
main