##// END OF EJS Templates
Add correction for TestVariable
perrinel -
r825:3b8725ae29c0
parent child
Show More
@@ -1,409 +1,409
1 #include <Variable/Variable.h>
1 #include <Variable/Variable.h>
2
2
3 #include <Data/ScalarSeries.h>
3 #include <Data/ScalarSeries.h>
4
4
5 #include <QObject>
5 #include <QObject>
6 #include <QtTest>
6 #include <QtTest>
7
7
8 #include <memory>
8 #include <memory>
9
9
10 namespace {
10 namespace {
11
11
12 /// Generates a date in double
12 /// Generates a date in double
13 auto date = [](int year, int month, int day, int hours, int minutes, int seconds) {
13 auto date = [](int year, int month, int day, int hours, int minutes, int seconds) {
14 return DateUtils::secondsSinceEpoch(
14 return DateUtils::secondsSinceEpoch(
15 QDateTime{{year, month, day}, {hours, minutes, seconds}, Qt::UTC});
15 QDateTime{{year, month, day}, {hours, minutes, seconds}, Qt::UTC});
16 };
16 };
17
17
18 /// Generates a series of test data for a range
18 /// Generates a series of test data for a range
19 std::shared_ptr<ScalarSeries> dataSeries(const SqpRange &range)
19 std::shared_ptr<ScalarSeries> dataSeries(const SqpRange &range)
20 {
20 {
21 auto xAxisData = std::vector<double>{};
21 auto xAxisData = std::vector<double>{};
22 auto valuesData = std::vector<double>{};
22 auto valuesData = std::vector<double>{};
23
23
24 auto value = 0;
24 auto value = 0;
25 for (auto x = range.m_TStart; x <= range.m_TEnd; ++x, ++value) {
25 for (auto x = range.m_TStart; x <= range.m_TEnd; ++x, ++value) {
26 xAxisData.push_back(x);
26 xAxisData.push_back(x);
27 valuesData.push_back(value);
27 valuesData.push_back(value);
28 }
28 }
29
29
30 return std::make_shared<ScalarSeries>(std::move(xAxisData), std::move(valuesData), Unit{},
30 return std::make_shared<ScalarSeries>(std::move(xAxisData), std::move(valuesData), Unit{},
31 Unit{});
31 Unit{});
32 }
32 }
33
33
34 } // namespace
34 } // namespace
35
35
36 Q_DECLARE_METATYPE(std::shared_ptr<ScalarSeries>)
36 Q_DECLARE_METATYPE(std::shared_ptr<ScalarSeries>)
37
37
38 class TestVariable : public QObject {
38 class TestVariable : public QObject {
39 Q_OBJECT
39 Q_OBJECT
40
40
41 private slots:
41 private slots:
42 void testClone_data();
42 void testClone_data();
43 void testClone();
43 void testClone();
44
44
45 void testNotInCacheRangeList();
45 void testNotInCacheRangeList();
46 void testInCacheRangeList();
46 void testInCacheRangeList();
47
47
48 void testNbPoints_data();
48 void testNbPoints_data();
49 void testNbPoints();
49 void testNbPoints();
50
50
51 void testRealRange_data();
51 void testRealRange_data();
52 void testRealRange();
52 void testRealRange();
53 };
53 };
54
54
55 void TestVariable::testClone_data()
55 void TestVariable::testClone_data()
56 {
56 {
57 // ////////////// //
57 // ////////////// //
58 // Test structure //
58 // Test structure //
59 // ////////////// //
59 // ////////////// //
60
60
61 QTest::addColumn<QString>("name");
61 QTest::addColumn<QString>("name");
62 QTest::addColumn<QVariantHash>("metadata");
62 QTest::addColumn<QVariantHash>("metadata");
63 QTest::addColumn<SqpRange>("range");
63 QTest::addColumn<SqpRange>("range");
64 QTest::addColumn<SqpRange>("cacheRange");
64 QTest::addColumn<SqpRange>("cacheRange");
65 QTest::addColumn<std::shared_ptr<ScalarSeries> >("dataSeries");
65 QTest::addColumn<std::shared_ptr<ScalarSeries> >("dataSeries");
66
66
67 // ////////// //
67 // ////////// //
68 // Test cases //
68 // Test cases //
69 // ////////// //
69 // ////////// //
70
70
71 auto cacheRange = SqpRange{date(2017, 1, 1, 12, 0, 0), date(2017, 1, 1, 13, 0, 0)};
71 auto cacheRange = SqpRange{date(2017, 1, 1, 12, 0, 0), date(2017, 1, 1, 13, 0, 0)};
72 QTest::newRow("clone1") << QStringLiteral("var1")
72 QTest::newRow("clone1") << QStringLiteral("var1")
73 << QVariantHash{{"data1", 1}, {"data2", "abc"}}
73 << QVariantHash{{"data1", 1}, {"data2", "abc"}}
74 << SqpRange{date(2017, 1, 1, 12, 30, 0), (date(2017, 1, 1, 12, 45, 0))}
74 << SqpRange{date(2017, 1, 1, 12, 30, 0), (date(2017, 1, 1, 12, 45, 0))}
75 << cacheRange << dataSeries(cacheRange);
75 << cacheRange << dataSeries(cacheRange);
76 }
76 }
77
77
78 void TestVariable::testClone()
78 void TestVariable::testClone()
79 {
79 {
80 // Creates variable
80 // Creates variable
81 QFETCH(QString, name);
81 QFETCH(QString, name);
82 QFETCH(QVariantHash, metadata);
82 QFETCH(QVariantHash, metadata);
83 QFETCH(SqpRange, range);
83 QFETCH(SqpRange, range);
84 QFETCH(SqpRange, cacheRange);
84 QFETCH(SqpRange, cacheRange);
85 QFETCH(std::shared_ptr<ScalarSeries>, dataSeries);
85 QFETCH(std::shared_ptr<ScalarSeries>, dataSeries);
86
86
87 Variable variable{name, metadata};
87 Variable variable{name, metadata};
88 variable.setRange(range);
88 variable.setRange(range);
89 variable.setCacheRange(cacheRange);
89 variable.setCacheRange(cacheRange);
90 variable.mergeDataSeries(dataSeries);
90 variable.mergeDataSeries(dataSeries);
91
91
92 // Clones variable
92 // Clones variable
93 auto clone = variable.clone();
93 auto clone = variable.clone();
94
94
95 // Checks cloned variable's state
95 // Checks cloned variable's state
96 QCOMPARE(clone->name(), name);
96 QCOMPARE(clone->name(), name);
97 QCOMPARE(clone->metadata(), metadata);
97 QCOMPARE(clone->metadata(), metadata);
98 QCOMPARE(clone->range(), range);
98 QCOMPARE(clone->range(), range);
99 QCOMPARE(clone->cacheRange(), cacheRange);
99 QCOMPARE(clone->cacheRange(), cacheRange);
100
100
101 // Compares data series
101 // Compares data series
102 if (dataSeries != nullptr) {
102 if (dataSeries != nullptr) {
103 QVERIFY(clone->dataSeries() != nullptr);
103 QVERIFY(clone->dataSeries() != nullptr);
104 QVERIFY(std::equal(dataSeries->cbegin(), dataSeries->cend(), clone->dataSeries()->cbegin(),
104 QVERIFY(std::equal(dataSeries->cbegin(), dataSeries->cend(), clone->dataSeries()->cbegin(),
105 clone->dataSeries()->cend(), [](const auto &it1, const auto &it2) {
105 clone->dataSeries()->cend(), [](const auto &it1, const auto &it2) {
106 return it1.x() == it2.x() && it1.value() == it2.value();
106 return it1.x() == it2.x() && it1.value() == it2.value();
107 }));
107 }));
108 }
108 }
109 else {
109 else {
110 QVERIFY(clone->dataSeries() == nullptr);
110 QVERIFY(clone->dataSeries() == nullptr);
111 }
111 }
112 }
112 }
113
113
114 void TestVariable::testNotInCacheRangeList()
114 void TestVariable::testNotInCacheRangeList()
115 {
115 {
116 auto varRS = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 20, 0}};
116 auto varRS = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 20, 0}};
117 auto varRE = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 40, 0}};
117 auto varRE = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 40, 0}};
118
118
119 auto sqpR = SqpRange{DateUtils::secondsSinceEpoch(varRS), DateUtils::secondsSinceEpoch(varRE)};
119 auto sqpR = SqpRange{DateUtils::secondsSinceEpoch(varRS), DateUtils::secondsSinceEpoch(varRE)};
120
120
121 auto varCRS = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 0, 0}};
121 auto varCRS = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 0, 0}};
122 auto varCRE = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}};
122 auto varCRE = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}};
123
123
124 auto sqpCR
124 auto sqpCR
125 = SqpRange{DateUtils::secondsSinceEpoch(varCRS), DateUtils::secondsSinceEpoch(varCRE)};
125 = SqpRange{DateUtils::secondsSinceEpoch(varCRS), DateUtils::secondsSinceEpoch(varCRE)};
126
126
127 Variable var{"Var test"};
127 Variable var{"Var test"};
128 var.setRange(sqpR);
128 var.setRange(sqpR);
129 var.setCacheRange(sqpCR);
129 var.setCacheRange(sqpCR);
130
130
131 // 1: [ts,te] < varTS
131 // 1: [ts,te] < varTS
132 auto ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}};
132 auto ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}};
133 auto te = QDateTime{QDate{2017, 01, 01}, QTime{2, 1, 0, 0}};
133 auto te = QDateTime{QDate{2017, 01, 01}, QTime{2, 1, 0, 0}};
134 auto sqp = SqpRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)};
134 auto sqp = SqpRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)};
135
135
136 auto notInCach = var.provideNotInCacheRangeList(sqp);
136 auto notInCach = var.provideNotInCacheRangeList(sqp);
137
137
138 QCOMPARE(notInCach.size(), 1);
138 QCOMPARE(notInCach.size(), 1);
139
139
140 auto notInCachRange = notInCach.first();
140 auto notInCachRange = notInCach.first();
141
141
142 QCOMPARE(notInCachRange.m_TStart, DateUtils::secondsSinceEpoch(ts));
142 QCOMPARE(notInCachRange.m_TStart, DateUtils::secondsSinceEpoch(ts));
143 QCOMPARE(notInCachRange.m_TEnd, DateUtils::secondsSinceEpoch(te));
143 QCOMPARE(notInCachRange.m_TEnd, DateUtils::secondsSinceEpoch(te));
144
144
145 // 2: ts < varTS < te < varTE
145 // 2: ts < varTS < te < varTE
146 ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}};
146 ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}};
147 te = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 30, 0}};
147 te = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 30, 0}};
148 sqp = SqpRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)};
148 sqp = SqpRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)};
149 notInCach = var.provideNotInCacheRangeList(sqp);
149 notInCach = var.provideNotInCacheRangeList(sqp);
150 QCOMPARE(notInCach.size(), 1);
150 QCOMPARE(notInCach.size(), 1);
151 notInCachRange = notInCach.first();
151 notInCachRange = notInCach.first();
152 QCOMPARE(notInCachRange.m_TStart, DateUtils::secondsSinceEpoch(ts));
152 QCOMPARE(notInCachRange.m_TStart, DateUtils::secondsSinceEpoch(ts));
153 QCOMPARE(notInCachRange.m_TEnd, DateUtils::secondsSinceEpoch(varCRS));
153 QCOMPARE(notInCachRange.m_TEnd, DateUtils::secondsSinceEpoch(varCRS));
154
154
155 // 3: varTS < ts < te < varTE
155 // 3: varTS < ts < te < varTE
156 ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 20, 0}};
156 ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 20, 0}};
157 te = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 30, 0}};
157 te = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 30, 0}};
158 sqp = SqpRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)};
158 sqp = SqpRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)};
159 notInCach = var.provideNotInCacheRangeList(sqp);
159 notInCach = var.provideNotInCacheRangeList(sqp);
160 QCOMPARE(notInCach.size(), 0);
160 QCOMPARE(notInCach.size(), 0);
161
161
162
162
163 // 4: varTS < ts < varTE < te
163 // 4: varTS < ts < varTE < te
164 ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 20, 0}};
164 ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 20, 0}};
165 te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}};
165 te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}};
166 sqp = SqpRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)};
166 sqp = SqpRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)};
167 notInCach = var.provideNotInCacheRangeList(sqp);
167 notInCach = var.provideNotInCacheRangeList(sqp);
168 QCOMPARE(notInCach.size(), 1);
168 QCOMPARE(notInCach.size(), 1);
169 notInCachRange = notInCach.first();
169 notInCachRange = notInCach.first();
170 QCOMPARE(notInCachRange.m_TStart, DateUtils::secondsSinceEpoch(varCRE));
170 QCOMPARE(notInCachRange.m_TStart, DateUtils::secondsSinceEpoch(varCRE));
171 QCOMPARE(notInCachRange.m_TEnd, DateUtils::secondsSinceEpoch(te));
171 QCOMPARE(notInCachRange.m_TEnd, DateUtils::secondsSinceEpoch(te));
172
172
173 // 5: varTS < varTE < ts < te
173 // 5: varTS < varTE < ts < te
174 ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 20, 0}};
174 ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 20, 0}};
175 te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}};
175 te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}};
176 sqp = SqpRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)};
176 sqp = SqpRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)};
177 notInCach = var.provideNotInCacheRangeList(sqp);
177 notInCach = var.provideNotInCacheRangeList(sqp);
178 QCOMPARE(notInCach.size(), 1);
178 QCOMPARE(notInCach.size(), 1);
179 notInCachRange = notInCach.first();
179 notInCachRange = notInCach.first();
180 QCOMPARE(notInCachRange.m_TStart, DateUtils::secondsSinceEpoch(ts));
180 QCOMPARE(notInCachRange.m_TStart, DateUtils::secondsSinceEpoch(ts));
181 QCOMPARE(notInCachRange.m_TEnd, DateUtils::secondsSinceEpoch(te));
181 QCOMPARE(notInCachRange.m_TEnd, DateUtils::secondsSinceEpoch(te));
182
182
183 // 6: ts <varTS < varTE < te
183 // 6: ts <varTS < varTE < te
184 ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 1, 0, 0}};
184 ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 1, 0, 0}};
185 te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}};
185 te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}};
186 sqp = SqpRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)};
186 sqp = SqpRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)};
187 notInCach = var.provideNotInCacheRangeList(sqp);
187 notInCach = var.provideNotInCacheRangeList(sqp);
188 QCOMPARE(notInCach.size(), 2);
188 QCOMPARE(notInCach.size(), 2);
189 notInCachRange = notInCach.first();
189 notInCachRange = notInCach.first();
190 QCOMPARE(notInCachRange.m_TStart, DateUtils::secondsSinceEpoch(ts));
190 QCOMPARE(notInCachRange.m_TStart, DateUtils::secondsSinceEpoch(ts));
191 QCOMPARE(notInCachRange.m_TEnd, DateUtils::secondsSinceEpoch(varCRS));
191 QCOMPARE(notInCachRange.m_TEnd, DateUtils::secondsSinceEpoch(varCRS));
192 notInCachRange = notInCach[1];
192 notInCachRange = notInCach[1];
193 QCOMPARE(notInCachRange.m_TStart, DateUtils::secondsSinceEpoch(varCRE));
193 QCOMPARE(notInCachRange.m_TStart, DateUtils::secondsSinceEpoch(varCRE));
194 QCOMPARE(notInCachRange.m_TEnd, DateUtils::secondsSinceEpoch(te));
194 QCOMPARE(notInCachRange.m_TEnd, DateUtils::secondsSinceEpoch(te));
195 }
195 }
196
196
197
197
198 void TestVariable::testInCacheRangeList()
198 void TestVariable::testInCacheRangeList()
199 {
199 {
200 auto varRS = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 20, 0}};
200 auto varRS = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 20, 0}};
201 auto varRE = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 40, 0}};
201 auto varRE = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 40, 0}};
202
202
203 auto sqpR = SqpRange{DateUtils::secondsSinceEpoch(varRS), DateUtils::secondsSinceEpoch(varRE)};
203 auto sqpR = SqpRange{DateUtils::secondsSinceEpoch(varRS), DateUtils::secondsSinceEpoch(varRE)};
204
204
205 auto varCRS = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 0, 0}};
205 auto varCRS = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 0, 0}};
206 auto varCRE = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}};
206 auto varCRE = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}};
207 auto sqpCR
207 auto sqpCR
208 = SqpRange{DateUtils::secondsSinceEpoch(varCRS), DateUtils::secondsSinceEpoch(varCRE)};
208 = SqpRange{DateUtils::secondsSinceEpoch(varCRS), DateUtils::secondsSinceEpoch(varCRE)};
209
209
210 Variable var{"Var test"};
210 Variable var{"Var test"};
211 var.setRange(sqpR);
211 var.setRange(sqpR);
212 var.setCacheRange(sqpCR);
212 var.setCacheRange(sqpCR);
213
213
214 // 1: [ts,te] < varTS
214 // 1: [ts,te] < varTS
215 auto ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}};
215 auto ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}};
216 auto te = QDateTime{QDate{2017, 01, 01}, QTime{2, 1, 0, 0}};
216 auto te = QDateTime{QDate{2017, 01, 01}, QTime{2, 1, 0, 0}};
217 auto sqp = SqpRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)};
217 auto sqp = SqpRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)};
218
218
219 auto notInCach = var.provideInCacheRangeList(sqp);
219 auto notInCach = var.provideInCacheRangeList(sqp);
220
220
221 QCOMPARE(notInCach.size(), 0);
221 QCOMPARE(notInCach.size(), 0);
222
222
223 // 2: ts < varTS < te < varTE
223 // 2: ts < varTS < te < varTE
224 ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}};
224 ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}};
225 te = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 30, 0}};
225 te = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 30, 0}};
226 sqp = SqpRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)};
226 sqp = SqpRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)};
227 notInCach = var.provideInCacheRangeList(sqp);
227 notInCach = var.provideInCacheRangeList(sqp);
228 QCOMPARE(notInCach.size(), 1);
228 QCOMPARE(notInCach.size(), 1);
229 auto notInCachRange = notInCach.first();
229 auto notInCachRange = notInCach.first();
230 QCOMPARE(notInCachRange.m_TStart, DateUtils::secondsSinceEpoch(varCRS));
230 QCOMPARE(notInCachRange.m_TStart, DateUtils::secondsSinceEpoch(varCRS));
231 QCOMPARE(notInCachRange.m_TEnd, DateUtils::secondsSinceEpoch(te));
231 QCOMPARE(notInCachRange.m_TEnd, DateUtils::secondsSinceEpoch(te));
232
232
233 // 3: varTS < ts < te < varTE
233 // 3: varTS < ts < te < varTE
234 ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 20, 0}};
234 ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 20, 0}};
235 te = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 30, 0}};
235 te = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 30, 0}};
236 sqp = SqpRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)};
236 sqp = SqpRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)};
237 notInCach = var.provideInCacheRangeList(sqp);
237 notInCach = var.provideInCacheRangeList(sqp);
238 QCOMPARE(notInCach.size(), 1);
238 QCOMPARE(notInCach.size(), 1);
239 notInCachRange = notInCach.first();
239 notInCachRange = notInCach.first();
240 QCOMPARE(notInCachRange.m_TStart, DateUtils::secondsSinceEpoch(ts));
240 QCOMPARE(notInCachRange.m_TStart, DateUtils::secondsSinceEpoch(ts));
241 QCOMPARE(notInCachRange.m_TEnd, DateUtils::secondsSinceEpoch(te));
241 QCOMPARE(notInCachRange.m_TEnd, DateUtils::secondsSinceEpoch(te));
242
242
243 // 4: varTS < ts < varTE < te
243 // 4: varTS < ts < varTE < te
244 ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 20, 0}};
244 ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 20, 0}};
245 te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}};
245 te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}};
246 sqp = SqpRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)};
246 sqp = SqpRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)};
247 notInCach = var.provideInCacheRangeList(sqp);
247 notInCach = var.provideInCacheRangeList(sqp);
248 QCOMPARE(notInCach.size(), 1);
248 QCOMPARE(notInCach.size(), 1);
249 notInCachRange = notInCach.first();
249 notInCachRange = notInCach.first();
250 QCOMPARE(notInCachRange.m_TStart, DateUtils::secondsSinceEpoch(ts));
250 QCOMPARE(notInCachRange.m_TStart, DateUtils::secondsSinceEpoch(ts));
251 QCOMPARE(notInCachRange.m_TEnd, DateUtils::secondsSinceEpoch(varCRE));
251 QCOMPARE(notInCachRange.m_TEnd, DateUtils::secondsSinceEpoch(varCRE));
252
252
253 // 5: varTS < varTE < ts < te
253 // 5: varTS < varTE < ts < te
254 ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 20, 0}};
254 ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 20, 0}};
255 te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}};
255 te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}};
256 sqp = SqpRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)};
256 sqp = SqpRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)};
257 notInCach = var.provideInCacheRangeList(sqp);
257 notInCach = var.provideInCacheRangeList(sqp);
258 QCOMPARE(notInCach.size(), 0);
258 QCOMPARE(notInCach.size(), 0);
259
259
260 // 6: ts <varTS < varTE < te
260 // 6: ts <varTS < varTE < te
261 ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 1, 0, 0}};
261 ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 1, 0, 0}};
262 te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}};
262 te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}};
263 sqp = SqpRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)};
263 sqp = SqpRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)};
264 notInCach = var.provideInCacheRangeList(sqp);
264 notInCach = var.provideInCacheRangeList(sqp);
265 QCOMPARE(notInCach.size(), 1);
265 QCOMPARE(notInCach.size(), 1);
266 notInCachRange = notInCach.first();
266 notInCachRange = notInCach.first();
267 QCOMPARE(notInCachRange.m_TStart, DateUtils::secondsSinceEpoch(varCRS));
267 QCOMPARE(notInCachRange.m_TStart, DateUtils::secondsSinceEpoch(varCRS));
268 QCOMPARE(notInCachRange.m_TEnd, DateUtils::secondsSinceEpoch(varCRE));
268 QCOMPARE(notInCachRange.m_TEnd, DateUtils::secondsSinceEpoch(varCRE));
269 }
269 }
270
270
271 namespace {
271 namespace {
272
272
273 /// Struct used to represent an operation for @sa TestVariable::testNbPoints()
273 /// Struct used to represent an operation for @sa TestVariable::testNbPoints()
274 struct NbPointsOperation {
274 struct NbPointsOperation {
275 SqpRange m_CacheRange; /// Range to set for the variable
275 SqpRange m_CacheRange; /// Range to set for the variable
276 std::shared_ptr<ScalarSeries> m_DataSeries; /// Series to merge in the variable
276 std::shared_ptr<ScalarSeries> m_DataSeries; /// Series to merge in the variable
277 int m_ExpectedNbPoints; /// Number of points in the variable expected after operation
277 int m_ExpectedNbPoints; /// Number of points in the variable expected after operation
278 };
278 };
279
279
280 using NbPointsOperations = std::vector<NbPointsOperation>;
280 using NbPointsOperations = std::vector<NbPointsOperation>;
281
281
282 } // namespace
282 } // namespace
283
283
284 Q_DECLARE_METATYPE(NbPointsOperations)
284 Q_DECLARE_METATYPE(NbPointsOperations)
285
285
286 void TestVariable::testNbPoints_data()
286 void TestVariable::testNbPoints_data()
287 {
287 {
288 // ////////////// //
288 // ////////////// //
289 // Test structure //
289 // Test structure //
290 // ////////////// //
290 // ////////////// //
291
291
292 QTest::addColumn<NbPointsOperations>("operations");
292 QTest::addColumn<NbPointsOperations>("operations");
293
293
294 // ////////// //
294 // ////////// //
295 // Test cases //
295 // Test cases //
296 // ////////// //
296 // ////////// //
297 NbPointsOperations operations{};
297 NbPointsOperations operations{};
298
298
299 // Sets cache range (expected nb points = series xAxis data + series values data)
299 // Sets cache range (expected nb points = series xAxis data + series values data)
300 auto cacheRange = SqpRange{date(2017, 1, 1, 12, 0, 0), date(2017, 1, 1, 12, 0, 9)};
300 auto cacheRange = SqpRange{date(2017, 1, 1, 12, 0, 0), date(2017, 1, 1, 12, 0, 9)};
301 operations.push_back({cacheRange, dataSeries(cacheRange), 20});
301 operations.push_back({cacheRange, dataSeries(cacheRange), 20});
302
302
303 // Doubles cache but don't add data series (expected nb points don't change)
303 // Doubles cache but don't add data series (expected nb points don't change)
304 cacheRange = SqpRange{date(2017, 1, 1, 12, 0, 0), date(2017, 1, 1, 12, 0, 19)};
304 cacheRange = SqpRange{date(2017, 1, 1, 12, 0, 0), date(2017, 1, 1, 12, 0, 19)};
305 operations.push_back({cacheRange, nullptr, 20});
305 operations.push_back({cacheRange, dataSeries(INVALID_RANGE), 20});
306
306
307 // Doubles cache and data series (expected nb points change)
307 // Doubles cache and data series (expected nb points change)
308 cacheRange = SqpRange{date(2017, 1, 1, 12, 0, 0), date(2017, 1, 1, 12, 0, 19)};
308 cacheRange = SqpRange{date(2017, 1, 1, 12, 0, 0), date(2017, 1, 1, 12, 0, 19)};
309 operations.push_back({cacheRange, dataSeries(cacheRange), 40});
309 operations.push_back({cacheRange, dataSeries(cacheRange), 40});
310
310
311 // Decreases cache (expected nb points decreases as the series is purged)
311 // Decreases cache (expected nb points decreases as the series is purged)
312 cacheRange = SqpRange{date(2017, 1, 1, 12, 0, 5), date(2017, 1, 1, 12, 0, 9)};
312 cacheRange = SqpRange{date(2017, 1, 1, 12, 0, 5), date(2017, 1, 1, 12, 0, 9)};
313 operations.push_back({cacheRange, nullptr, 10});
313 operations.push_back({cacheRange, dataSeries(INVALID_RANGE), 10});
314
314
315 QTest::newRow("nbPoints1") << operations;
315 QTest::newRow("nbPoints1") << operations;
316 }
316 }
317
317
318 void TestVariable::testNbPoints()
318 void TestVariable::testNbPoints()
319 {
319 {
320 // Creates variable
320 // Creates variable
321 Variable variable{"var"};
321 Variable variable{"var"};
322 QCOMPARE(variable.nbPoints(), 0);
322 QCOMPARE(variable.nbPoints(), 0);
323
323
324 QFETCH(NbPointsOperations, operations);
324 QFETCH(NbPointsOperations, operations);
325 for (const auto &operation : operations) {
325 for (const auto &operation : operations) {
326 // Sets cache range and merge data series
326 // Sets cache range and merge data series
327 variable.setCacheRange(operation.m_CacheRange);
327 variable.setCacheRange(operation.m_CacheRange);
328 if (operation.m_DataSeries != nullptr) {
328 if (operation.m_DataSeries != nullptr) {
329 variable.mergeDataSeries(operation.m_DataSeries);
329 variable.mergeDataSeries(operation.m_DataSeries);
330 }
330 }
331
331
332 // Checks nb points
332 // Checks nb points
333 QCOMPARE(variable.nbPoints(), operation.m_ExpectedNbPoints);
333 QCOMPARE(variable.nbPoints(), operation.m_ExpectedNbPoints);
334 }
334 }
335 }
335 }
336
336
337 namespace {
337 namespace {
338
338
339 /// Struct used to represent a range operation on a variable
339 /// Struct used to represent a range operation on a variable
340 /// @sa TestVariable::testRealRange()
340 /// @sa TestVariable::testRealRange()
341 struct RangeOperation {
341 struct RangeOperation {
342 SqpRange m_CacheRange; /// Range to set for the variable
342 SqpRange m_CacheRange; /// Range to set for the variable
343 std::shared_ptr<ScalarSeries> m_DataSeries; /// Series to merge in the variable
343 std::shared_ptr<ScalarSeries> m_DataSeries; /// Series to merge in the variable
344 SqpRange m_ExpectedRealRange; /// Real Range expected after operation on the variable
344 SqpRange m_ExpectedRealRange; /// Real Range expected after operation on the variable
345 };
345 };
346
346
347 using RangeOperations = std::vector<RangeOperation>;
347 using RangeOperations = std::vector<RangeOperation>;
348
348
349 } // namespace
349 } // namespace
350
350
351 Q_DECLARE_METATYPE(RangeOperations)
351 Q_DECLARE_METATYPE(RangeOperations)
352
352
353 void TestVariable::testRealRange_data()
353 void TestVariable::testRealRange_data()
354 {
354 {
355 // ////////////// //
355 // ////////////// //
356 // Test structure //
356 // Test structure //
357 // ////////////// //
357 // ////////////// //
358
358
359 QTest::addColumn<RangeOperations>("operations");
359 QTest::addColumn<RangeOperations>("operations");
360
360
361 // ////////// //
361 // ////////// //
362 // Test cases //
362 // Test cases //
363 // ////////// //
363 // ////////// //
364 RangeOperations operations{};
364 RangeOperations operations{};
365
365
366 // Inits cache range and data series (expected real range = cache range)
366 // Inits cache range and data series (expected real range = cache range)
367 auto cacheRange = SqpRange{date(2017, 1, 1, 12, 0, 0), date(2017, 1, 1, 13, 0, 0)};
367 auto cacheRange = SqpRange{date(2017, 1, 1, 12, 0, 0), date(2017, 1, 1, 13, 0, 0)};
368 operations.push_back({cacheRange, dataSeries(cacheRange), cacheRange});
368 operations.push_back({cacheRange, dataSeries(cacheRange), cacheRange});
369
369
370 // Changes cache range and updates data series (expected real range = cache range)
370 // Changes cache range and updates data series (expected real range = cache range)
371 cacheRange = SqpRange{date(2017, 1, 1, 14, 0, 0), date(2017, 1, 1, 15, 0, 0)};
371 cacheRange = SqpRange{date(2017, 1, 1, 14, 0, 0), date(2017, 1, 1, 15, 0, 0)};
372 operations.push_back({cacheRange, dataSeries(cacheRange), cacheRange});
372 operations.push_back({cacheRange, dataSeries(cacheRange), cacheRange});
373
373
374 // Changes cache range and update data series but with a lower range (expected real range =
374 // Changes cache range and update data series but with a lower range (expected real range =
375 // data series range)
375 // data series range)
376 cacheRange = SqpRange{date(2017, 1, 1, 12, 0, 0), date(2017, 1, 1, 16, 0, 0)};
376 cacheRange = SqpRange{date(2017, 1, 1, 12, 0, 0), date(2017, 1, 1, 16, 0, 0)};
377 auto dataSeriesRange = SqpRange{date(2017, 1, 1, 14, 0, 0), date(2017, 1, 1, 15, 0, 0)};
377 auto dataSeriesRange = SqpRange{date(2017, 1, 1, 14, 0, 0), date(2017, 1, 1, 15, 0, 0)};
378 operations.push_back({cacheRange, dataSeries(dataSeriesRange), dataSeriesRange});
378 operations.push_back({cacheRange, dataSeries(dataSeriesRange), dataSeriesRange});
379
379
380 // Changes cache range but DON'T update data series (expected real range = cache range
380 // Changes cache range but DON'T update data series (expected real range = cache range
381 // before operation)
381 // before operation)
382 cacheRange = SqpRange{date(2017, 1, 1, 10, 0, 0), date(2017, 1, 1, 17, 0, 0)};
382 cacheRange = SqpRange{date(2017, 1, 1, 10, 0, 0), date(2017, 1, 1, 17, 0, 0)};
383 operations.push_back({cacheRange, nullptr, dataSeriesRange});
383 operations.push_back({cacheRange, nullptr, dataSeriesRange});
384
384
385 QTest::newRow("realRange1") << operations;
385 QTest::newRow("realRange1") << operations;
386 }
386 }
387
387
388 void TestVariable::testRealRange()
388 void TestVariable::testRealRange()
389 {
389 {
390 // Creates variable (real range is invalid)
390 // Creates variable (real range is invalid)
391 Variable variable{"var"};
391 Variable variable{"var"};
392 QCOMPARE(variable.realRange(), INVALID_RANGE);
392 QCOMPARE(variable.realRange(), INVALID_RANGE);
393
393
394 QFETCH(RangeOperations, operations);
394 QFETCH(RangeOperations, operations);
395 for (const auto &operation : operations) {
395 for (const auto &operation : operations) {
396 // Sets cache range and merge data series
396 // Sets cache range and merge data series
397 variable.setCacheRange(operation.m_CacheRange);
397 variable.setCacheRange(operation.m_CacheRange);
398 if (operation.m_DataSeries != nullptr) {
398 if (operation.m_DataSeries != nullptr) {
399 variable.mergeDataSeries(operation.m_DataSeries);
399 variable.mergeDataSeries(operation.m_DataSeries);
400 }
400 }
401
401
402 // Checks real range
402 // Checks real range
403 QCOMPARE(variable.realRange(), operation.m_ExpectedRealRange);
403 QCOMPARE(variable.realRange(), operation.m_ExpectedRealRange);
404 }
404 }
405 }
405 }
406
406
407
407
408 QTEST_MAIN(TestVariable)
408 QTEST_MAIN(TestVariable)
409 #include "TestVariable.moc"
409 #include "TestVariable.moc"
General Comments 3
Under Review
author

Auto status change to "Under Review"

Approved
author

Merge lasted acquisition developpement on main Sciqlop branch

You need to be logged in to leave comments. Login now