From c061091bd2de03186ea24d9d96c87ff92f88f645 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Sun, 4 Mar 2018 22:24:39 +0100 Subject: [PATCH] Ref T259, Ref T243 unit test for parts --- tests/blackmisc/testblackmiscmain.cpp | 11 ++- tests/blackmisc/testinterpolatorparts.cpp | 93 +++++++++++++++++++++++ tests/blackmisc/testinterpolatorparts.h | 50 ++++++++++++ 3 files changed, 151 insertions(+), 3 deletions(-) create mode 100644 tests/blackmisc/testinterpolatorparts.cpp create mode 100644 tests/blackmisc/testinterpolatorparts.h diff --git a/tests/blackmisc/testblackmiscmain.cpp b/tests/blackmisc/testblackmiscmain.cpp index 353d97a5d..2a9ebbdb1 100644 --- a/tests/blackmisc/testblackmiscmain.cpp +++ b/tests/blackmisc/testblackmiscmain.cpp @@ -22,7 +22,8 @@ #include "testicon.h" #include "testidentifier.h" #include "testinput.h" -#include "testinterpolator.h" +#include "testinterpolatorlinear.h" +#include "testinterpolatorparts.h" #include "testlibrarypath.h" #include "testmath.h" #include "testphysicalquantities.h" @@ -113,8 +114,12 @@ namespace BlackMiscTest status |= test.exec(&mathTests, "blackmisc_math"); } { - CTestInterpolator interpolatorTests; - status |= test.exec(&interpolatorTests, "blackmisc_interpolator"); + CTestInterpolatorLinear interpolatorTests; + status |= test.exec(&interpolatorTests, "blackmisc_interpolatorlinear"); + } + { + CTestInterpolatorParts interpolatorParts; + status |= test.exec(&interpolatorParts, "blackmisc_interpolatorparts"); } { CTestLibraryPath libraryPathTests; diff --git a/tests/blackmisc/testinterpolatorparts.cpp b/tests/blackmisc/testinterpolatorparts.cpp new file mode 100644 index 000000000..02cc209f8 --- /dev/null +++ b/tests/blackmisc/testinterpolatorparts.cpp @@ -0,0 +1,93 @@ +/* Copyright (C) 2018 + * swift project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +//! \cond PRIVATE_TESTS + +/*! + * \file + * \ingroup testblackmisc + */ + +#include "testinterpolatorparts.h" +#include "blackmisc/simulation/interpolatorspline.h" +#include +#include + +using namespace BlackMisc; +using namespace BlackMisc::Aviation; +using namespace BlackMisc::Geo; +using namespace BlackMisc::PhysicalQuantities; +using namespace BlackMisc::Simulation; + +namespace BlackMiscTest +{ + void CTestInterpolatorParts::groundFlagInterpolation() + { + CCallsign cs("SWIFT"); + CInterpolatorSpline interpolator(cs); + + // fixed time so everything can be debugged + const qint64 ts = 1425000000000; // QDateTime::currentMSecsSinceEpoch() + const qint64 deltaT = 5000; // ms + const int number = interpolator.maxParts(); + // const int numberHalf = number / 2; + const qint64 farFuture = ts + 3 * number * deltaT; + const qint64 farPast = ts - 4 * number * deltaT; + + CAircraftPartsList parts; + for (int i = 0; i < number; i++) + { + const CAircraftParts p = getTestParts(i, ts, deltaT, true); + parts.push_back(p); + } + + // interpolation functional check + CPartsStatus status; + const CInterpolationAndRenderingSetup setup; + qint64 oldestTs = parts.oldestTimestampMsecsSinceEpoch(); + + // Testing for a time >> last time + // all on ground flags true + interpolator.addAircraftParts(parts, false); // we work with 0 offsets here + CAircraftParts p = interpolator.getInterpolatedParts(farFuture, setup, status); + qint64 pTs = p.getAdjustedMSecsSinceEpoch(); + QVERIFY2(status.isSupportingParts(), "Should support parts"); + QVERIFY2(pTs == ts, "Expect latest ts"); + QCOMPARE(p.isOnGroundInterpolated(), 1.0); + p = interpolator.getInterpolatedParts(farPast, setup, status); + pTs = p.getAdjustedMSecsSinceEpoch(); + QVERIFY2(status.isSupportingParts(), "Should support parts"); + QVERIFY2(pTs == oldestTs, "Expect oldest ts"); + QCOMPARE(p.isOnGroundInterpolated(), 1.0); + + // Testing for a time >> last time + // all on ground flags true + interpolator.clear(); + parts.setOnGround(false); + interpolator.addAircraftParts(parts, false); // we work with 0 offsets here + p = interpolator.getInterpolatedParts(farFuture, setup, status); + pTs = p.getAdjustedMSecsSinceEpoch(); + QVERIFY2(status.isSupportingParts(), "Should support parts"); + QVERIFY2(p.getAdjustedMSecsSinceEpoch() == pTs, "Expect latest ts"); + QCOMPARE(p.isOnGroundInterpolated(), 0.0); + } + + CAircraftParts CTestInterpolatorParts::getTestParts(int number, qint64 ts, qint64 deltaT, bool onGround) + { + CAircraftLights l(true, false, true, false, true, false); + CAircraftEngineList e({ CAircraftEngine(1, true), CAircraftEngine(2, false), CAircraftEngine(3, true) }); + CAircraftParts p(l, true, 20, true, e, false); + p.setMSecsSinceEpoch(ts - deltaT * number); // values in past + p.setTimeOffsetMs(0); + p.setOnGround(onGround); + return p; + } +} // namespace + +//! \endcond diff --git a/tests/blackmisc/testinterpolatorparts.h b/tests/blackmisc/testinterpolatorparts.h new file mode 100644 index 000000000..54005e4bc --- /dev/null +++ b/tests/blackmisc/testinterpolatorparts.h @@ -0,0 +1,50 @@ +/* Copyright (C) 2018 + * swift project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +#ifndef BLACKMISCTEST_TESTINTERPOLATORPARTS_H +#define BLACKMISCTEST_TESTINTERPOLATORPARTS_H + +//! \cond PRIVATE_TESTS + +/*! + * \file + * \ingroup testblackmisc + */ + +#include "blackmisc/aviation/aircraftparts.h" + +#include +#include + +namespace BlackMiscTest +{ + /*! + * Aircraft parts interpolation, mainly ground flag interpolation + */ + class CTestInterpolatorParts : public QObject + { + Q_OBJECT + + public: + //! Standard test case constructor + explicit CTestInterpolatorParts(QObject *parent = nullptr) : QObject(parent) {} + + private slots: + //! Basic unit tests for interpolator + void groundFlagInterpolation(); + + private: + //! Test parts + static BlackMisc::Aviation::CAircraftParts getTestParts(int number, qint64 ts, qint64 deltaT, bool onGround); + }; +} // namespace + +//! \endcond + +#endif // guard