Mercurial > hg > svcore
comparison base/test/TestEventSeries.h @ 1616:de446dd905e6 single-point
Rework EventSeries to explicitly store counts of events (+ add comments explaining, among other things, why)
author | Chris Cannam |
---|---|
date | Fri, 08 Mar 2019 10:16:12 +0000 |
parents | 24dc8cb42755 |
children | bdc19a09a1f9 |
comparison
equal
deleted
inserted
replaced
1615:24dc8cb42755 | 1616:de446dd905e6 |
---|---|
35 QCOMPARE(s.isEmpty(), true); | 35 QCOMPARE(s.isEmpty(), true); |
36 QCOMPARE(s.count(), 0); | 36 QCOMPARE(s.count(), 0); |
37 | 37 |
38 Event p(10, QString()); | 38 Event p(10, QString()); |
39 QCOMPARE(s.contains(p), false); | 39 QCOMPARE(s.contains(p), false); |
40 QCOMPARE(s.getEventsSpanning(400), EventVector()); | 40 QCOMPARE(s.getEventsCovering(400), EventVector()); |
41 } | 41 } |
42 | 42 |
43 void singleEvent() { | 43 void singleEvent() { |
44 | 44 |
45 EventSeries s; | 45 EventSeries s; |
49 QCOMPARE(s.count(), 1); | 49 QCOMPARE(s.count(), 1); |
50 QCOMPARE(s.contains(p), true); | 50 QCOMPARE(s.contains(p), true); |
51 | 51 |
52 s.remove(p); | 52 s.remove(p); |
53 QCOMPARE(s.isEmpty(), true); | 53 QCOMPARE(s.isEmpty(), true); |
54 QCOMPARE(s.count(), 0); | |
54 QCOMPARE(s.contains(p), false); | 55 QCOMPARE(s.contains(p), false); |
55 } | 56 } |
56 | 57 |
57 void singleEventSpan() { | 58 void duplicateEvents() { |
58 | 59 |
59 EventSeries s; | 60 EventSeries s; |
60 Event p(10, QString()); | 61 Event p(10, QString()); |
61 s.add(p); | 62 s.add(p); |
62 EventVector span; | 63 s.add(p); |
63 span.push_back(p); | 64 QCOMPARE(s.isEmpty(), false); |
64 QCOMPARE(s.getEventsSpanning(10), span); | 65 QCOMPARE(s.count(), 2); |
65 QCOMPARE(s.getEventsSpanning(11), EventVector()); | 66 QCOMPARE(s.contains(p), true); |
66 QCOMPARE(s.getEventsSpanning(9), EventVector()); | 67 |
67 } | 68 s.remove(p); |
68 | 69 QCOMPARE(s.isEmpty(), false); |
69 void singleEventWithDurationSpan() { | 70 QCOMPARE(s.count(), 1); |
71 QCOMPARE(s.contains(p), true); | |
72 | |
73 s.remove(p); | |
74 QCOMPARE(s.isEmpty(), true); | |
75 QCOMPARE(s.count(), 0); | |
76 QCOMPARE(s.contains(p), false); | |
77 } | |
78 | |
79 void singleEventCover() { | |
80 | |
81 EventSeries s; | |
82 Event p(10, QString()); | |
83 s.add(p); | |
84 EventVector cover; | |
85 cover.push_back(p); | |
86 QCOMPARE(s.getEventsCovering(10), cover); | |
87 QCOMPARE(s.getEventsCovering(11), EventVector()); | |
88 QCOMPARE(s.getEventsCovering(9), EventVector()); | |
89 } | |
90 | |
91 void similarEventsCover() { | |
92 | |
93 EventSeries s; | |
94 Event a(10, QString("a")); | |
95 Event b(10, QString("b")); | |
96 s.add(a); | |
97 s.add(b); | |
98 EventVector cover; | |
99 cover.push_back(a); | |
100 cover.push_back(b); | |
101 QCOMPARE(s.getEventsCovering(10), cover); | |
102 QCOMPARE(s.getEventsCovering(11), EventVector()); | |
103 QCOMPARE(s.getEventsCovering(9), EventVector()); | |
104 } | |
105 | |
106 void singleEventWithDurationCover() { | |
70 | 107 |
71 EventSeries s; | 108 EventSeries s; |
72 Event p(10, 1.0, 20, QString()); | 109 Event p(10, 1.0, 20, QString()); |
73 s.add(p); | 110 s.add(p); |
74 EventVector span; | 111 EventVector cover; |
75 span.push_back(p); | 112 cover.push_back(p); |
76 QCOMPARE(s.getEventsSpanning(10), span); | 113 QCOMPARE(s.getEventsCovering(10), cover); |
77 QCOMPARE(s.getEventsSpanning(11), span); | 114 QCOMPARE(s.getEventsCovering(11), cover); |
78 QCOMPARE(s.getEventsSpanning(29), span); | 115 QCOMPARE(s.getEventsCovering(29), cover); |
79 QCOMPARE(s.getEventsSpanning(30), EventVector()); | 116 QCOMPARE(s.getEventsCovering(30), EventVector()); |
80 QCOMPARE(s.getEventsSpanning(9), EventVector()); | 117 QCOMPARE(s.getEventsCovering(9), EventVector()); |
81 } | 118 } |
82 | 119 |
83 void identicalEventsSpan() { | 120 void identicalEventsCover() { |
84 | 121 |
85 EventSeries s; | 122 EventSeries s; |
86 Event p(10, QString()); | 123 Event p(10, QString()); |
87 s.add(p); | 124 s.add(p); |
88 s.add(p); | 125 s.add(p); |
89 | 126 |
90 EventVector span; | 127 EventVector cover; |
91 span.push_back(p); | 128 cover.push_back(p); |
92 span.push_back(p); | 129 cover.push_back(p); |
93 QCOMPARE(s.getEventsSpanning(10), span); | 130 QCOMPARE(s.getEventsCovering(10), cover); |
94 QCOMPARE(s.getEventsSpanning(11), EventVector()); | 131 QCOMPARE(s.getEventsCovering(11), EventVector()); |
95 QCOMPARE(s.getEventsSpanning(9), EventVector()); | 132 QCOMPARE(s.getEventsCovering(9), EventVector()); |
96 | 133 |
97 s.remove(p); | 134 s.remove(p); |
98 span.clear(); | 135 cover.clear(); |
99 span.push_back(p); | 136 cover.push_back(p); |
100 QCOMPARE(s.getEventsSpanning(10), span); | 137 QCOMPARE(s.getEventsCovering(10), cover); |
101 QCOMPARE(s.getEventsSpanning(11), EventVector()); | 138 QCOMPARE(s.getEventsCovering(11), EventVector()); |
102 QCOMPARE(s.getEventsSpanning(9), EventVector()); | 139 QCOMPARE(s.getEventsCovering(9), EventVector()); |
103 } | 140 } |
104 | 141 |
105 void identicalEventsWithDurationSpan() { | 142 void identicalEventsWithDurationCover() { |
106 | 143 |
107 EventSeries s; | 144 EventSeries s; |
108 Event p(10, 1.0, 20, QString()); | 145 Event p(10, 1.0, 20, QString()); |
109 s.add(p); | 146 s.add(p); |
110 s.add(p); | 147 s.add(p); |
111 EventVector span; | 148 EventVector cover; |
112 span.push_back(p); | 149 cover.push_back(p); |
113 span.push_back(p); | 150 cover.push_back(p); |
114 QCOMPARE(s.getEventsSpanning(10), span); | 151 QCOMPARE(s.getEventsCovering(10), cover); |
115 QCOMPARE(s.getEventsSpanning(11), span); | 152 QCOMPARE(s.getEventsCovering(11), cover); |
116 QCOMPARE(s.getEventsSpanning(29), span); | 153 QCOMPARE(s.getEventsCovering(29), cover); |
117 QCOMPARE(s.getEventsSpanning(30), EventVector()); | 154 QCOMPARE(s.getEventsCovering(30), EventVector()); |
118 QCOMPARE(s.getEventsSpanning(9), EventVector()); | 155 QCOMPARE(s.getEventsCovering(9), EventVector()); |
119 | 156 |
120 s.remove(p); | 157 s.remove(p); |
121 span.clear(); | 158 cover.clear(); |
122 span.push_back(p); | 159 cover.push_back(p); |
123 QCOMPARE(s.getEventsSpanning(10), span); | 160 QCOMPARE(s.getEventsCovering(10), cover); |
124 QCOMPARE(s.getEventsSpanning(11), span); | 161 QCOMPARE(s.getEventsCovering(11), cover); |
125 QCOMPARE(s.getEventsSpanning(29), span); | 162 QCOMPARE(s.getEventsCovering(29), cover); |
126 QCOMPARE(s.getEventsSpanning(30), EventVector()); | 163 QCOMPARE(s.getEventsCovering(30), EventVector()); |
127 QCOMPARE(s.getEventsSpanning(9), EventVector()); | 164 QCOMPARE(s.getEventsCovering(9), EventVector()); |
128 } | 165 } |
129 | 166 |
130 void multipleEventsSpan() { | 167 void multipleEventsCover() { |
131 | 168 |
132 EventSeries s; | 169 EventSeries s; |
133 Event a(10, QString("a")); | 170 Event a(10, QString("a")); |
134 Event b(11, QString("b")); | 171 Event b(11, QString("b")); |
135 Event c(40, QString("c")); | 172 Event c(40, QString("c")); |
139 s.remove(a); | 176 s.remove(a); |
140 s.add(a); | 177 s.add(a); |
141 s.add(c); | 178 s.add(c); |
142 s.remove(c); | 179 s.remove(c); |
143 QCOMPARE(s.count(), 3); | 180 QCOMPARE(s.count(), 3); |
144 EventVector span; | 181 EventVector cover; |
145 span.push_back(a); | 182 cover.push_back(a); |
146 QCOMPARE(s.getEventsSpanning(10), span); | 183 QCOMPARE(s.getEventsCovering(10), cover); |
147 span.clear(); | 184 cover.clear(); |
148 span.push_back(c); | 185 cover.push_back(c); |
149 QCOMPARE(s.getEventsSpanning(40), span); | 186 QCOMPARE(s.getEventsCovering(40), cover); |
150 QCOMPARE(s.getEventsSpanning(9), EventVector()); | 187 QCOMPARE(s.getEventsCovering(9), EventVector()); |
151 } | 188 } |
152 | 189 |
153 void disjointEventsWithDurationSpan() { | 190 void disjointEventsWithDurationCover() { |
154 | 191 |
155 EventSeries s; | 192 EventSeries s; |
156 Event a(10, 1.0f, 20, QString("a")); | 193 Event a(10, 1.0f, 20, QString("a")); |
157 Event b(100, 1.2f, 30, QString("b")); | 194 Event b(100, 1.2f, 30, QString("b")); |
158 s.add(a); | 195 s.add(a); |
159 s.add(b); | 196 s.add(b); |
160 QCOMPARE(s.getEventsSpanning(0), EventVector()); | 197 QCOMPARE(s.getEventsCovering(0), EventVector()); |
161 QCOMPARE(s.getEventsSpanning(10), EventVector({ a })); | 198 QCOMPARE(s.getEventsCovering(10), EventVector({ a })); |
162 QCOMPARE(s.getEventsSpanning(15), EventVector({ a })); | 199 QCOMPARE(s.getEventsCovering(15), EventVector({ a })); |
163 QCOMPARE(s.getEventsSpanning(30), EventVector()); | 200 QCOMPARE(s.getEventsCovering(30), EventVector()); |
164 QCOMPARE(s.getEventsSpanning(99), EventVector()); | 201 QCOMPARE(s.getEventsCovering(99), EventVector()); |
165 QCOMPARE(s.getEventsSpanning(100), EventVector({ b })); | 202 QCOMPARE(s.getEventsCovering(100), EventVector({ b })); |
166 QCOMPARE(s.getEventsSpanning(120), EventVector({ b })); | 203 QCOMPARE(s.getEventsCovering(120), EventVector({ b })); |
167 QCOMPARE(s.getEventsSpanning(130), EventVector()); | 204 QCOMPARE(s.getEventsCovering(130), EventVector()); |
168 } | 205 } |
169 | 206 |
170 void overlappingEventsWithAndWithoutDurationSpan() { | 207 void overlappingEventsWithAndWithoutDurationCover() { |
171 | 208 |
172 EventSeries s; | 209 EventSeries s; |
173 Event p(20, QString("p")); | 210 Event p(20, QString("p")); |
174 Event a(10, 1.0, 20, QString("a")); | 211 Event a(10, 1.0f, 20, QString("a")); |
175 s.add(p); | 212 s.add(p); |
176 s.add(a); | 213 s.add(a); |
177 EventVector span; | 214 EventVector cover; |
178 span.push_back(a); | 215 cover.push_back(a); |
179 QCOMPARE(s.getEventsSpanning(15), span); | 216 QCOMPARE(s.getEventsCovering(15), cover); |
180 QCOMPARE(s.getEventsSpanning(25), span); | 217 QCOMPARE(s.getEventsCovering(25), cover); |
181 span.clear(); | 218 cover.clear(); |
182 span.push_back(p); | 219 cover.push_back(p); |
183 span.push_back(a); | 220 cover.push_back(a); |
184 QCOMPARE(s.getEventsSpanning(20), span); | 221 QCOMPARE(s.getEventsCovering(20), cover); |
185 } | 222 } |
186 | 223 |
187 void overlappingEventsWithDurationSpan() { | 224 void overlappingEventsWithDurationCover() { |
188 | 225 |
189 EventSeries s; | 226 EventSeries s; |
190 Event a(20, 1.0, 10, QString("a")); | 227 Event a(20, 1.0f, 10, QString("a")); |
191 Event b(10, 1.0, 20, QString("b")); | 228 Event b(10, 1.0f, 20, QString("b")); |
192 Event c(10, 1.0, 40, QString("c")); | 229 Event c(10, 1.0f, 40, QString("c")); |
193 s.add(a); | 230 s.add(a); |
194 s.add(b); | 231 s.add(b); |
195 s.add(c); | 232 s.add(c); |
196 QCOMPARE(s.getEventsSpanning(10), EventVector({ b, c })); | 233 QCOMPARE(s.getEventsCovering(10), EventVector({ b, c })); |
197 QCOMPARE(s.getEventsSpanning(20), EventVector({ b, c, a })); | 234 QCOMPARE(s.getEventsCovering(20), EventVector({ b, c, a })); |
198 QCOMPARE(s.getEventsSpanning(25), EventVector({ b, c, a })); | 235 QCOMPARE(s.getEventsCovering(25), EventVector({ b, c, a })); |
199 QCOMPARE(s.getEventsSpanning(30), EventVector({ c })); | 236 QCOMPARE(s.getEventsCovering(30), EventVector({ c })); |
200 QCOMPARE(s.getEventsSpanning(40), EventVector({ c })); | 237 QCOMPARE(s.getEventsCovering(40), EventVector({ c })); |
201 QCOMPARE(s.getEventsSpanning(50), EventVector()); | 238 QCOMPARE(s.getEventsCovering(50), EventVector()); |
202 } | 239 } |
203 | 240 |
204 void eventPatternSpan() { | 241 void eventPatternCover() { |
205 | 242 |
206 EventSeries s; | 243 EventSeries s; |
207 Event a(0, 1.0, 18, QString("a")); | 244 Event a(0, 1.0f, 18, QString("a")); |
208 Event b(3, 2.0, 6, QString("b")); | 245 Event b(3, 2.0f, 6, QString("b")); |
209 Event c(5, 3.0, 2, QString("c")); | 246 Event c(5, 3.0f, 2, QString("c")); |
210 Event d(6, 4.0, 10, QString("d")); | 247 Event cc(5, 3.1f, 2, QString("cc")); |
211 Event e(14, 5.0, 3, QString("e")); | 248 Event d(6, 4.0f, 10, QString("d")); |
249 Event dd(6, 4.5f, 10, QString("dd")); | |
250 Event e(14, 5.0f, 3, QString("e")); | |
212 s.add(b); | 251 s.add(b); |
213 s.add(c); | 252 s.add(c); |
214 s.add(d); | 253 s.add(d); |
215 s.add(a); | 254 s.add(a); |
255 s.add(cc); | |
256 s.add(dd); | |
216 s.add(e); | 257 s.add(e); |
217 QCOMPARE(s.getEventsSpanning(8), EventVector({ a, b, d })); | 258 QCOMPARE(s.getEventsCovering(8), EventVector({ a, b, d, dd })); |
259 } | |
260 | |
261 void eventPatternAddRemove() { | |
262 | |
263 // This is mostly here to exercise the innards of EventSeries | |
264 // and check it doesn't crash out with any internal | |
265 // consistency problems | |
266 | |
267 EventSeries s; | |
268 Event a(0, 1.0f, 18, QString("a")); | |
269 Event b(3, 2.0f, 6, QString("b")); | |
270 Event c(5, 3.0f, 2, QString("c")); | |
271 Event cc(5, 3.1f, 2, QString("cc")); | |
272 Event d(6, 4.0f, 10, QString("d")); | |
273 Event dd(6, 4.5f, 10, QString("dd")); | |
274 Event e(14, 5.0f, 3, QString("e")); | |
275 s.add(b); | |
276 s.add(c); | |
277 s.add(d); | |
278 s.add(a); | |
279 s.add(cc); | |
280 s.add(dd); | |
281 s.add(e); | |
282 QCOMPARE(s.count(), 7); | |
283 s.remove(d); | |
284 QCOMPARE(s.getEventsCovering(8), EventVector({ a, b, dd })); | |
285 s.remove(e); | |
286 s.remove(a); | |
287 QCOMPARE(s.getEventsCovering(8), EventVector({ b, dd })); | |
288 s.remove(cc); | |
289 s.remove(c); | |
290 s.remove(dd); | |
291 QCOMPARE(s.getEventsCovering(8), EventVector({ b })); | |
292 s.remove(b); | |
293 QCOMPARE(s.getEventsCovering(8), EventVector()); | |
294 QCOMPARE(s.count(), 0); | |
295 QCOMPARE(s.isEmpty(), true); | |
218 } | 296 } |
219 }; | 297 }; |
220 | 298 |
221 #endif | 299 #endif |