@@ -0,0 +1,188 | |||||
|
1 | #include <Variable/Variable.h> | |||
|
2 | ||||
|
3 | #include <QObject> | |||
|
4 | #include <QtTest> | |||
|
5 | ||||
|
6 | #include <memory> | |||
|
7 | ||||
|
8 | class TestVariable : public QObject { | |||
|
9 | Q_OBJECT | |||
|
10 | ||||
|
11 | private slots: | |||
|
12 | void testNotInCacheRangeList(); | |||
|
13 | ||||
|
14 | void testInCacheRangeList(); | |||
|
15 | }; | |||
|
16 | ||||
|
17 | ||||
|
18 | void TestVariable::testNotInCacheRangeList() | |||
|
19 | { | |||
|
20 | auto varRS = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 20, 0}}; | |||
|
21 | auto varRE = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 40, 0}}; | |||
|
22 | ||||
|
23 | auto sqpR = SqpRange{static_cast<double>(varRS.toMSecsSinceEpoch()), | |||
|
24 | static_cast<double>(varRE.toMSecsSinceEpoch())}; | |||
|
25 | ||||
|
26 | auto varCRS = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 0, 0}}; | |||
|
27 | auto varCRE = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}}; | |||
|
28 | auto sqpCR = SqpRange{static_cast<double>(varCRS.toMSecsSinceEpoch()), | |||
|
29 | static_cast<double>(varCRE.toMSecsSinceEpoch())}; | |||
|
30 | ||||
|
31 | Variable var{"Var test", sqpR}; | |||
|
32 | var.setCacheRange(sqpCR); | |||
|
33 | ||||
|
34 | // 1: [ts,te] < varTS | |||
|
35 | auto ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}}; | |||
|
36 | auto te = QDateTime{QDate{2017, 01, 01}, QTime{2, 1, 0, 0}}; | |||
|
37 | auto sqp = SqpRange{static_cast<double>(ts.toMSecsSinceEpoch()), | |||
|
38 | static_cast<double>(te.toMSecsSinceEpoch())}; | |||
|
39 | ||||
|
40 | auto notInCach = var.provideNotInCacheRangeList(sqp); | |||
|
41 | ||||
|
42 | QCOMPARE(notInCach.size(), 1); | |||
|
43 | ||||
|
44 | auto notInCachRange = notInCach.first(); | |||
|
45 | ||||
|
46 | QCOMPARE(notInCachRange.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch())); | |||
|
47 | QCOMPARE(notInCachRange.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch())); | |||
|
48 | ||||
|
49 | // 2: ts < varTS < te < varTE | |||
|
50 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}}; | |||
|
51 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 30, 0}}; | |||
|
52 | sqp = SqpRange{static_cast<double>(ts.toMSecsSinceEpoch()), | |||
|
53 | static_cast<double>(te.toMSecsSinceEpoch())}; | |||
|
54 | notInCach = var.provideNotInCacheRangeList(sqp); | |||
|
55 | QCOMPARE(notInCach.size(), 1); | |||
|
56 | notInCachRange = notInCach.first(); | |||
|
57 | QCOMPARE(notInCachRange.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch())); | |||
|
58 | QCOMPARE(notInCachRange.m_TEnd, static_cast<double>(varCRS.toMSecsSinceEpoch())); | |||
|
59 | ||||
|
60 | // 3: varTS < ts < te < varTE | |||
|
61 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 20, 0}}; | |||
|
62 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 30, 0}}; | |||
|
63 | sqp = SqpRange{static_cast<double>(ts.toMSecsSinceEpoch()), | |||
|
64 | static_cast<double>(te.toMSecsSinceEpoch())}; | |||
|
65 | notInCach = var.provideNotInCacheRangeList(sqp); | |||
|
66 | QCOMPARE(notInCach.size(), 0); | |||
|
67 | ||||
|
68 | ||||
|
69 | // 4: varTS < ts < varTE < te | |||
|
70 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 20, 0}}; | |||
|
71 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; | |||
|
72 | sqp = SqpRange{static_cast<double>(ts.toMSecsSinceEpoch()), | |||
|
73 | static_cast<double>(te.toMSecsSinceEpoch())}; | |||
|
74 | notInCach = var.provideNotInCacheRangeList(sqp); | |||
|
75 | QCOMPARE(notInCach.size(), 1); | |||
|
76 | notInCachRange = notInCach.first(); | |||
|
77 | QCOMPARE(notInCachRange.m_TStart, static_cast<double>(varCRE.toMSecsSinceEpoch())); | |||
|
78 | QCOMPARE(notInCachRange.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch())); | |||
|
79 | ||||
|
80 | // 5: varTS < varTE < ts < te | |||
|
81 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 20, 0}}; | |||
|
82 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; | |||
|
83 | sqp = SqpRange{static_cast<double>(ts.toMSecsSinceEpoch()), | |||
|
84 | static_cast<double>(te.toMSecsSinceEpoch())}; | |||
|
85 | notInCach = var.provideNotInCacheRangeList(sqp); | |||
|
86 | QCOMPARE(notInCach.size(), 1); | |||
|
87 | notInCachRange = notInCach.first(); | |||
|
88 | QCOMPARE(notInCachRange.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch())); | |||
|
89 | QCOMPARE(notInCachRange.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch())); | |||
|
90 | ||||
|
91 | // 6: ts <varTS < varTE < te | |||
|
92 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 1, 0, 0}}; | |||
|
93 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; | |||
|
94 | sqp = SqpRange{static_cast<double>(ts.toMSecsSinceEpoch()), | |||
|
95 | static_cast<double>(te.toMSecsSinceEpoch())}; | |||
|
96 | notInCach = var.provideNotInCacheRangeList(sqp); | |||
|
97 | QCOMPARE(notInCach.size(), 2); | |||
|
98 | notInCachRange = notInCach.first(); | |||
|
99 | QCOMPARE(notInCachRange.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch())); | |||
|
100 | QCOMPARE(notInCachRange.m_TEnd, static_cast<double>(varCRS.toMSecsSinceEpoch())); | |||
|
101 | notInCachRange = notInCach[1]; | |||
|
102 | QCOMPARE(notInCachRange.m_TStart, static_cast<double>(varCRE.toMSecsSinceEpoch())); | |||
|
103 | QCOMPARE(notInCachRange.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch())); | |||
|
104 | } | |||
|
105 | ||||
|
106 | ||||
|
107 | void TestVariable::testInCacheRangeList() | |||
|
108 | { | |||
|
109 | auto varRS = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 20, 0}}; | |||
|
110 | auto varRE = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 40, 0}}; | |||
|
111 | ||||
|
112 | auto sqpR = SqpRange{static_cast<double>(varRS.toMSecsSinceEpoch()), | |||
|
113 | static_cast<double>(varRE.toMSecsSinceEpoch())}; | |||
|
114 | ||||
|
115 | auto varCRS = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 0, 0}}; | |||
|
116 | auto varCRE = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}}; | |||
|
117 | auto sqpCR = SqpRange{static_cast<double>(varCRS.toMSecsSinceEpoch()), | |||
|
118 | static_cast<double>(varCRE.toMSecsSinceEpoch())}; | |||
|
119 | ||||
|
120 | Variable var{"Var test", sqpR}; | |||
|
121 | var.setCacheRange(sqpCR); | |||
|
122 | ||||
|
123 | // 1: [ts,te] < varTS | |||
|
124 | auto ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}}; | |||
|
125 | auto te = QDateTime{QDate{2017, 01, 01}, QTime{2, 1, 0, 0}}; | |||
|
126 | auto sqp = SqpRange{static_cast<double>(ts.toMSecsSinceEpoch()), | |||
|
127 | static_cast<double>(te.toMSecsSinceEpoch())}; | |||
|
128 | ||||
|
129 | auto notInCach = var.provideInCacheRangeList(sqp); | |||
|
130 | ||||
|
131 | QCOMPARE(notInCach.size(), 0); | |||
|
132 | ||||
|
133 | // 2: ts < varTS < te < varTE | |||
|
134 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}}; | |||
|
135 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 30, 0}}; | |||
|
136 | sqp = SqpRange{static_cast<double>(ts.toMSecsSinceEpoch()), | |||
|
137 | static_cast<double>(te.toMSecsSinceEpoch())}; | |||
|
138 | notInCach = var.provideInCacheRangeList(sqp); | |||
|
139 | QCOMPARE(notInCach.size(), 1); | |||
|
140 | auto notInCachRange = notInCach.first(); | |||
|
141 | QCOMPARE(notInCachRange.m_TStart, static_cast<double>(varCRS.toMSecsSinceEpoch())); | |||
|
142 | QCOMPARE(notInCachRange.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch())); | |||
|
143 | ||||
|
144 | // 3: varTS < ts < te < varTE | |||
|
145 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 20, 0}}; | |||
|
146 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 30, 0}}; | |||
|
147 | sqp = SqpRange{static_cast<double>(ts.toMSecsSinceEpoch()), | |||
|
148 | static_cast<double>(te.toMSecsSinceEpoch())}; | |||
|
149 | notInCach = var.provideInCacheRangeList(sqp); | |||
|
150 | QCOMPARE(notInCach.size(), 1); | |||
|
151 | notInCachRange = notInCach.first(); | |||
|
152 | QCOMPARE(notInCachRange.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch())); | |||
|
153 | QCOMPARE(notInCachRange.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch())); | |||
|
154 | ||||
|
155 | // 4: varTS < ts < varTE < te | |||
|
156 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 20, 0}}; | |||
|
157 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; | |||
|
158 | sqp = SqpRange{static_cast<double>(ts.toMSecsSinceEpoch()), | |||
|
159 | static_cast<double>(te.toMSecsSinceEpoch())}; | |||
|
160 | notInCach = var.provideInCacheRangeList(sqp); | |||
|
161 | QCOMPARE(notInCach.size(), 1); | |||
|
162 | notInCachRange = notInCach.first(); | |||
|
163 | QCOMPARE(notInCachRange.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch())); | |||
|
164 | QCOMPARE(notInCachRange.m_TEnd, static_cast<double>(varCRE.toMSecsSinceEpoch())); | |||
|
165 | ||||
|
166 | // 5: varTS < varTE < ts < te | |||
|
167 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 20, 0}}; | |||
|
168 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; | |||
|
169 | sqp = SqpRange{static_cast<double>(ts.toMSecsSinceEpoch()), | |||
|
170 | static_cast<double>(te.toMSecsSinceEpoch())}; | |||
|
171 | notInCach = var.provideInCacheRangeList(sqp); | |||
|
172 | QCOMPARE(notInCach.size(), 0); | |||
|
173 | ||||
|
174 | // 6: ts <varTS < varTE < te | |||
|
175 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 1, 0, 0}}; | |||
|
176 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; | |||
|
177 | sqp = SqpRange{static_cast<double>(ts.toMSecsSinceEpoch()), | |||
|
178 | static_cast<double>(te.toMSecsSinceEpoch())}; | |||
|
179 | notInCach = var.provideInCacheRangeList(sqp); | |||
|
180 | QCOMPARE(notInCach.size(), 1); | |||
|
181 | notInCachRange = notInCach.first(); | |||
|
182 | QCOMPARE(notInCachRange.m_TStart, static_cast<double>(varCRS.toMSecsSinceEpoch())); | |||
|
183 | QCOMPARE(notInCachRange.m_TEnd, static_cast<double>(varCRE.toMSecsSinceEpoch())); | |||
|
184 | } | |||
|
185 | ||||
|
186 | ||||
|
187 | QTEST_MAIN(TestVariable) | |||
|
188 | #include "TestVariable.moc" |
@@ -219,19 +219,24 QVector<SqpRange> Variable::provideInCacheRangeList(const SqpRange &range) const | |||||
219 | auto inCache = QVector<SqpRange>{}; |
|
219 | auto inCache = QVector<SqpRange>{}; | |
220 |
|
220 | |||
221 |
|
221 | |||
222 |
if (this-> |
|
222 | if (this->intersect(range)) { | |
223 |
if (range.m_TStart <= impl->m_CacheRange.m_T |
|
223 | if (range.m_TStart <= impl->m_CacheRange.m_TStart | |
224 |
&& range.m_TEnd >= impl->m_CacheRange.m_T |
|
224 | && range.m_TEnd >= impl->m_CacheRange.m_TStart | |
225 |
|
|
225 | && range.m_TEnd < impl->m_CacheRange.m_TEnd) { | |
|
226 | inCache << SqpRange{impl->m_CacheRange.m_TStart, range.m_TEnd}; | |||
226 | } |
|
227 | } | |
227 |
|
228 | |||
228 | else if (range.m_TStart >= impl->m_CacheRange.m_TStart |
|
229 | else if (range.m_TStart >= impl->m_CacheRange.m_TStart | |
229 | && range.m_TEnd < impl->m_CacheRange.m_TEnd) { |
|
230 | && range.m_TEnd <= impl->m_CacheRange.m_TEnd) { | |
230 | inCache << range; |
|
231 | inCache << range; | |
231 | } |
|
232 | } | |
232 |
else if (range.m_TStart |
|
233 | else if (range.m_TStart > impl->m_CacheRange.m_TStart | |
233 |
&& range.m_TEnd > |
|
234 | && range.m_TEnd > impl->m_CacheRange.m_TEnd) { | |
234 |
inCache << SqpRange{impl->m_CacheRange. |
|
235 | inCache << SqpRange{range.m_TStart, impl->m_CacheRange.m_TEnd}; | |
|
236 | } | |||
|
237 | else if (range.m_TStart <= impl->m_CacheRange.m_TStart | |||
|
238 | && range.m_TEnd >= impl->m_CacheRange.m_TEnd) { | |||
|
239 | inCache << impl->m_CacheRange; | |||
235 | } |
|
240 | } | |
236 | else { |
|
241 | else { | |
237 | qCCritical(LOG_Variable()) << tr("Detection of unknown case.") |
|
242 | qCCritical(LOG_Variable()) << tr("Detection of unknown case.") |
General Comments 0
You need to be logged in to leave comments.
Login now