TestProviders.h
71 lines
| 1.9 KiB
| text/x-c
|
CLexer
r5 | #ifndef TESTPROVIDER_H | |||
#define TESTPROVIDER_H | ||||
#include <Data/DataProviderParameters.h> | ||||
#include <Data/DataSeries.h> | ||||
r67 | #include <Data/IDataProvider.h> | |||
r5 | #include <Data/ScalarSeries.h> | |||
r67 | #include <Data/ScalarTimeSerie.h> | |||
#include <QUuid> | ||||
#include <QtGlobal> | ||||
#include <QtTest> | ||||
#include <TimeSeries.h> | ||||
#include <Variable/Variable2.h> | ||||
#include <algorithm> | ||||
#include <cmath> | ||||
#include <memory> | ||||
#include <numeric> | ||||
r5 | ||||
r67 | template<int slope> class SimpleRange : public IDataProvider | |||
r5 | { | |||
public: | ||||
r67 | SimpleRange() = default; | |||
r5 | ||||
r67 | int callCounter = 0; | |||
std::shared_ptr<IDataProvider> clone() const override | ||||
{ | ||||
return std::make_shared<SimpleRange>(); | ||||
} | ||||
r5 | ||||
r67 | TimeSeries::ITimeSerie* | |||
getData(const DataProviderParameters& parameters) override | ||||
{ | ||||
callCounter += 1; | ||||
std::size_t size = | ||||
static_cast<std::size_t>(floor(parameters.m_Range.m_TEnd) - | ||||
ceil(parameters.m_Range.m_TStart) + 1.); | ||||
auto serie = new ScalarTimeSerie(size); | ||||
std::generate(std::begin(*serie), std::end(*serie), | ||||
[i = ceil(parameters.m_Range.m_TStart)]() mutable { | ||||
r68 | return std::pair<double, double>{i, i++ * slope}; | |||
r67 | }); | |||
return serie; | ||||
} | ||||
r5 | }; | |||
r67 | template<class T> auto sumdiff(T begin, T end) | |||
r5 | { | |||
r67 | std::vector<double> diff_vect(end - begin - 1); | |||
auto diff = [](auto next, auto item) { return next.value() - item.value(); }; | ||||
std::transform(begin + 1, end, begin, diff_vect.begin(), diff); | ||||
return std::accumulate(diff_vect.cbegin(), diff_vect.cend(), 0); | ||||
r5 | } | |||
r67 | template<int slope = 1> struct RangeType | |||
r5 | { | |||
r67 | static void check_properties(std::shared_ptr<Variable2> v, DateTimeRange r) | |||
{ | ||||
// TODO | ||||
} | ||||
r5 | }; | |||
r67 | template<class T> | |||
void check_variable_state(std::shared_ptr<Variable2> v, DateTimeRange r) | ||||
r5 | { | |||
r68 | auto range = v->data()->axis_range(0); | |||
QVERIFY(range.first >= r.m_TStart); | ||||
QVERIFY(range.second <= r.m_TEnd); | ||||
r67 | T::check_properties(v, r); | |||
r5 | } | |||
#endif | ||||