ok with: or you could directly pass 0 in arg of the method
@@ -1,26 +1,33 | |||||
1 | #ifndef SCIQLOP_VARIABLECACHECONTROLLER_H |
|
1 | #ifndef SCIQLOP_VARIABLECACHECONTROLLER_H | |
2 | #define SCIQLOP_VARIABLECACHECONTROLLER_H |
|
2 | #define SCIQLOP_VARIABLECACHECONTROLLER_H | |
3 |
|
3 | |||
4 | #include <QObject> |
|
4 | #include <QObject> | |
5 |
|
5 | |||
6 | #include <Data/SqpDateTime.h> |
|
6 | #include <Data/SqpDateTime.h> | |
7 |
|
7 | |||
8 | #include <Common/spimpl.h> |
|
8 | #include <Common/spimpl.h> | |
9 |
|
9 | |||
10 | class Variable; |
|
10 | class Variable; | |
11 |
|
11 | |||
12 | /// This class aims to store in the cash all of the dateTime already requested to the variable. |
|
12 | /// This class aims to store in the cash all of the dateTime already requested to the variable. | |
13 | class VariableCacheController : public QObject { |
|
13 | class VariableCacheController : public QObject { | |
14 | Q_OBJECT |
|
14 | Q_OBJECT | |
15 | public: |
|
15 | public: | |
16 | explicit VariableCacheController(QObject *parent = 0); |
|
16 | explicit VariableCacheController(QObject *parent = 0); | |
17 |
|
17 | |||
18 |
|
18 | |||
19 | void addDateTime(std::shared_ptr<Variable> variable, const SqpDateTime &dateTime); |
|
19 | void addDateTime(std::shared_ptr<Variable> variable, const SqpDateTime &dateTime); | |
20 |
|
20 | |||
|
21 | /// Return all of the SqpDataTime part of the dateTime whose are not in the cache | |||
|
22 | QVector<SqpDateTime> provideNotInCacheDateTimeList(std::shared_ptr<Variable> variable, | |||
|
23 | const SqpDateTime &dateTime); | |||
|
24 | ||||
|
25 | ||||
|
26 | QVector<SqpDateTime> dateCacheList(std::shared_ptr<Variable> variable) const noexcept; | |||
|
27 | ||||
21 | private: |
|
28 | private: | |
22 | class VariableCacheControllerPrivate; |
|
29 | class VariableCacheControllerPrivate; | |
23 | spimpl::unique_impl_ptr<VariableCacheControllerPrivate> impl; |
|
30 | spimpl::unique_impl_ptr<VariableCacheControllerPrivate> impl; | |
24 | }; |
|
31 | }; | |
25 |
|
32 | |||
26 | #endif // SCIQLOP_VARIABLECACHECONTROLLER_H |
|
33 | #endif // SCIQLOP_VARIABLECACHECONTROLLER_H |
@@ -1,111 +1,173 | |||||
1 | #include "Variable/VariableCacheController.h" |
|
1 | #include "Variable/VariableCacheController.h" | |
2 |
|
2 | |||
3 | #include "Variable/Variable.h" |
|
3 | #include "Variable/Variable.h" | |
4 | #include <unordered_map> |
|
4 | #include <unordered_map> | |
5 |
|
5 | |||
6 | struct VariableCacheController::VariableCacheControllerPrivate { |
|
6 | struct VariableCacheController::VariableCacheControllerPrivate { | |
7 |
|
7 | |||
8 | std::unordered_map<std::shared_ptr<Variable>, QVector<SqpDateTime> > |
|
8 | std::unordered_map<std::shared_ptr<Variable>, QVector<SqpDateTime> > | |
9 | m_VariableToSqpDateTimeListMap; |
|
9 | m_VariableToSqpDateTimeListMap; | |
10 |
|
10 | |||
11 | void addInCacheDataByEnd(const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList, |
|
11 | void addInCacheDataByEnd(const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList, | |
12 | QVector<SqpDateTime> ¬InCache, int cacheIndex, |
|
12 | QVector<SqpDateTime> ¬InCache, int cacheIndex, | |
13 | double currentTStart); |
|
13 | double currentTStart); | |
14 |
|
14 | |||
15 | void addInCacheDataByStart(const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList, |
|
15 | void addInCacheDataByStart(const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList, | |
16 | QVector<SqpDateTime> ¬InCache, int cacheIndex, |
|
16 | QVector<SqpDateTime> ¬InCache, int cacheIndex, | |
17 | double currentTStart); |
|
17 | double currentTStart); | |
|
18 | ||||
|
19 | ||||
|
20 | void addDateTimeRecurse(const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList, | |||
|
21 | int cacheIndex); | |||
18 | }; |
|
22 | }; | |
19 |
|
23 | |||
20 |
|
24 | |||
21 | VariableCacheController::VariableCacheController(QObject *parent) |
|
25 | VariableCacheController::VariableCacheController(QObject *parent) | |
22 | : QObject(parent), impl{spimpl::make_unique_impl<VariableCacheControllerPrivate>()} |
|
26 | : QObject(parent), impl{spimpl::make_unique_impl<VariableCacheControllerPrivate>()} | |
23 | { |
|
27 | { | |
24 | } |
|
28 | } | |
25 |
|
29 | |||
26 | void VariableCacheController::addDateTime(std::shared_ptr<Variable> variable, |
|
30 | void VariableCacheController::addDateTime(std::shared_ptr<Variable> variable, | |
27 | const SqpDateTime &dateTime) |
|
31 | const SqpDateTime &dateTime) | |
28 | { |
|
32 | { | |
29 | if (variable) { |
|
33 | if (variable) { | |
30 | // TODO: squeeze the map to let it only some SqpDateTime without intersection |
|
34 | auto findVariableIte = impl->m_VariableToSqpDateTimeListMap.find(variable); | |
31 |
impl->m_VariableToSqpDateTimeListMap |
|
35 | if (findVariableIte == impl->m_VariableToSqpDateTimeListMap.end()) { | |
|
36 | impl->m_VariableToSqpDateTimeListMap[variable].push_back(dateTime); | |||
|
37 | } | |||
|
38 | else { | |||
|
39 | ||||
|
40 | // addDateTime modify the list<SqpDateTime> of the variable in a way to ensure | |||
|
41 | // that the list is ordered : l(0) < l(1). We assume also a < b | |||
|
42 | // (with a & b of type SqpDateTime) means ts(b) > te(a) | |||
|
43 | ||||
|
44 | // The algorithm will try the merge of two interval: | |||
|
45 | // - dateTime will be compare with the first interval of the list: | |||
|
46 | // A: if it is inferior, it will be inserted and it's finished. | |||
|
47 | // B: if it is in intersection, it will be merge then the merged one | |||
|
48 | // will be compared to the next interval. The old one is remove from the list | |||
|
49 | // C: if it is superior, we do the same with the next interval of the list | |||
|
50 | ||||
|
51 |
int cacheIndex = 0;
|
|||
|
52 | impl->addDateTimeRecurse(dateTime, impl->m_VariableToSqpDateTimeListMap.at(variable), | |||
|
53 | cacheIndex); | |||
|
54 | } | |||
32 | } |
|
55 | } | |
33 | } |
|
56 | } | |
34 |
|
57 | |||
35 | QVector<SqpDateTime> |
|
58 | QVector<SqpDateTime> | |
36 | VariableCacheController::provideNotInCacheDateTimeList(std::shared_ptr<Variable> variable, |
|
59 | VariableCacheController::provideNotInCacheDateTimeList(std::shared_ptr<Variable> variable, | |
37 | const SqpDateTime &dateTime) |
|
60 | const SqpDateTime &dateTime) | |
38 | { |
|
61 | { | |
39 | auto notInCache = QVector<SqpDateTime>{}; |
|
62 | auto notInCache = QVector<SqpDateTime>{}; | |
40 |
|
63 | |||
41 | // This algorithm is recursif. The idea is to localise the start time then the end time in the |
|
64 | // This algorithm is recursif. The idea is to localise the start time then the end time in the | |
42 | // list of date time request associated to the variable |
|
65 | // list of date time request associated to the variable | |
43 | // We assume that the list is ordered in a way that l(0) < l(1). We assume also a < b |
|
66 | // We assume that the list is ordered in a way that l(0) < l(1). We assume also a < b | |
44 | // (with a & b of type SqpDateTime) means ts(b) > te(a) |
|
67 | // (with a & b of type SqpDateTime) means ts(b) > te(a) | |
45 |
|
68 | |||
46 | impl->addInCacheDataByStart(dateTime, impl->m_VariableToSqpDateTimeListMap.at(variable), |
|
69 | impl->addInCacheDataByStart(dateTime, impl->m_VariableToSqpDateTimeListMap.at(variable), | |
47 | notInCache, 0, dateTime.m_TStart); |
|
70 | notInCache, 0, dateTime.m_TStart); | |
48 |
|
71 | |||
49 | return notInCache; |
|
72 | return notInCache; | |
50 | } |
|
73 | } | |
51 |
|
74 | |||
|
75 | QVector<SqpDateTime> | |||
|
76 | VariableCacheController::dateCacheList(std::shared_ptr<Variable> variable) const noexcept | |||
|
77 | { | |||
|
78 | return impl->m_VariableToSqpDateTimeListMap.at(variable); | |||
|
79 | } | |||
|
80 | ||||
|
81 | void VariableCacheController::VariableCacheControllerPrivate::addDateTimeRecurse( | |||
|
82 | const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList, int cacheIndex) | |||
|
83 | { | |||
|
84 | const auto dateTimeListSize = dateTimeList.count(); | |||
|
85 | if (cacheIndex >= dateTimeListSize) { | |||
|
86 | dateTimeList.push_back(dateTime); | |||
|
87 | // there is no anymore interval to compore, we can just push_back it | |||
|
88 | return; | |||
|
89 | } | |||
|
90 | ||||
|
91 | auto currentDateTime = dateTimeList[cacheIndex]; | |||
|
92 | ||||
|
93 | if (dateTime.m_TEnd < currentDateTime.m_TStart) { | |||
|
94 | // The compared one is < to current one compared, we can insert it | |||
|
95 | dateTimeList.insert(cacheIndex, dateTime); | |||
|
96 | } | |||
|
97 |
ok |
|||
|
98 | else if (dateTime.m_TStart > currentDateTime.m_TEnd) { | |||
|
99 | // The compared one is > to current one compared we can comparet if to the next one | |||
|
100 | addDateTimeRecurse(dateTime, dateTimeList, ++cacheIndex); | |||
|
101 | } | |||
|
102 | else { | |||
|
103 | // Merge cases: we need to merge the two interval, remove the old one from the list then | |||
|
104 | // rerun the algo from this index with the merged interval | |||
|
105 | auto mTStart = std::min(dateTime.m_TStart, currentDateTime.m_TStart); | |||
|
106 | auto mTEnd = std::max(dateTime.m_TEnd, currentDateTime.m_TEnd); | |||
|
107 | auto mergeDateTime = SqpDateTime{mTStart, mTEnd}; | |||
|
108 | ||||
|
109 | dateTimeList.remove(cacheIndex); | |||
|
110 | addDateTimeRecurse(mergeDateTime, dateTimeList, cacheIndex); | |||
|
111 | } | |||
|
112 | } | |||
|
113 | ||||
52 |
|
114 | |||
53 | void VariableCacheController::VariableCacheControllerPrivate::addInCacheDataByEnd( |
|
115 | void VariableCacheController::VariableCacheControllerPrivate::addInCacheDataByEnd( | |
54 | const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList, |
|
116 | const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList, | |
55 | QVector<SqpDateTime> ¬InCache, int cacheIndex, double currentTStart) |
|
117 | QVector<SqpDateTime> ¬InCache, int cacheIndex, double currentTStart) | |
56 | { |
|
118 | { | |
57 | const auto dateTimeListSize = dateTimeList.count(); |
|
119 | const auto dateTimeListSize = dateTimeList.count(); | |
58 | if (cacheIndex >= dateTimeListSize) { |
|
120 | if (cacheIndex >= dateTimeListSize) { | |
59 | if (currentTStart < dateTime.m_TEnd) { |
|
121 | if (currentTStart < dateTime.m_TEnd) { | |
60 |
|
122 | |||
61 | // te localised after all other interval: The last interval is [currentTsart, te] |
|
123 | // te localised after all other interval: The last interval is [currentTsart, te] | |
62 | notInCache.push_back(SqpDateTime{currentTStart, dateTime.m_TEnd}); |
|
124 | notInCache.push_back(SqpDateTime{currentTStart, dateTime.m_TEnd}); | |
63 | } |
|
125 | } | |
64 | return; |
|
126 | return; | |
65 | } |
|
127 | } | |
66 |
|
128 | |||
67 | auto currentDateTimeJ = dateTimeList[cacheIndex]; |
|
129 | auto currentDateTimeJ = dateTimeList[cacheIndex]; | |
68 | if (dateTime.m_TEnd <= currentDateTimeJ.m_TStart) { |
|
130 | if (dateTime.m_TEnd <= currentDateTimeJ.m_TStart) { | |
69 | // te localised between to interval: The last interval is [currentTsart, te] |
|
131 | // te localised between to interval: The last interval is [currentTsart, te] | |
70 | notInCache.push_back(SqpDateTime{currentTStart, dateTime.m_TEnd}); |
|
132 | notInCache.push_back(SqpDateTime{currentTStart, dateTime.m_TEnd}); | |
71 | } |
|
133 | } | |
72 | else { |
|
134 | else { | |
73 | notInCache.push_back(SqpDateTime{currentTStart, currentDateTimeJ.m_TStart}); |
|
135 | notInCache.push_back(SqpDateTime{currentTStart, currentDateTimeJ.m_TStart}); | |
74 | if (dateTime.m_TEnd > currentDateTimeJ.m_TEnd) { |
|
136 | if (dateTime.m_TEnd > currentDateTimeJ.m_TEnd) { | |
75 | // te not localised before the current interval: we need to look at the next interval |
|
137 | // te not localised before the current interval: we need to look at the next interval | |
76 | addInCacheDataByEnd(dateTime, dateTimeList, notInCache, ++cacheIndex, |
|
138 | addInCacheDataByEnd(dateTime, dateTimeList, notInCache, ++cacheIndex, | |
77 | currentDateTimeJ.m_TEnd); |
|
139 | currentDateTimeJ.m_TEnd); | |
78 | } |
|
140 | } | |
79 | } |
|
141 | } | |
80 | } |
|
142 | } | |
81 |
|
143 | |||
82 | void VariableCacheController::VariableCacheControllerPrivate::addInCacheDataByStart( |
|
144 | void VariableCacheController::VariableCacheControllerPrivate::addInCacheDataByStart( | |
83 | const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList, |
|
145 | const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList, | |
84 | QVector<SqpDateTime> ¬InCache, int cacheIndex, double currentTStart) |
|
146 | QVector<SqpDateTime> ¬InCache, int cacheIndex, double currentTStart) | |
85 | { |
|
147 | { | |
86 | const auto dateTimeListSize = dateTimeList.count(); |
|
148 | const auto dateTimeListSize = dateTimeList.count(); | |
87 | if (cacheIndex >= dateTimeListSize) { |
|
149 | if (cacheIndex >= dateTimeListSize) { | |
88 | // ts localised after all other interval: The last interval is [ts, te] |
|
150 | // ts localised after all other interval: The last interval is [ts, te] | |
89 | notInCache.push_back(SqpDateTime{currentTStart, dateTime.m_TEnd}); |
|
151 | notInCache.push_back(SqpDateTime{currentTStart, dateTime.m_TEnd}); | |
90 | return; |
|
152 | return; | |
91 | } |
|
153 | } | |
92 |
|
154 | |||
93 | auto currentDateTimeI = dateTimeList[cacheIndex]; |
|
155 | auto currentDateTimeI = dateTimeList[cacheIndex]; | |
94 | auto cacheIndexJ = cacheIndex; |
|
156 | auto cacheIndexJ = cacheIndex; | |
95 | if (currentTStart < currentDateTimeI.m_TStart) { |
|
157 | if (currentTStart < currentDateTimeI.m_TStart) { | |
96 |
|
158 | |||
97 | // ts localised between to interval: let's localized te |
|
159 | // ts localised between to interval: let's localized te | |
98 | addInCacheDataByEnd(dateTime, dateTimeList, notInCache, cacheIndexJ, currentTStart); |
|
160 | addInCacheDataByEnd(dateTime, dateTimeList, notInCache, cacheIndexJ, currentTStart); | |
99 | } |
|
161 | } | |
100 | else if (dateTime.m_TStart < currentDateTimeI.m_TEnd) { |
|
162 | else if (dateTime.m_TStart < currentDateTimeI.m_TEnd) { | |
101 | // ts not localised before the current interval: we need to look at the next interval |
|
163 | // ts not localised before the current interval: we need to look at the next interval | |
102 | // We can assume now current tstart is the last interval tend, because data between them are |
|
164 | // We can assume now current tstart is the last interval tend, because data between them are | |
103 | // in the cache |
|
165 | // in the cache | |
104 | addInCacheDataByStart(dateTime, dateTimeList, notInCache, ++cacheIndex, |
|
166 | addInCacheDataByStart(dateTime, dateTimeList, notInCache, ++cacheIndex, | |
105 | currentDateTimeI.m_TEnd); |
|
167 | currentDateTimeI.m_TEnd); | |
106 | } |
|
168 | } | |
107 | else { |
|
169 | else { | |
108 | // ts not localised before the current interval: we need to look at the next interval |
|
170 | // ts not localised before the current interval: we need to look at the next interval | |
109 | addInCacheDataByStart(dateTime, dateTimeList, notInCache, ++cacheIndex, currentTStart); |
|
171 | addInCacheDataByStart(dateTime, dateTimeList, notInCache, ++cacheIndex, currentTStart); | |
110 | } |
|
172 | } | |
111 | } |
|
173 | } |
@@ -1,245 +1,343 | |||||
1 | #include <Variable/Variable.h> |
|
1 | #include <Variable/Variable.h> | |
2 | #include <Variable/VariableCacheController.h> |
|
2 | #include <Variable/VariableCacheController.h> | |
3 |
|
3 | |||
4 | #include <QObject> |
|
4 | #include <QObject> | |
5 | #include <QtTest> |
|
5 | #include <QtTest> | |
6 |
|
6 | |||
7 | #include <memory> |
|
7 | #include <memory> | |
8 |
|
8 | |||
9 | class TestVariableCacheController : public QObject { |
|
9 | class TestVariableCacheController : public QObject { | |
10 | Q_OBJECT |
|
10 | Q_OBJECT | |
11 |
|
11 | |||
12 | private slots: |
|
12 | private slots: | |
13 | void testProvideNotInCacheDateTimeList(); |
|
13 | void testProvideNotInCacheDateTimeList(); | |
|
14 | ||||
|
15 | void testAddDateTime(); | |||
14 | }; |
|
16 | }; | |
15 |
|
17 | |||
16 |
|
18 | |||
17 | void TestVariableCacheController::testProvideNotInCacheDateTimeList() |
|
19 | void TestVariableCacheController::testProvideNotInCacheDateTimeList() | |
18 | { |
|
20 | { | |
19 | VariableCacheController variableCacheController{}; |
|
21 | VariableCacheController variableCacheController{}; | |
20 |
|
22 | |||
21 | auto ts0 = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 0, 0}}; |
|
23 | auto ts0 = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 0, 0}}; | |
22 | auto te0 = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}}; |
|
24 | auto te0 = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}}; | |
23 | auto sqp0 = SqpDateTime{static_cast<double>(ts0.toMSecsSinceEpoch()), |
|
25 | auto sqp0 = SqpDateTime{static_cast<double>(ts0.toMSecsSinceEpoch()), | |
24 | static_cast<double>(te0.toMSecsSinceEpoch())}; |
|
26 | static_cast<double>(te0.toMSecsSinceEpoch())}; | |
25 |
|
27 | |||
26 | auto ts1 = QDateTime{QDate{2017, 01, 01}, QTime{2, 6, 0, 0}}; |
|
28 | auto ts1 = QDateTime{QDate{2017, 01, 01}, QTime{2, 6, 0, 0}}; | |
27 | auto te1 = QDateTime{QDate{2017, 01, 01}, QTime{2, 8, 0, 0}}; |
|
29 | auto te1 = QDateTime{QDate{2017, 01, 01}, QTime{2, 8, 0, 0}}; | |
28 | auto sqp1 = SqpDateTime{static_cast<double>(ts1.toMSecsSinceEpoch()), |
|
30 | auto sqp1 = SqpDateTime{static_cast<double>(ts1.toMSecsSinceEpoch()), | |
29 | static_cast<double>(te1.toMSecsSinceEpoch())}; |
|
31 | static_cast<double>(te1.toMSecsSinceEpoch())}; | |
30 |
|
32 | |||
31 | auto ts2 = QDateTime{QDate{2017, 01, 01}, QTime{2, 18, 0, 0}}; |
|
33 | auto ts2 = QDateTime{QDate{2017, 01, 01}, QTime{2, 18, 0, 0}}; | |
32 | auto te2 = QDateTime{QDate{2017, 01, 01}, QTime{2, 20, 0, 0}}; |
|
34 | auto te2 = QDateTime{QDate{2017, 01, 01}, QTime{2, 20, 0, 0}}; | |
33 | auto sqp2 = SqpDateTime{static_cast<double>(ts2.toMSecsSinceEpoch()), |
|
35 | auto sqp2 = SqpDateTime{static_cast<double>(ts2.toMSecsSinceEpoch()), | |
34 | static_cast<double>(te2.toMSecsSinceEpoch())}; |
|
36 | static_cast<double>(te2.toMSecsSinceEpoch())}; | |
35 |
|
37 | |||
36 | auto var0 = std::make_shared<Variable>("", "", "", sqp0); |
|
38 | auto var0 = std::make_shared<Variable>("", "", "", sqp0); | |
37 |
|
39 | |||
38 | variableCacheController.addDateTime(var0, sqp0); |
|
40 | variableCacheController.addDateTime(var0, sqp0); | |
39 | variableCacheController.addDateTime(var0, sqp1); |
|
41 | variableCacheController.addDateTime(var0, sqp1); | |
40 | variableCacheController.addDateTime(var0, sqp2); |
|
42 | variableCacheController.addDateTime(var0, sqp2); | |
41 |
|
43 | |||
42 | // first case [ts,te] < ts0 |
|
44 | // first case [ts,te] < ts0 | |
43 | auto ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}}; |
|
45 | auto ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}}; | |
44 | auto te = QDateTime{QDate{2017, 01, 01}, QTime{2, 1, 0, 0}}; |
|
46 | auto te = QDateTime{QDate{2017, 01, 01}, QTime{2, 1, 0, 0}}; | |
45 | auto sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()), |
|
47 | auto sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()), | |
46 | static_cast<double>(te.toMSecsSinceEpoch())}; |
|
48 | static_cast<double>(te.toMSecsSinceEpoch())}; | |
47 |
|
49 | |||
48 |
|
50 | |||
49 | auto notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); |
|
51 | auto notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); | |
50 |
|
52 | |||
51 | QCOMPARE(notInCach.size(), 1); |
|
53 | QCOMPARE(notInCach.size(), 1); | |
52 | auto notInCashSqp = notInCach.first(); |
|
54 | auto notInCashSqp = notInCach.first(); | |
53 | QCOMPARE(notInCashSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch())); |
|
55 | QCOMPARE(notInCashSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch())); | |
54 | QCOMPARE(notInCashSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch())); |
|
56 | QCOMPARE(notInCashSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch())); | |
55 |
|
57 | |||
56 |
|
58 | |||
57 | // second case ts < ts0 && ts0 < te <= te0 |
|
59 | // second case ts < ts0 && ts0 < te <= te0 | |
58 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}}; |
|
60 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}}; | |
59 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 30, 0}}; |
|
61 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 30, 0}}; | |
60 | sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()), |
|
62 | sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()), | |
61 | static_cast<double>(te.toMSecsSinceEpoch())}; |
|
63 | static_cast<double>(te.toMSecsSinceEpoch())}; | |
62 |
|
64 | |||
63 |
|
65 | |||
64 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); |
|
66 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); | |
65 |
|
67 | |||
66 | QCOMPARE(notInCach.size(), 1); |
|
68 | QCOMPARE(notInCach.size(), 1); | |
67 | notInCashSqp = notInCach.first(); |
|
69 | notInCashSqp = notInCach.first(); | |
68 | QCOMPARE(notInCashSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch())); |
|
70 | QCOMPARE(notInCashSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch())); | |
69 | QCOMPARE(notInCashSqp.m_TEnd, static_cast<double>(ts0.toMSecsSinceEpoch())); |
|
71 | QCOMPARE(notInCashSqp.m_TEnd, static_cast<double>(ts0.toMSecsSinceEpoch())); | |
70 |
|
72 | |||
71 | // 3th case ts < ts0 && te0 < te <= ts1 |
|
73 | // 3th case ts < ts0 && te0 < te <= ts1 | |
72 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}}; |
|
74 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}}; | |
73 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; |
|
75 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; | |
74 | sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()), |
|
76 | sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()), | |
75 | static_cast<double>(te.toMSecsSinceEpoch())}; |
|
77 | static_cast<double>(te.toMSecsSinceEpoch())}; | |
76 |
|
78 | |||
77 |
|
79 | |||
78 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); |
|
80 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); | |
79 |
|
81 | |||
80 | QCOMPARE(notInCach.size(), 2); |
|
82 | QCOMPARE(notInCach.size(), 2); | |
81 | notInCashSqp = notInCach.first(); |
|
83 | notInCashSqp = notInCach.first(); | |
82 | QCOMPARE(notInCashSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch())); |
|
84 | QCOMPARE(notInCashSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch())); | |
83 | QCOMPARE(notInCashSqp.m_TEnd, static_cast<double>(ts0.toMSecsSinceEpoch())); |
|
85 | QCOMPARE(notInCashSqp.m_TEnd, static_cast<double>(ts0.toMSecsSinceEpoch())); | |
84 |
|
86 | |||
85 | notInCashSqp = notInCach.at(1); |
|
87 | notInCashSqp = notInCach.at(1); | |
86 | QCOMPARE(notInCashSqp.m_TStart, static_cast<double>(te0.toMSecsSinceEpoch())); |
|
88 | QCOMPARE(notInCashSqp.m_TStart, static_cast<double>(te0.toMSecsSinceEpoch())); | |
87 | QCOMPARE(notInCashSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch())); |
|
89 | QCOMPARE(notInCashSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch())); | |
88 |
|
90 | |||
89 | // 4th case ts < ts0 && ts1 < te <= te1 |
|
91 | // 4th case ts < ts0 && ts1 < te <= te1 | |
90 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}}; |
|
92 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}}; | |
91 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 7, 0, 0}}; |
|
93 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 7, 0, 0}}; | |
92 | sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()), |
|
94 | sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()), | |
93 | static_cast<double>(te.toMSecsSinceEpoch())}; |
|
95 | static_cast<double>(te.toMSecsSinceEpoch())}; | |
94 |
|
96 | |||
95 |
|
97 | |||
96 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); |
|
98 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); | |
97 |
|
99 | |||
98 | QCOMPARE(notInCach.size(), 2); |
|
100 | QCOMPARE(notInCach.size(), 2); | |
99 | notInCashSqp = notInCach.first(); |
|
101 | notInCashSqp = notInCach.first(); | |
100 | QCOMPARE(notInCashSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch())); |
|
102 | QCOMPARE(notInCashSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch())); | |
101 | QCOMPARE(notInCashSqp.m_TEnd, static_cast<double>(ts0.toMSecsSinceEpoch())); |
|
103 | QCOMPARE(notInCashSqp.m_TEnd, static_cast<double>(ts0.toMSecsSinceEpoch())); | |
102 |
|
104 | |||
103 | notInCashSqp = notInCach.at(1); |
|
105 | notInCashSqp = notInCach.at(1); | |
104 | QCOMPARE(notInCashSqp.m_TStart, static_cast<double>(te0.toMSecsSinceEpoch())); |
|
106 | QCOMPARE(notInCashSqp.m_TStart, static_cast<double>(te0.toMSecsSinceEpoch())); | |
105 | QCOMPARE(notInCashSqp.m_TEnd, static_cast<double>(ts1.toMSecsSinceEpoch())); |
|
107 | QCOMPARE(notInCashSqp.m_TEnd, static_cast<double>(ts1.toMSecsSinceEpoch())); | |
106 |
|
108 | |||
107 | // 5th case ts < ts0 && te3 < te |
|
109 | // 5th case ts < ts0 && te3 < te | |
108 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}}; |
|
110 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}}; | |
109 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 22, 0, 0}}; |
|
111 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 22, 0, 0}}; | |
110 | sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()), |
|
112 | sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()), | |
111 | static_cast<double>(te.toMSecsSinceEpoch())}; |
|
113 | static_cast<double>(te.toMSecsSinceEpoch())}; | |
112 |
|
114 | |||
113 |
|
115 | |||
114 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); |
|
116 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); | |
115 |
|
117 | |||
116 | QCOMPARE(notInCach.size(), 4); |
|
118 | QCOMPARE(notInCach.size(), 4); | |
117 | notInCashSqp = notInCach.first(); |
|
119 | notInCashSqp = notInCach.first(); | |
118 | QCOMPARE(notInCashSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch())); |
|
120 | QCOMPARE(notInCashSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch())); | |
119 | QCOMPARE(notInCashSqp.m_TEnd, static_cast<double>(ts0.toMSecsSinceEpoch())); |
|
121 | QCOMPARE(notInCashSqp.m_TEnd, static_cast<double>(ts0.toMSecsSinceEpoch())); | |
120 |
|
122 | |||
121 | notInCashSqp = notInCach.at(1); |
|
123 | notInCashSqp = notInCach.at(1); | |
122 | QCOMPARE(notInCashSqp.m_TStart, static_cast<double>(te0.toMSecsSinceEpoch())); |
|
124 | QCOMPARE(notInCashSqp.m_TStart, static_cast<double>(te0.toMSecsSinceEpoch())); | |
123 | QCOMPARE(notInCashSqp.m_TEnd, static_cast<double>(ts1.toMSecsSinceEpoch())); |
|
125 | QCOMPARE(notInCashSqp.m_TEnd, static_cast<double>(ts1.toMSecsSinceEpoch())); | |
124 |
|
126 | |||
125 | notInCashSqp = notInCach.at(2); |
|
127 | notInCashSqp = notInCach.at(2); | |
126 | QCOMPARE(notInCashSqp.m_TStart, static_cast<double>(te1.toMSecsSinceEpoch())); |
|
128 | QCOMPARE(notInCashSqp.m_TStart, static_cast<double>(te1.toMSecsSinceEpoch())); | |
127 | QCOMPARE(notInCashSqp.m_TEnd, static_cast<double>(ts2.toMSecsSinceEpoch())); |
|
129 | QCOMPARE(notInCashSqp.m_TEnd, static_cast<double>(ts2.toMSecsSinceEpoch())); | |
128 |
|
130 | |||
129 | notInCashSqp = notInCach.at(3); |
|
131 | notInCashSqp = notInCach.at(3); | |
130 | QCOMPARE(notInCashSqp.m_TStart, static_cast<double>(te2.toMSecsSinceEpoch())); |
|
132 | QCOMPARE(notInCashSqp.m_TStart, static_cast<double>(te2.toMSecsSinceEpoch())); | |
131 | QCOMPARE(notInCashSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch())); |
|
133 | QCOMPARE(notInCashSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch())); | |
132 |
|
134 | |||
133 |
|
135 | |||
134 | // 6th case ts2 < ts |
|
136 | // 6th case ts2 < ts | |
135 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 45, 0, 0}}; |
|
137 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 45, 0, 0}}; | |
136 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 47, 0, 0}}; |
|
138 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 47, 0, 0}}; | |
137 | sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()), |
|
139 | sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()), | |
138 | static_cast<double>(te.toMSecsSinceEpoch())}; |
|
140 | static_cast<double>(te.toMSecsSinceEpoch())}; | |
139 |
|
141 | |||
140 |
|
142 | |||
141 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); |
|
143 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); | |
142 |
|
144 | |||
143 | QCOMPARE(notInCach.size(), 1); |
|
145 | QCOMPARE(notInCach.size(), 1); | |
144 | notInCashSqp = notInCach.first(); |
|
146 | notInCashSqp = notInCach.first(); | |
145 | QCOMPARE(notInCashSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch())); |
|
147 | QCOMPARE(notInCashSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch())); | |
146 | QCOMPARE(notInCashSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch())); |
|
148 | QCOMPARE(notInCashSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch())); | |
147 |
|
149 | |||
148 | // 7th case ts = te0 && te < ts1 |
|
150 | // 7th case ts = te0 && te < ts1 | |
149 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}}; |
|
151 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}}; | |
150 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; |
|
152 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; | |
151 | sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()), |
|
153 | sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()), | |
152 | static_cast<double>(te.toMSecsSinceEpoch())}; |
|
154 | static_cast<double>(te.toMSecsSinceEpoch())}; | |
153 |
|
155 | |||
154 |
|
156 | |||
155 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); |
|
157 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); | |
156 |
|
158 | |||
157 | QCOMPARE(notInCach.size(), 1); |
|
159 | QCOMPARE(notInCach.size(), 1); | |
158 | notInCashSqp = notInCach.first(); |
|
160 | notInCashSqp = notInCach.first(); | |
159 | QCOMPARE(notInCashSqp.m_TStart, static_cast<double>(te0.toMSecsSinceEpoch())); |
|
161 | QCOMPARE(notInCashSqp.m_TStart, static_cast<double>(te0.toMSecsSinceEpoch())); | |
160 | QCOMPARE(notInCashSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch())); |
|
162 | QCOMPARE(notInCashSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch())); | |
161 |
|
163 | |||
162 | // 8th case ts0 < ts < te0 && te < ts1 |
|
164 | // 8th case ts0 < ts < te0 && te < ts1 | |
163 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 30, 0}}; |
|
165 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 30, 0}}; | |
164 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; |
|
166 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; | |
165 | sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()), |
|
167 | sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()), | |
166 | static_cast<double>(te.toMSecsSinceEpoch())}; |
|
168 | static_cast<double>(te.toMSecsSinceEpoch())}; | |
167 |
|
169 | |||
168 |
|
170 | |||
169 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); |
|
171 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); | |
170 |
|
172 | |||
171 | QCOMPARE(notInCach.size(), 1); |
|
173 | QCOMPARE(notInCach.size(), 1); | |
172 | notInCashSqp = notInCach.first(); |
|
174 | notInCashSqp = notInCach.first(); | |
173 | QCOMPARE(notInCashSqp.m_TStart, static_cast<double>(te0.toMSecsSinceEpoch())); |
|
175 | QCOMPARE(notInCashSqp.m_TStart, static_cast<double>(te0.toMSecsSinceEpoch())); | |
174 | QCOMPARE(notInCashSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch())); |
|
176 | QCOMPARE(notInCashSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch())); | |
175 |
|
177 | |||
176 | // 9th case ts0 < ts < te0 && ts1 < te < te1 |
|
178 | // 9th case ts0 < ts < te0 && ts1 < te < te1 | |
177 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 30, 0}}; |
|
179 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 30, 0}}; | |
178 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 7, 0, 0}}; |
|
180 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 7, 0, 0}}; | |
179 | sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()), |
|
181 | sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()), | |
180 | static_cast<double>(te.toMSecsSinceEpoch())}; |
|
182 | static_cast<double>(te.toMSecsSinceEpoch())}; | |
181 |
|
183 | |||
182 |
|
184 | |||
183 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); |
|
185 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); | |
184 |
|
186 | |||
185 | QCOMPARE(notInCach.size(), 1); |
|
187 | QCOMPARE(notInCach.size(), 1); | |
186 | notInCashSqp = notInCach.first(); |
|
188 | notInCashSqp = notInCach.first(); | |
187 | QCOMPARE(notInCashSqp.m_TStart, static_cast<double>(te0.toMSecsSinceEpoch())); |
|
189 | QCOMPARE(notInCashSqp.m_TStart, static_cast<double>(te0.toMSecsSinceEpoch())); | |
188 | QCOMPARE(notInCashSqp.m_TEnd, static_cast<double>(ts1.toMSecsSinceEpoch())); |
|
190 | QCOMPARE(notInCashSqp.m_TEnd, static_cast<double>(ts1.toMSecsSinceEpoch())); | |
189 |
|
191 | |||
190 | // 10th case te1 < ts < te < ts2 |
|
192 | // 10th case te1 < ts < te < ts2 | |
191 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 9, 0, 0}}; |
|
193 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 9, 0, 0}}; | |
192 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 10, 0, 0}}; |
|
194 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 10, 0, 0}}; | |
193 | sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()), |
|
195 | sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()), | |
194 | static_cast<double>(te.toMSecsSinceEpoch())}; |
|
196 | static_cast<double>(te.toMSecsSinceEpoch())}; | |
195 |
|
197 | |||
196 |
|
198 | |||
197 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); |
|
199 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); | |
198 |
|
200 | |||
199 | QCOMPARE(notInCach.size(), 1); |
|
201 | QCOMPARE(notInCach.size(), 1); | |
200 | notInCashSqp = notInCach.first(); |
|
202 | notInCashSqp = notInCach.first(); | |
201 | QCOMPARE(notInCashSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch())); |
|
203 | QCOMPARE(notInCashSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch())); | |
202 | QCOMPARE(notInCashSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch())); |
|
204 | QCOMPARE(notInCashSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch())); | |
203 |
|
205 | |||
204 | // 11th case te0 < ts < ts1 && te3 < te |
|
206 | // 11th case te0 < ts < ts1 && te3 < te | |
205 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; |
|
207 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; | |
206 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 47, 0, 0}}; |
|
208 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 47, 0, 0}}; | |
207 | sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()), |
|
209 | sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()), | |
208 | static_cast<double>(te.toMSecsSinceEpoch())}; |
|
210 | static_cast<double>(te.toMSecsSinceEpoch())}; | |
209 |
|
211 | |||
210 |
|
212 | |||
211 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); |
|
213 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); | |
212 |
|
214 | |||
213 | QCOMPARE(notInCach.size(), 3); |
|
215 | QCOMPARE(notInCach.size(), 3); | |
214 | notInCashSqp = notInCach.first(); |
|
216 | notInCashSqp = notInCach.first(); | |
215 | QCOMPARE(notInCashSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch())); |
|
217 | QCOMPARE(notInCashSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch())); | |
216 | QCOMPARE(notInCashSqp.m_TEnd, static_cast<double>(ts1.toMSecsSinceEpoch())); |
|
218 | QCOMPARE(notInCashSqp.m_TEnd, static_cast<double>(ts1.toMSecsSinceEpoch())); | |
217 |
|
219 | |||
218 | notInCashSqp = notInCach.at(1); |
|
220 | notInCashSqp = notInCach.at(1); | |
219 | QCOMPARE(notInCashSqp.m_TStart, static_cast<double>(te1.toMSecsSinceEpoch())); |
|
221 | QCOMPARE(notInCashSqp.m_TStart, static_cast<double>(te1.toMSecsSinceEpoch())); | |
220 | QCOMPARE(notInCashSqp.m_TEnd, static_cast<double>(ts2.toMSecsSinceEpoch())); |
|
222 | QCOMPARE(notInCashSqp.m_TEnd, static_cast<double>(ts2.toMSecsSinceEpoch())); | |
221 |
|
223 | |||
222 | notInCashSqp = notInCach.at(2); |
|
224 | notInCashSqp = notInCach.at(2); | |
223 | QCOMPARE(notInCashSqp.m_TStart, static_cast<double>(te2.toMSecsSinceEpoch())); |
|
225 | QCOMPARE(notInCashSqp.m_TStart, static_cast<double>(te2.toMSecsSinceEpoch())); | |
224 | QCOMPARE(notInCashSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch())); |
|
226 | QCOMPARE(notInCashSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch())); | |
225 |
|
227 | |||
226 | // 12th case te0 < ts < ts1 && te3 < te |
|
228 | // 12th case te0 < ts < ts1 && te3 < te | |
227 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; |
|
229 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; | |
228 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 10, 0, 0}}; |
|
230 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 10, 0, 0}}; | |
229 | sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()), |
|
231 | sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()), | |
230 | static_cast<double>(te.toMSecsSinceEpoch())}; |
|
232 | static_cast<double>(te.toMSecsSinceEpoch())}; | |
231 |
|
233 | |||
232 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); |
|
234 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); | |
233 |
|
235 | |||
234 | QCOMPARE(notInCach.size(), 2); |
|
236 | QCOMPARE(notInCach.size(), 2); | |
235 | notInCashSqp = notInCach.first(); |
|
237 | notInCashSqp = notInCach.first(); | |
236 | QCOMPARE(notInCashSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch())); |
|
238 | QCOMPARE(notInCashSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch())); | |
237 | QCOMPARE(notInCashSqp.m_TEnd, static_cast<double>(ts1.toMSecsSinceEpoch())); |
|
239 | QCOMPARE(notInCashSqp.m_TEnd, static_cast<double>(ts1.toMSecsSinceEpoch())); | |
238 |
|
240 | |||
239 | notInCashSqp = notInCach.at(1); |
|
241 | notInCashSqp = notInCach.at(1); | |
240 | QCOMPARE(notInCashSqp.m_TStart, static_cast<double>(te1.toMSecsSinceEpoch())); |
|
242 | QCOMPARE(notInCashSqp.m_TStart, static_cast<double>(te1.toMSecsSinceEpoch())); | |
241 | QCOMPARE(notInCashSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch())); |
|
243 | QCOMPARE(notInCashSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch())); | |
242 | } |
|
244 | } | |
243 |
|
245 | |||
|
246 | ||||
|
247 | void TestVariableCacheController::testAddDateTime() | |||
|
248 | { | |||
|
249 | VariableCacheController variableCacheController{}; | |||
|
250 | ||||
|
251 | auto ts0 = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 0, 0}}; | |||
|
252 | auto te0 = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}}; | |||
|
253 | auto sqp0 = SqpDateTime{static_cast<double>(ts0.toMSecsSinceEpoch()), | |||
|
254 | static_cast<double>(te0.toMSecsSinceEpoch())}; | |||
|
255 | ||||
|
256 | auto ts1 = QDateTime{QDate{2017, 01, 01}, QTime{2, 6, 0, 0}}; | |||
|
257 | auto te1 = QDateTime{QDate{2017, 01, 01}, QTime{2, 8, 0, 0}}; | |||
|
258 | auto sqp1 = SqpDateTime{static_cast<double>(ts1.toMSecsSinceEpoch()), | |||
|
259 | static_cast<double>(te1.toMSecsSinceEpoch())}; | |||
|
260 | ||||
|
261 | auto ts2 = QDateTime{QDate{2017, 01, 01}, QTime{2, 18, 0, 0}}; | |||
|
262 | auto te2 = QDateTime{QDate{2017, 01, 01}, QTime{2, 20, 0, 0}}; | |||
|
263 | auto sqp2 = SqpDateTime{static_cast<double>(ts2.toMSecsSinceEpoch()), | |||
|
264 | static_cast<double>(te2.toMSecsSinceEpoch())}; | |||
|
265 | ||||
|
266 | auto ts01 = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}}; | |||
|
267 | auto te01 = QDateTime{QDate{2017, 01, 01}, QTime{2, 6, 0, 0}}; | |||
|
268 | auto sqp01 = SqpDateTime{static_cast<double>(ts01.toMSecsSinceEpoch()), | |||
|
269 | static_cast<double>(te01.toMSecsSinceEpoch())}; | |||
|
270 | ||||
|
271 | auto ts3 = QDateTime{QDate{2017, 01, 01}, QTime{2, 14, 0, 0}}; | |||
|
272 | auto te3 = QDateTime{QDate{2017, 01, 01}, QTime{2, 16, 0, 0}}; | |||
|
273 | auto sqp3 = SqpDateTime{static_cast<double>(ts3.toMSecsSinceEpoch()), | |||
|
274 | static_cast<double>(te3.toMSecsSinceEpoch())}; | |||
|
275 | ||||
|
276 | auto ts03 = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}}; | |||
|
277 | auto te03 = QDateTime{QDate{2017, 01, 01}, QTime{2, 22, 0, 0}}; | |||
|
278 | auto sqp03 = SqpDateTime{static_cast<double>(ts03.toMSecsSinceEpoch()), | |||
|
279 | static_cast<double>(te03.toMSecsSinceEpoch())}; | |||
|
280 | ||||
|
281 | ||||
|
282 | auto var0 = std::make_shared<Variable>("", "", "", sqp0); | |||
|
283 | ||||
|
284 | ||||
|
285 | // First case: add the first interval to the variable :sqp0 | |||
|
286 | variableCacheController.addDateTime(var0, sqp0); | |||
|
287 | auto dateCacheList = variableCacheController.dateCacheList(var0); | |||
|
288 | QCOMPARE(dateCacheList.count(), 1); | |||
|
289 | auto dateCache = dateCacheList.at(0); | |||
|
290 | QCOMPARE(dateCache.m_TStart, static_cast<double>(ts0.toMSecsSinceEpoch())); | |||
|
291 | QCOMPARE(dateCache.m_TEnd, static_cast<double>(te0.toMSecsSinceEpoch())); | |||
|
292 | ||||
|
293 | // 2nd case: add a second interval : sqp1 > sqp0 | |||
|
294 | variableCacheController.addDateTime(var0, sqp1); | |||
|
295 | dateCacheList = variableCacheController.dateCacheList(var0); | |||
|
296 | QCOMPARE(dateCacheList.count(), 2); | |||
|
297 | dateCache = dateCacheList.at(0); | |||
|
298 | QCOMPARE(dateCache.m_TStart, static_cast<double>(ts0.toMSecsSinceEpoch())); | |||
|
299 | QCOMPARE(dateCache.m_TEnd, static_cast<double>(te0.toMSecsSinceEpoch())); | |||
|
300 | ||||
|
301 | dateCache = dateCacheList.at(1); | |||
|
302 | QCOMPARE(dateCache.m_TStart, static_cast<double>(ts1.toMSecsSinceEpoch())); | |||
|
303 | QCOMPARE(dateCache.m_TEnd, static_cast<double>(te1.toMSecsSinceEpoch())); | |||
|
304 | ||||
|
305 | // 3th case: merge sqp0 & sqp1 with sqp01 | |||
|
306 | variableCacheController.addDateTime(var0, sqp01); | |||
|
307 | dateCacheList = variableCacheController.dateCacheList(var0); | |||
|
308 | QCOMPARE(dateCacheList.count(), 1); | |||
|
309 | dateCache = dateCacheList.at(0); | |||
|
310 | QCOMPARE(dateCache.m_TStart, static_cast<double>(ts0.toMSecsSinceEpoch())); | |||
|
311 | QCOMPARE(dateCache.m_TEnd, static_cast<double>(te1.toMSecsSinceEpoch())); | |||
|
312 | ||||
|
313 | ||||
|
314 | // 4th case: add a second interval : sqp1 > sqp0 | |||
|
315 | variableCacheController.addDateTime(var0, sqp2); | |||
|
316 | variableCacheController.addDateTime(var0, sqp3); | |||
|
317 | dateCacheList = variableCacheController.dateCacheList(var0); | |||
|
318 | QCOMPARE(dateCacheList.count(), 3); | |||
|
319 | dateCache = dateCacheList.at(0); | |||
|
320 | QCOMPARE(dateCache.m_TStart, static_cast<double>(ts0.toMSecsSinceEpoch())); | |||
|
321 | QCOMPARE(dateCache.m_TEnd, static_cast<double>(te1.toMSecsSinceEpoch())); | |||
|
322 | ||||
|
323 | dateCache = dateCacheList.at(1); | |||
|
324 | QCOMPARE(dateCache.m_TStart, static_cast<double>(ts3.toMSecsSinceEpoch())); | |||
|
325 | QCOMPARE(dateCache.m_TEnd, static_cast<double>(te3.toMSecsSinceEpoch())); | |||
|
326 | ||||
|
327 | dateCache = dateCacheList.at(2); | |||
|
328 | QCOMPARE(dateCache.m_TStart, static_cast<double>(ts2.toMSecsSinceEpoch())); | |||
|
329 | QCOMPARE(dateCache.m_TEnd, static_cast<double>(te2.toMSecsSinceEpoch())); | |||
|
330 | ||||
|
331 | ||||
|
332 | // 5th case: merge all interval | |||
|
333 | variableCacheController.addDateTime(var0, sqp03); | |||
|
334 | dateCacheList = variableCacheController.dateCacheList(var0); | |||
|
335 | QCOMPARE(dateCacheList.count(), 1); | |||
|
336 | dateCache = dateCacheList.at(0); | |||
|
337 | QCOMPARE(dateCache.m_TStart, static_cast<double>(ts0.toMSecsSinceEpoch())); | |||
|
338 | QCOMPARE(dateCache.m_TEnd, static_cast<double>(te03.toMSecsSinceEpoch())); | |||
|
339 | } | |||
|
340 | ||||
|
341 | ||||
244 | QTEST_MAIN(TestVariableCacheController) |
|
342 | QTEST_MAIN(TestVariableCacheController) | |
245 | #include "TestVariableCacheController.moc" |
|
343 | #include "TestVariableCacheController.moc" |
General Comments 0
You need to be logged in to leave comments.
Login now