8 #include <QCoreApplication>
11 #include <QScopedPointer>
40 using namespace swift::misc::aviation;
41 using namespace swift::misc::geo;
42 using namespace swift::misc::physical_quantities;
43 using namespace swift::misc::simulation;
54 void basicInterpolatorTests();
66 void CTestInterpolatorLinear::basicInterpolatorTests()
71 interpolator.markAsUnitTest();
74 const qint64 ts = 1425000000000;
75 const qint64 deltaT = 5000;
76 const qint64 offset = 5000;
77 for (
int i = IRemoteAircraftProvider::MaxSituationsPerCallsign - 1; i >= 0; i--)
82 CLength hag = (s.getAltitude() - s.getGroundElevation());
83 QVERIFY2(s.getHeightAboveGround() == hag,
"Wrong elevation");
87 constexpr
int partsCount = 10;
88 for (
int i = partsCount - 1; i >= 0; i--)
95 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
99 double latOld = 360.0;
100 double lngOld = 360.0;
102 qint64 from = ts - 2 * deltaT + offset;
104 qint64 step = deltaT / 20;
105 for (qint64 currentTime = from; currentTime < to; currentTime += step)
114 const double latDeg = currentSituation.getPosition().latitude().valueRounded(CAngleUnit::deg(), 5);
115 const double lngDeg = currentSituation.getPosition().longitude().valueRounded(CAngleUnit::deg(), 5);
116 QVERIFY2(latDeg < latOld && lngDeg < lngOld, QStringLiteral(
"Values shall decrease: %1/%2 %3/%4")
122 QVERIFY2(latDeg >= 0 && latDeg <= IRemoteAircraftProvider::MaxSituationsPerCallsign,
123 "Values shall be in range");
130 int interpolationNo = 0;
131 const qint64 startTimeMsSinceEpoch = ts - 2 * deltaT;
138 interpolator.resetLastInterpolation();
139 interpolator.markAsUnitTest();
140 for (
int loops = 0; loops < 20; loops++)
142 from = startTimeMsSinceEpoch + offset;
146 for (qint64 currentTime = from; currentTime < to; currentTime += step)
154 QVERIFY2(!currentSituation.getCallsign().isEmpty(),
"Empty callsign");
155 QVERIFY2(currentSituation.getCallsign() == cs,
"Wrong callsign");
156 const double latDeg = currentSituation.getPosition().latitude().valueRounded(CAngleUnit::deg(), 5);
157 const double lngDeg = currentSituation.getPosition().longitude().valueRounded(CAngleUnit::deg(), 5);
166 int timeMs = timer.elapsed();
167 QVERIFY2(timeMs < interpolationNo * 1.5, "Interpolation > 1.5ms
");
168 qDebug() << timeMs << "ms
"
169 << "for" << interpolationNo << "interpolations
";
171 int fetchedParts = 0;
173 for (qint64 currentTime = ts - 2 * deltaT; currentTime < ts; currentTime += 250)
175 const CInterpolationResult result = interpolator.getInterpolation(currentTime, setup, 0);
177 QVERIFY2(result.getPartsStatus().isSupportingParts(), "Parts not supported
");
179 timeMs = timer.elapsed();
180 qDebug() << timeMs << "ms
"
181 << "for" << fetchedParts << "fetched parts
";
184 CAircraftSituation CTestInterpolatorLinear::getTestSituation(const CCallsign &callsign, int number, qint64 ts,
185 qint64 deltaT, qint64 offset)
187 const CAltitude alt(number, CAltitude::MeanSeaLevel, CLengthUnit::m());
188 const CLatitude lat(number, CAngleUnit::deg());
189 const CLongitude lng(180.0 + number, CAngleUnit::deg());
190 const CHeading heading(number * 10, CHeading::True, CAngleUnit::deg());
191 const CAngle bank(number, CAngleUnit::deg());
192 const CAngle pitch(number, CAngleUnit::deg());
193 const CSpeed gs(number * 10, CSpeedUnit::km_h());
194 const CAltitude gndElev({ 0, CLengthUnit::m() }, CAltitude::MeanSeaLevel);
195 const CCoordinateGeodetic c(lat, lng, alt);
196 CAircraftSituation s(callsign, c, heading, pitch, bank, gs);
197 s.setGroundElevation(gndElev, CAircraftSituation::Test);
198 s.setMSecsSinceEpoch(ts - deltaT * number); // values in past
199 s.setTimeOffsetMs(offset);
203 CAircraftParts CTestInterpolatorLinear::getTestParts(int number, qint64 ts, qint64 deltaT)
205 CAircraftLights l(true, false, true, false, true, false);
206 CAircraftEngineList e({ CAircraftEngine(1, true), CAircraftEngine(2, false), CAircraftEngine(3, true) });
207 CAircraftParts p(l, true, 20, true, e, false);
208 p.setMSecsSinceEpoch(ts - deltaT * number); // values in past
211 } // namespace MiscTest
214 SWIFTTEST_MAIN(MiscTest::CTestInterpolatorLinear);
216 #include "testinterpolatorlinear.moc
"
Interpolator classes basic tests.
Value object encapsulating information of aircraft's parts.
Value object encapsulating information of an aircraft's situation.
Value object encapsulating information of a callsign.
Physical unit length (length)
Value object for interpolator and rendering per callsign.
const CInterpolationStatus & getInterpolationStatus() const
Get status.
bool isInterpolated() const
Did interpolation succeed?
Linear interpolator, calculation inbetween positions.
Dummy implementation for testing purpose.
void insertNewSituation(const aviation::CAircraftSituation &situation)
For testing, add new situation and fire signals.
void insertNewAircraftParts(const aviation::CCallsign &callsign, const aviation::CAircraftParts &parts, bool removeOutdatedParts)
For testing, add new situation and fire signals.
Free functions in swift::misc.