From 0f9b275f52b9c2b41180a27eea63da990b14e4f7 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Fri, 11 May 2018 03:06:05 +0200 Subject: [PATCH] Allow to mark interpolator for unit tests (which can be used to disable some checks) --- src/blackmisc/simulation/interpolator.cpp | 7 +++++-- src/blackmisc/simulation/interpolator.h | 4 ++++ tests/blackmisc/testinterpolatorlinear.cpp | 1 + tests/blackmisc/testinterpolatorparts.cpp | 1 + 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/blackmisc/simulation/interpolator.cpp b/src/blackmisc/simulation/interpolator.cpp index 6465d5bfb..ec4a16e0d 100644 --- a/src/blackmisc/simulation/interpolator.cpp +++ b/src/blackmisc/simulation/interpolator.cpp @@ -147,9 +147,12 @@ namespace BlackMisc CInterpolationResult result; do { - if (!this->initIniterpolationStepData(currentTimeSinceEpoc, setup)) { break; } + if (!this->initIniterpolationStepData(currentTimeSinceEpoc, setup)) + { + // make sure we can also interpolate parts only (needed in unit tests) + if (!m_unitTest) { break; } + } - // make sure we can also interpolate parts only (needed in unit tests for instance) const CAircraftSituation interpolatedSituation = this->getInterpolatedSituation(); const CAircraftParts interpolatedParts = this->getInterpolatedOrGuessedParts(); diff --git a/src/blackmisc/simulation/interpolator.h b/src/blackmisc/simulation/interpolator.h index f15b36e89..1a8bab501 100644 --- a/src/blackmisc/simulation/interpolator.h +++ b/src/blackmisc/simulation/interpolator.h @@ -204,6 +204,9 @@ namespace BlackMisc //! \remark either by passing a model or using the provider void initCorrespondingModel(const CAircraftModel &model = {}); + //! Mark as unit test + void markAsUnitTest() { m_unitTest = true; } + protected: //! Constructor CInterpolator(const Aviation::CCallsign &callsign, @@ -249,6 +252,7 @@ namespace BlackMisc qint64 m_situationsLastModifiedUsed { -1 }; //!< interpolant based on situations last updated int m_interpolatedSituationsCounter { 0 }; //!< counter for each interpolated situations: statistics, every n-th interpolation .... + bool m_unitTest = false; //!< mark as unit test //! Verify gnd flag, times, ... true means "OK" bool verifyInterpolationSituations(const Aviation::CAircraftSituation &oldest, const Aviation::CAircraftSituation &newer, const Aviation::CAircraftSituation &latest, diff --git a/tests/blackmisc/testinterpolatorlinear.cpp b/tests/blackmisc/testinterpolatorlinear.cpp index c9dd6b7a8..96a767427 100644 --- a/tests/blackmisc/testinterpolatorlinear.cpp +++ b/tests/blackmisc/testinterpolatorlinear.cpp @@ -57,6 +57,7 @@ namespace BlackMiscTest CCallsign cs("SWIFT"); CRemoteAircraftProviderDummy provider; CInterpolatorLinear interpolator(cs, nullptr, nullptr, &provider); + // interpolator.markAsUnitTest(); // fixed time so everything can be debugged const qint64 ts = 1425000000000; // QDateTime::currentMSecsSinceEpoch(); diff --git a/tests/blackmisc/testinterpolatorparts.cpp b/tests/blackmisc/testinterpolatorparts.cpp index a741688a3..f25f068a2 100644 --- a/tests/blackmisc/testinterpolatorparts.cpp +++ b/tests/blackmisc/testinterpolatorparts.cpp @@ -33,6 +33,7 @@ namespace BlackMiscTest CCallsign cs("SWIFT"); CRemoteAircraftProviderDummy provider; CInterpolatorSpline interpolator(cs, nullptr, nullptr, &provider); + interpolator.markAsUnitTest(); // fixed time so everything can be debugged const qint64 ts = 1425000000000; // QDateTime::currentMSecsSinceEpoch()