##// END OF EJS Templates
Fixed tests due to async var creation, plus minor stuff...
Fixed tests due to async var creation, plus minor stuff A variable is created synchronously but its data is get in background so tests have now to wait until the variable is ready before checking its state. VC should have a [] operator, it's a model feature. The new data provider interface implies that each call only ask for one range, this has been reflected in its parameters. Signed-off-by: Alexis Jeandet <alexis.jeandet@member.fsf.org>

File last commit:

r30:02d2d8643fcb
r30:02d2d8643fcb
Show More
TestProviders.h
83 lines | 2.3 KiB | text/x-c | CLexer
More VC2 tests refactoring...
r5 #ifndef TESTPROVIDER_H
#define TESTPROVIDER_H
#include <memory>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <QUuid>
#include <QtGlobal>
#include <QtTest>
#include <Data/IDataProvider.h>
#include <Data/DataProviderParameters.h>
#include <Data/DataSeries.h>
#include <Data/ScalarSeries.h>
#include <Variable/Variable.h>
template<int slope>
class SimpleRange: public IDataProvider
{
public:
SimpleRange() = default;
Added basic cache tests for new VC...
r11 int callCounter = 0;
More VC2 tests refactoring...
r5 std::shared_ptr<IDataProvider> clone() const override{ return std::make_shared<SimpleRange>(); }
IDataSeries* getData(const DataProviderParameters &parameters) override
{
Added basic cache tests for new VC...
r11 callCounter+=1;
Fixed tests due to async var creation, plus minor stuff...
r30 auto tstart = parameters.m_Range.m_TStart;
auto tend = parameters.m_Range.m_TEnd;
More VC2 tests refactoring...
r5 std::vector<double> x;
std::vector<double> y;
for(double i = ceil(tstart);i<=floor(tend);i+=1.) //1 seconde data resolution
{
x.push_back(i);
y.push_back(i*slope);
}
auto serie = new ScalarSeries(std::move(x),std::move(y),Unit("Secondes",true),Unit("Volts",false));
return serie;
}
};
template <class T>
auto sumdiff(T begin, T end)
{
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);
}
template <int slope=1>
struct RangeType
{
static void check_properties(std::shared_ptr<Variable> v, DateTimeRange r)
{
auto bounds = v->dataSeries()->valuesBounds(r.m_TStart, r.m_TEnd);
auto s = sumdiff(bounds.first, bounds.second) / slope;
auto nbpoints = bounds.second - bounds.first+1.;
QCOMPARE(nbpoints, int(s)+2);//<- @TODO weird has to be investigated why +2?
QCOMPARE(bounds.first->x(), bounds.first->value()/slope);
}
};
template <class T>
void check_variable_state(std::shared_ptr<Variable> v, DateTimeRange r)
{
auto bounds = v->dataSeries()->valuesBounds(r.m_TStart, r.m_TEnd);
//generated data has to be inside range
QVERIFY(bounds.first->x() >= r.m_TStart);
QVERIFY(bounds.second->x() <= r.m_TEnd);
T::check_properties(v,r);
}
#endif