swift
Loading...
Searching...
No Matches
testinterpolatorparts.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (C) 2018 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#include <QtDebug>
10
11#include "test.h"
12
15
16using namespace swift::misc;
17using namespace swift::misc::aviation;
18using namespace swift::misc::geo;
19using namespace swift::misc::physical_quantities;
20using namespace swift::misc::simulation;
21
22namespace MiscTest
23{
26 {
28
29 private slots:
31 void groundFlagInterpolation();
32
34 void partsToSituationGndFlag();
35
36 private:
38 static swift::misc::aviation::CAircraftParts createTestParts(int number, qint64 ts, qint64 deltaT,
39 bool onGround);
40
43 createTestSituation(const swift::misc::aviation::CCallsign &callsign, int number, qint64 ts, qint64 deltaT,
44 qint64 offset);
45 };
46
47 void CTestInterpolatorParts::groundFlagInterpolation()
48 {
49 const CCallsign cs("SWIFT");
51 const CInterpolationAndRenderingSetupPerCallsign setup(cs, gSetup);
52
54
55 // fixed time so everything can be debugged
56 const qint64 ts = 1425000000000; // QDateTime::currentMSecsSinceEpoch()
57 const qint64 deltaT = 5000; // ms
59 // const int numberHalf = number / 2;
60 const qint64 farFuture = ts + 3 * number * deltaT;
61 const qint64 farPast = ts - 4 * number * deltaT;
62
64 for (int i = 0; i < number; i++)
65 {
66 const CAircraftParts p = createTestParts(i, ts, deltaT, true);
67 parts.push_back(p);
68 }
69 QVERIFY2(parts.size() == number, "Wrong parts size of list");
70
71 // interpolation functional check
72 const qint64 oldestTs = parts.oldestTimestampMsecsSinceEpoch();
73
74 // Testing for a time >> last time
75 // all on ground flags true
76 {
77 CInterpolatorSpline interpolator(cs, nullptr, nullptr, &provider);
78 interpolator.markAsUnitTest();
79
80 provider.insertNewAircraftParts(cs, parts, false); // we work with 0 offsets here
81 QVERIFY2(provider.remoteAircraftPartsCount(cs) == parts.size(), "Wrong parts size");
82
83 CInterpolationResult result = interpolator.getInterpolation(farFuture, setup, 0);
84 CAircraftParts p = result;
85 qint64 pTs = p.getAdjustedMSecsSinceEpoch();
86 QVERIFY2(result.getPartsStatus().isSupportingParts(), "Should support parts");
87 QVERIFY2(pTs == ts, "Expect latest ts");
88 result = interpolator.getInterpolation(farPast, setup, 0);
89 p = result;
91 QVERIFY2(result.getPartsStatus().isSupportingParts(), "Should support parts");
92 QVERIFY2(pTs == oldestTs, "Expect oldest ts");
93 }
94
95 // Testing for a time >> last time
96 // all on ground flags false
97 {
98 provider.clear();
99
100 CInterpolatorSpline interpolator(cs, nullptr, nullptr, &provider);
101 interpolator.markAsUnitTest();
102
103 parts.setOnGround(false);
104 provider.insertNewAircraftParts(cs, parts, false); // we work with 0 offsets here
105 CInterpolationResult result = interpolator.getInterpolation(farFuture, setup, 0);
106 CAircraftParts p = result;
107 qint64 pTs = p.getAdjustedMSecsSinceEpoch();
108 QVERIFY2(result.getPartsStatus().isSupportingParts(), "Should support parts");
109 QVERIFY2(p.getAdjustedMSecsSinceEpoch() == pTs, "Expect latest ts");
110 }
111 }
112
113 void CTestInterpolatorParts::partsToSituationGndFlag()
114 {
115 CCallsign cs("SWIFT");
116
117 // fixed time so everything can be debugged
118 const qint64 ts = 1425000000000; // QDateTime::currentMSecsSinceEpoch()
119 const qint64 deltaT = 5000; // ms
120 const int number = 10;
121
122 CAircraftPartsList partsOnGround;
123 for (int i = 0; i < number; i++)
124 {
125 const CAircraftParts p = createTestParts(i, ts, deltaT, true);
126 partsOnGround.push_back(p);
127 }
128
129 CAircraftPartsList partsNotOnGround;
130 for (int i = 0; i < number; i++)
131 {
132 const CAircraftParts p = createTestParts(i, ts, deltaT, false);
133 partsNotOnGround.push_back(p);
134 }
135
136 CAircraftSituationList situations;
137 for (int i = 0; i < number; i++)
138 {
139 CAircraftSituation s = createTestSituation(cs, i, ts, deltaT, 0);
140 s.setOnGroundInfo({ COnGroundInfo::OnGroundSituationUnknown, COnGroundInfo::NotSetGroundDetails });
141 situations.push_back(s);
142 }
143
144 CAircraftSituation s0 = situations[0];
145 s0.adjustGroundFlag(partsOnGround, true);
146 QVERIFY2(s0.getOnGroundInfo().getOnGround(), "Supposed to be on ground");
147
148 s0 = situations[0];
149 s0.adjustGroundFlag(partsNotOnGround, true);
150 QVERIFY2(!s0.getOnGroundInfo().getOnGround(), "Supposed to be not on ground");
151
152 qint64 distanceMs = -1;
153 const qint64 Offset = 33;
154 partsOnGround.addMsecsToOffset(Offset);
155 CAircraftSituation s1 = situations[1];
156 s1.setOnGroundInfo({ COnGroundInfo::OnGroundSituationUnknown, COnGroundInfo::NotSetGroundDetails });
157 s1.adjustGroundFlag(partsOnGround, true, 0.1, &distanceMs);
158 QVERIFY2(s1.getOnGroundInfo().getOnGround(), "Supposed to be on ground");
159 QVERIFY2(distanceMs == deltaT - Offset, "Offset time wrong");
161 }
162
163 CAircraftParts CTestInterpolatorParts::createTestParts(int number, qint64 ts, qint64 deltaT, bool onGround)
164 {
165 CAircraftLights l(true, false, true, false, true, false);
166 CAircraftEngineList e(
167 { CAircraftEngine(1, true, 100), CAircraftEngine(2, false, 0), CAircraftEngine(3, true, 100) });
168 CAircraftParts p(l, true, 20, true, e, false);
169 p.setMSecsSinceEpoch(ts - deltaT * number); // values in past
170 p.setTimeOffsetMs(0);
171 p.setOnGround(onGround);
172 return p;
173 }
174
175 CAircraftSituation CTestInterpolatorParts::createTestSituation(const CCallsign &callsign, int number, qint64 ts,
176 qint64 deltaT, qint64 offset)
177 {
178 const CAltitude alt(number, CAltitude::MeanSeaLevel, CLengthUnit::m());
179 const CLatitude lat(number, CAngleUnit::deg());
180 const CLongitude lng(180.0 + number, CAngleUnit::deg());
181 const CHeading heading(number * 10, CHeading::True, CAngleUnit::deg());
182 const CAngle bank(number, CAngleUnit::deg());
183 const CAngle pitch(number, CAngleUnit::deg());
184 const CSpeed gs(number * 10, CSpeedUnit::km_h());
185 const CAltitude gndElev({ 0, CLengthUnit::m() }, CAltitude::MeanSeaLevel);
186 const CCoordinateGeodetic c(lat, lng, alt);
187 CAircraftSituation s(callsign, c, heading, pitch, bank, gs);
189 s.setMSecsSinceEpoch(ts - deltaT * number); // values in past
190 s.setTimeOffsetMs(offset);
191 return s;
192 }
193} // namespace MiscTest
194
197
198#include "testinterpolatorparts.moc"
199
static CAngleUnit deg()
Degrees.
Definition units.h:276
Aircraft parts interpolation, mainly ground flag interpolation.
size_type size() const
Returns number of elements in the sequence.
Definition sequence.h:273
void push_back(const T &value)
Appends an element at the end of the sequence.
Definition sequence.h:308
void setMSecsSinceEpoch(qint64 mSecsSinceEpoch)
Timestamp as ms value.
qint64 oldestTimestampMsecsSinceEpoch() const
Oldest timestamp.
qint64 getAdjustedMSecsSinceEpoch() const
Timestamp with offset added for interpolation.
void setTimeOffsetMs(qint64 offset)
Milliseconds to add to timestamp for interpolation.
void addMsecsToOffset(qint64 msToAdd)
Adds a time to all offset values.
Value object encapsulating information of aircraft's parts.
void setOnGround(bool onGround)
Set aircraft on ground.
Value object encapsulating a list of aircraft parts.
int setOnGround(bool onGround)
Set on ground for all entries.
Value object encapsulating information of an aircraft's situation.
bool setGroundElevation(const aviation::CAltitude &altitude, GndElevationInfo info, bool transferred=false)
Elevation of the ground directly beneath at the given situation.
aviation::COnGroundInfo getOnGroundInfo() const
On ground info.
void setOnGroundInfo(const aviation::COnGroundInfo &info)
Set the on ground info.
bool adjustGroundFlag(const CAircraftParts &parts, bool alwaysSetDetails, double timeDeviationFactor=0.1, qint64 *differenceMs=nullptr)
Transfer ground flag from parts.
Value object encapsulating information of a callsign.
Definition callsign.h:30
@ InFromParts
set from aircraft parts
@ NotSetGroundDetails
not set or unknown if correct (e.g.
IsOnGround getOnGround() const
Is on ground?
OnGroundDetails getGroundDetails() const
Get ground details.
static CLengthUnit m()
Meter m.
Definition units.h:140
static CSpeedUnit km_h()
Kilometer/hour km/h.
Definition units.h:852
Value object for interpolator and rendering per callsign.
const CPartsStatus & getPartsStatus() const
Get status.
bool isSupportingParts() const
Supporting parts.
Definition partsstatus.h:26
void insertNewAircraftParts(const aviation::CCallsign &callsign, const aviation::CAircraftParts &parts, bool removeOutdatedParts)
For testing, add new situation and fire signals.
int remoteAircraftPartsCount(const aviation::CCallsign &callsign) const
All parts (per callsign, time history).
static constexpr int MaxPartsPerCallsign
How many parts we keep per callsign.
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