annotate base/test/TestEventSeries.h @ 1651:7a56bb85030f single-point

Introduce deferred notifier, + start converting sparse time-value model (perhaps we should rename it too)
author Chris Cannam
date Mon, 18 Mar 2019 14:17:20 +0000
parents e7f557789f99
children eaad70939848
rev   line source
Chris@1612 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@1612 2
Chris@1612 3 /*
Chris@1612 4 Sonic Visualiser
Chris@1612 5 An audio file viewer and annotation editor.
Chris@1612 6 Centre for Digital Music, Queen Mary, University of London.
Chris@1612 7
Chris@1612 8 This program is free software; you can redistribute it and/or
Chris@1612 9 modify it under the terms of the GNU General Public License as
Chris@1612 10 published by the Free Software Foundation; either version 2 of the
Chris@1612 11 License, or (at your option) any later version. See the file
Chris@1612 12 COPYING included with this distribution for more information.
Chris@1612 13 */
Chris@1612 14
Chris@1615 15 #ifndef TEST_EVENT_SERIES_H
Chris@1615 16 #define TEST_EVENT_SERIES_H
Chris@1612 17
Chris@1615 18 #include "../EventSeries.h"
Chris@1612 19
Chris@1612 20 #include <QObject>
Chris@1612 21 #include <QtTest>
Chris@1612 22
Chris@1612 23 #include <iostream>
Chris@1612 24
Chris@1612 25 using namespace std;
Chris@1612 26
Chris@1615 27 class TestEventSeries : public QObject
Chris@1612 28 {
Chris@1612 29 Q_OBJECT
Chris@1612 30
Chris@1612 31 private slots:
Chris@1612 32 void empty() {
Chris@1612 33
Chris@1615 34 EventSeries s;
Chris@1612 35 QCOMPARE(s.isEmpty(), true);
Chris@1612 36 QCOMPARE(s.count(), 0);
Chris@1612 37
Chris@1615 38 Event p(10, QString());
Chris@1612 39 QCOMPARE(s.contains(p), false);
Chris@1616 40 QCOMPARE(s.getEventsCovering(400), EventVector());
Chris@1612 41 }
Chris@1612 42
Chris@1615 43 void singleEvent() {
Chris@1612 44
Chris@1615 45 EventSeries s;
Chris@1615 46 Event p(10, QString());
Chris@1612 47 s.add(p);
Chris@1612 48 QCOMPARE(s.isEmpty(), false);
Chris@1612 49 QCOMPARE(s.count(), 1);
Chris@1612 50 QCOMPARE(s.contains(p), true);
Chris@1612 51
Chris@1612 52 s.remove(p);
Chris@1612 53 QCOMPARE(s.isEmpty(), true);
Chris@1616 54 QCOMPARE(s.count(), 0);
Chris@1612 55 QCOMPARE(s.contains(p), false);
Chris@1612 56 }
Chris@1612 57
Chris@1616 58 void duplicateEvents() {
Chris@1612 59
Chris@1615 60 EventSeries s;
Chris@1615 61 Event p(10, QString());
Chris@1612 62 s.add(p);
Chris@1616 63 s.add(p);
Chris@1616 64 QCOMPARE(s.isEmpty(), false);
Chris@1616 65 QCOMPARE(s.count(), 2);
Chris@1616 66 QCOMPARE(s.contains(p), true);
Chris@1616 67
Chris@1616 68 s.remove(p);
Chris@1616 69 QCOMPARE(s.isEmpty(), false);
Chris@1616 70 QCOMPARE(s.count(), 1);
Chris@1616 71 QCOMPARE(s.contains(p), true);
Chris@1616 72
Chris@1616 73 s.remove(p);
Chris@1616 74 QCOMPARE(s.isEmpty(), true);
Chris@1616 75 QCOMPARE(s.count(), 0);
Chris@1616 76 QCOMPARE(s.contains(p), false);
Chris@1612 77 }
Chris@1612 78
Chris@1616 79 void singleEventCover() {
Chris@1616 80
Chris@1616 81 EventSeries s;
Chris@1616 82 Event p(10, QString());
Chris@1616 83 s.add(p);
Chris@1616 84 EventVector cover;
Chris@1616 85 cover.push_back(p);
Chris@1616 86 QCOMPARE(s.getEventsCovering(10), cover);
Chris@1616 87 QCOMPARE(s.getEventsCovering(11), EventVector());
Chris@1616 88 QCOMPARE(s.getEventsCovering(9), EventVector());
Chris@1616 89 }
Chris@1616 90
Chris@1617 91 void singleEventSpan() {
Chris@1617 92
Chris@1617 93 EventSeries s;
Chris@1617 94 Event p(10, QString());
Chris@1617 95 s.add(p);
Chris@1617 96 EventVector span;
Chris@1617 97 span.push_back(p);
Chris@1617 98 QCOMPARE(s.getEventsSpanning(10, 2), span);
Chris@1617 99 QCOMPARE(s.getEventsSpanning(9, 2), span);
Chris@1617 100 QCOMPARE(s.getEventsSpanning(8, 2), EventVector());
Chris@1617 101 QCOMPARE(s.getEventsSpanning(7, 2), EventVector());
Chris@1617 102 QCOMPARE(s.getEventsSpanning(11, 2), EventVector());
Chris@1617 103 }
Chris@1617 104
Chris@1617 105 void identicalEventsCover() {
Chris@1617 106
Chris@1617 107 EventSeries s;
Chris@1617 108 Event p(10, QString());
Chris@1617 109 s.add(p);
Chris@1617 110 s.add(p);
Chris@1617 111
Chris@1617 112 EventVector cover;
Chris@1617 113 cover.push_back(p);
Chris@1617 114 cover.push_back(p);
Chris@1617 115 QCOMPARE(s.getEventsCovering(10), cover);
Chris@1617 116 QCOMPARE(s.getEventsCovering(11), EventVector());
Chris@1617 117 QCOMPARE(s.getEventsCovering(9), EventVector());
Chris@1617 118
Chris@1617 119 s.remove(p);
Chris@1617 120 cover.clear();
Chris@1617 121 cover.push_back(p);
Chris@1617 122 QCOMPARE(s.getEventsCovering(10), cover);
Chris@1617 123 QCOMPARE(s.getEventsCovering(11), EventVector());
Chris@1617 124 QCOMPARE(s.getEventsCovering(9), EventVector());
Chris@1617 125 }
Chris@1617 126
Chris@1617 127 void identicalEventsSpan() {
Chris@1617 128
Chris@1617 129 EventSeries s;
Chris@1617 130 Event p(10, QString());
Chris@1617 131 s.add(p);
Chris@1617 132 s.add(p);
Chris@1617 133
Chris@1617 134 EventVector span;
Chris@1617 135 span.push_back(p);
Chris@1617 136 span.push_back(p);
Chris@1617 137 QCOMPARE(s.getEventsSpanning(10, 2), span);
Chris@1617 138 QCOMPARE(s.getEventsSpanning(9, 2), span);
Chris@1617 139 QCOMPARE(s.getEventsSpanning(8, 2), EventVector());
Chris@1617 140 QCOMPARE(s.getEventsSpanning(11, 2), EventVector());
Chris@1617 141 }
Chris@1617 142
Chris@1616 143 void similarEventsCover() {
Chris@1616 144
Chris@1616 145 EventSeries s;
Chris@1616 146 Event a(10, QString("a"));
Chris@1616 147 Event b(10, QString("b"));
Chris@1616 148 s.add(a);
Chris@1616 149 s.add(b);
Chris@1616 150 EventVector cover;
Chris@1616 151 cover.push_back(a);
Chris@1616 152 cover.push_back(b);
Chris@1616 153 QCOMPARE(s.getEventsCovering(10), cover);
Chris@1616 154 QCOMPARE(s.getEventsCovering(11), EventVector());
Chris@1616 155 QCOMPARE(s.getEventsCovering(9), EventVector());
Chris@1616 156 }
Chris@1616 157
Chris@1617 158 void similarEventsSpan() {
Chris@1617 159
Chris@1617 160 EventSeries s;
Chris@1617 161 Event a(10, QString("a"));
Chris@1617 162 Event b(10, QString("b"));
Chris@1617 163 s.add(a);
Chris@1617 164 s.add(b);
Chris@1617 165 EventVector span;
Chris@1617 166 span.push_back(a);
Chris@1617 167 span.push_back(b);
Chris@1617 168 QCOMPARE(s.getEventsSpanning(10, 2), span);
Chris@1617 169 QCOMPARE(s.getEventsSpanning(9, 2), span);
Chris@1617 170 QCOMPARE(s.getEventsSpanning(11, 2), EventVector());
Chris@1617 171 QCOMPARE(s.getEventsSpanning(8, 2), EventVector());
Chris@1617 172 }
Chris@1617 173
Chris@1616 174 void singleEventWithDurationCover() {
Chris@1612 175
Chris@1615 176 EventSeries s;
Chris@1615 177 Event p(10, 1.0, 20, QString());
Chris@1612 178 s.add(p);
Chris@1616 179 EventVector cover;
Chris@1616 180 cover.push_back(p);
Chris@1616 181 QCOMPARE(s.getEventsCovering(10), cover);
Chris@1616 182 QCOMPARE(s.getEventsCovering(11), cover);
Chris@1616 183 QCOMPARE(s.getEventsCovering(29), cover);
Chris@1616 184 QCOMPARE(s.getEventsCovering(30), EventVector());
Chris@1616 185 QCOMPARE(s.getEventsCovering(9), EventVector());
Chris@1612 186 }
Chris@1614 187
Chris@1617 188 void singleEventWithDurationSpan() {
Chris@1614 189
Chris@1615 190 EventSeries s;
Chris@1617 191 Event p(10, 1.0, 20, QString());
Chris@1614 192 s.add(p);
Chris@1617 193 EventVector span;
Chris@1617 194 span.push_back(p);
Chris@1617 195 QCOMPARE(s.getEventsSpanning(9, 2), span);
Chris@1617 196 QCOMPARE(s.getEventsSpanning(8, 2), EventVector());
Chris@1617 197 QCOMPARE(s.getEventsSpanning(19, 4), span);
Chris@1617 198 QCOMPARE(s.getEventsSpanning(29, 2), span);
Chris@1617 199 QCOMPARE(s.getEventsSpanning(30, 2), EventVector());
Chris@1617 200 }
Chris@1614 201
Chris@1616 202 void identicalEventsWithDurationCover() {
Chris@1614 203
Chris@1615 204 EventSeries s;
Chris@1615 205 Event p(10, 1.0, 20, QString());
Chris@1614 206 s.add(p);
Chris@1614 207 s.add(p);
Chris@1616 208 EventVector cover;
Chris@1616 209 cover.push_back(p);
Chris@1616 210 cover.push_back(p);
Chris@1616 211 QCOMPARE(s.getEventsCovering(10), cover);
Chris@1616 212 QCOMPARE(s.getEventsCovering(11), cover);
Chris@1616 213 QCOMPARE(s.getEventsCovering(29), cover);
Chris@1616 214 QCOMPARE(s.getEventsCovering(30), EventVector());
Chris@1616 215 QCOMPARE(s.getEventsCovering(9), EventVector());
Chris@1614 216
Chris@1614 217 s.remove(p);
Chris@1616 218 cover.clear();
Chris@1616 219 cover.push_back(p);
Chris@1616 220 QCOMPARE(s.getEventsCovering(10), cover);
Chris@1616 221 QCOMPARE(s.getEventsCovering(11), cover);
Chris@1616 222 QCOMPARE(s.getEventsCovering(29), cover);
Chris@1616 223 QCOMPARE(s.getEventsCovering(30), EventVector());
Chris@1616 224 QCOMPARE(s.getEventsCovering(9), EventVector());
Chris@1614 225 }
Chris@1614 226
Chris@1617 227 void identicalEventsWithDurationSpan() {
Chris@1617 228
Chris@1617 229 EventSeries s;
Chris@1617 230 Event p(10, 1.0, 20, QString());
Chris@1617 231 s.add(p);
Chris@1617 232 s.add(p);
Chris@1617 233 EventVector span;
Chris@1617 234 span.push_back(p);
Chris@1617 235 span.push_back(p);
Chris@1617 236 QCOMPARE(s.getEventsSpanning(9, 2), span);
Chris@1617 237 QCOMPARE(s.getEventsSpanning(10, 2), span);
Chris@1617 238 QCOMPARE(s.getEventsSpanning(11, 2), span);
Chris@1617 239 QCOMPARE(s.getEventsSpanning(29, 2), span);
Chris@1617 240 QCOMPARE(s.getEventsSpanning(30, 2), EventVector());
Chris@1617 241 QCOMPARE(s.getEventsSpanning(8, 2), EventVector());
Chris@1617 242 }
Chris@1617 243
Chris@1616 244 void multipleEventsCover() {
Chris@1614 245
Chris@1615 246 EventSeries s;
Chris@1615 247 Event a(10, QString("a"));
Chris@1615 248 Event b(11, QString("b"));
Chris@1615 249 Event c(40, QString("c"));
Chris@1614 250 s.add(c);
Chris@1614 251 s.add(a);
Chris@1614 252 s.add(b);
Chris@1614 253 s.remove(a);
Chris@1614 254 s.add(a);
Chris@1614 255 s.add(c);
Chris@1614 256 s.remove(c);
Chris@1614 257 QCOMPARE(s.count(), 3);
Chris@1616 258 EventVector cover;
Chris@1616 259 cover.push_back(a);
Chris@1616 260 QCOMPARE(s.getEventsCovering(10), cover);
Chris@1616 261 cover.clear();
Chris@1616 262 cover.push_back(c);
Chris@1616 263 QCOMPARE(s.getEventsCovering(40), cover);
Chris@1616 264 QCOMPARE(s.getEventsCovering(9), EventVector());
Chris@1614 265 }
Chris@1614 266
Chris@1617 267 void multipleEventsSpan() {
Chris@1617 268
Chris@1617 269 EventSeries s;
Chris@1617 270 Event a(10, QString("a"));
Chris@1617 271 Event b(11, QString("b"));
Chris@1617 272 Event c(40, QString("c"));
Chris@1617 273 s.add(c);
Chris@1617 274 s.add(a);
Chris@1617 275 s.add(b);
Chris@1617 276 EventVector span;
Chris@1617 277 span.push_back(a);
Chris@1617 278 span.push_back(b);
Chris@1617 279 QCOMPARE(s.getEventsSpanning(10, 2), span);
Chris@1617 280 span.clear();
Chris@1617 281 span.push_back(c);
Chris@1617 282 QCOMPARE(s.getEventsSpanning(39, 3), span);
Chris@1617 283 QCOMPARE(s.getEventsSpanning(9, 1), EventVector());
Chris@1617 284 QCOMPARE(s.getEventsSpanning(10, 0), EventVector());
Chris@1617 285 }
Chris@1617 286
Chris@1640 287 void multipleEventsEndFrame() {
Chris@1640 288
Chris@1640 289 EventSeries s;
Chris@1640 290 Event a(10, QString("a"));
Chris@1640 291 Event b(11, QString("b"));
Chris@1640 292 Event c(40, QString("c"));
Chris@1640 293 s.add(c);
Chris@1640 294 s.add(a);
Chris@1640 295 s.add(b);
Chris@1640 296 s.add(b);
Chris@1640 297 QCOMPARE(s.getEndFrame(), 40);
Chris@1640 298 s.remove(c);
Chris@1640 299 QCOMPARE(s.getEndFrame(), 11);
Chris@1640 300 s.remove(b);
Chris@1640 301 QCOMPARE(s.getEndFrame(), 11);
Chris@1640 302 s.remove(a);
Chris@1640 303 QCOMPARE(s.getEndFrame(), 11);
Chris@1640 304 s.remove(b);
Chris@1640 305 QCOMPARE(s.getEndFrame(), 0);
Chris@1640 306 }
Chris@1640 307
Chris@1616 308 void disjointEventsWithDurationCover() {
Chris@1614 309
Chris@1615 310 EventSeries s;
Chris@1615 311 Event a(10, 1.0f, 20, QString("a"));
Chris@1615 312 Event b(100, 1.2f, 30, QString("b"));
Chris@1614 313 s.add(a);
Chris@1614 314 s.add(b);
Chris@1616 315 QCOMPARE(s.getEventsCovering(0), EventVector());
Chris@1616 316 QCOMPARE(s.getEventsCovering(10), EventVector({ a }));
Chris@1616 317 QCOMPARE(s.getEventsCovering(15), EventVector({ a }));
Chris@1616 318 QCOMPARE(s.getEventsCovering(30), EventVector());
Chris@1616 319 QCOMPARE(s.getEventsCovering(99), EventVector());
Chris@1616 320 QCOMPARE(s.getEventsCovering(100), EventVector({ b }));
Chris@1616 321 QCOMPARE(s.getEventsCovering(120), EventVector({ b }));
Chris@1616 322 QCOMPARE(s.getEventsCovering(130), EventVector());
Chris@1614 323 }
Chris@1614 324
Chris@1619 325 void disjointEventsWithDurationSpan() {
Chris@1619 326
Chris@1619 327 EventSeries s;
Chris@1619 328 Event a(10, 1.0f, 20, QString("a"));
Chris@1619 329 Event b(100, 1.2f, 30, QString("b"));
Chris@1619 330 s.add(a);
Chris@1619 331 s.add(b);
Chris@1619 332 QCOMPARE(s.getEventsSpanning(0, 10), EventVector());
Chris@1619 333 QCOMPARE(s.getEventsSpanning(10, 10), EventVector({ a }));
Chris@1619 334 QCOMPARE(s.getEventsSpanning(15, 85), EventVector({ a }));
Chris@1619 335 QCOMPARE(s.getEventsSpanning(30, 5), EventVector());
Chris@1619 336 QCOMPARE(s.getEventsSpanning(99, 1), EventVector());
Chris@1619 337 QCOMPARE(s.getEventsSpanning(100, 1), EventVector({ b }));
Chris@1619 338 QCOMPARE(s.getEventsSpanning(120, 20), EventVector({ b }));
Chris@1619 339 QCOMPARE(s.getEventsSpanning(130, 109), EventVector());
Chris@1619 340 }
Chris@1619 341
Chris@1616 342 void overlappingEventsWithAndWithoutDurationCover() {
Chris@1614 343
Chris@1615 344 EventSeries s;
Chris@1615 345 Event p(20, QString("p"));
Chris@1616 346 Event a(10, 1.0f, 20, QString("a"));
Chris@1614 347 s.add(p);
Chris@1614 348 s.add(a);
Chris@1616 349 EventVector cover;
Chris@1616 350 cover.push_back(a);
Chris@1616 351 QCOMPARE(s.getEventsCovering(15), cover);
Chris@1616 352 QCOMPARE(s.getEventsCovering(25), cover);
Chris@1616 353 cover.clear();
Chris@1616 354 cover.push_back(p);
Chris@1616 355 cover.push_back(a);
Chris@1616 356 QCOMPARE(s.getEventsCovering(20), cover);
Chris@1614 357 }
Chris@1619 358
Chris@1619 359 void overlappingEventsWithAndWithoutDurationSpan() {
Chris@1619 360
Chris@1619 361 EventSeries s;
Chris@1619 362 Event p(20, QString("p"));
Chris@1619 363 Event a(10, 1.0f, 20, QString("a"));
Chris@1619 364 s.add(p);
Chris@1619 365 s.add(a);
Chris@1619 366 EventVector span;
Chris@1619 367 span.push_back(a);
Chris@1619 368 QCOMPARE(s.getEventsSpanning(5, 10), span);
Chris@1619 369 QCOMPARE(s.getEventsSpanning(25, 5), span);
Chris@1619 370 span.clear();
Chris@1619 371 span.push_back(p);
Chris@1619 372 span.push_back(a);
Chris@1619 373 QCOMPARE(s.getEventsSpanning(20, 1), span);
Chris@1619 374 }
Chris@1614 375
Chris@1616 376 void overlappingEventsWithDurationCover() {
Chris@1614 377
Chris@1615 378 EventSeries s;
Chris@1616 379 Event a(20, 1.0f, 10, QString("a"));
Chris@1616 380 Event b(10, 1.0f, 20, QString("b"));
Chris@1616 381 Event c(10, 1.0f, 40, QString("c"));
Chris@1614 382 s.add(a);
Chris@1614 383 s.add(b);
Chris@1614 384 s.add(c);
Chris@1616 385 QCOMPARE(s.getEventsCovering(10), EventVector({ b, c }));
Chris@1616 386 QCOMPARE(s.getEventsCovering(20), EventVector({ b, c, a }));
Chris@1616 387 QCOMPARE(s.getEventsCovering(25), EventVector({ b, c, a }));
Chris@1616 388 QCOMPARE(s.getEventsCovering(30), EventVector({ c }));
Chris@1616 389 QCOMPARE(s.getEventsCovering(40), EventVector({ c }));
Chris@1616 390 QCOMPARE(s.getEventsCovering(50), EventVector());
Chris@1614 391 }
Chris@1614 392
Chris@1619 393 void overlappingEventsWithDurationSpan() {
Chris@1619 394
Chris@1619 395 EventSeries s;
Chris@1619 396 Event a(20, 1.0f, 10, QString("a"));
Chris@1619 397 Event b(10, 1.0f, 20, QString("b"));
Chris@1619 398 Event c(10, 1.0f, 40, QString("c"));
Chris@1619 399 s.add(a);
Chris@1619 400 s.add(b);
Chris@1619 401 s.add(c);
Chris@1619 402 QCOMPARE(s.getEventsSpanning(10, 5), EventVector({ b, c }));
Chris@1619 403 QCOMPARE(s.getEventsSpanning(20, 15), EventVector({ b, c, a }));
Chris@1619 404 QCOMPARE(s.getEventsSpanning(0, 100), EventVector({ b, c, a }));
Chris@1619 405 QCOMPARE(s.getEventsSpanning(25, 4), EventVector({ b, c, a }));
Chris@1619 406 QCOMPARE(s.getEventsSpanning(30, 4), EventVector({ c }));
Chris@1619 407 QCOMPARE(s.getEventsSpanning(40, 15), EventVector({ c }));
Chris@1619 408 QCOMPARE(s.getEventsSpanning(50, 10), EventVector());
Chris@1619 409 }
Chris@1619 410
Chris@1616 411 void eventPatternCover() {
Chris@1614 412
Chris@1615 413 EventSeries s;
Chris@1616 414 Event a(0, 1.0f, 18, QString("a"));
Chris@1616 415 Event b(3, 2.0f, 6, QString("b"));
Chris@1616 416 Event c(5, 3.0f, 2, QString("c"));
Chris@1616 417 Event cc(5, 3.1f, 2, QString("cc"));
Chris@1616 418 Event d(6, 4.0f, 10, QString("d"));
Chris@1616 419 Event dd(6, 4.5f, 10, QString("dd"));
Chris@1616 420 Event e(14, 5.0f, 3, QString("e"));
Chris@1614 421 s.add(b);
Chris@1614 422 s.add(c);
Chris@1614 423 s.add(d);
Chris@1614 424 s.add(a);
Chris@1616 425 s.add(cc);
Chris@1616 426 s.add(dd);
Chris@1614 427 s.add(e);
Chris@1616 428 QCOMPARE(s.getEventsCovering(8), EventVector({ a, b, d, dd }));
Chris@1616 429 }
Chris@1616 430
Chris@1619 431 void eventPatternSpan() {
Chris@1619 432
Chris@1619 433 EventSeries s;
Chris@1619 434 Event a(0, 1.0f, 18, QString("a"));
Chris@1619 435 Event b(3, 2.0f, 6, QString("b"));
Chris@1619 436 Event c(5, 3.0f, 2, QString("c"));
Chris@1619 437 Event cc(5, 3.1f, 2, QString("cc"));
Chris@1619 438 Event d(6, 4.0f, 10, QString("d"));
Chris@1619 439 Event dd(6, 4.5f, 10, QString("dd"));
Chris@1619 440 Event e(14, 5.0f, 3, QString("e"));
Chris@1619 441 s.add(b);
Chris@1619 442 s.add(c);
Chris@1619 443 s.add(d);
Chris@1619 444 s.add(a);
Chris@1619 445 s.add(cc);
Chris@1619 446 s.add(dd);
Chris@1619 447 s.add(e);
Chris@1619 448 QCOMPARE(s.getEventsSpanning(6, 2), EventVector({ a, b, c, cc, d, dd }));
Chris@1619 449 }
Chris@1619 450
Chris@1635 451 void eventPatternWithin() {
Chris@1635 452
Chris@1635 453 EventSeries s;
Chris@1635 454 Event a(0, 1.0f, 18, QString("a"));
Chris@1635 455 Event b(3, 2.0f, 6, QString("b"));
Chris@1635 456 Event c(5, 3.0f, 2, QString("c"));
Chris@1635 457 Event cc(5, 3.1f, 2, QString("cc"));
Chris@1635 458 Event d(6, 4.0f, 10, QString("d"));
Chris@1635 459 Event dd(6, 4.5f, 10, QString("dd"));
Chris@1635 460 Event e(14, 5.0f, 3, QString("e"));
Chris@1635 461 s.add(b);
Chris@1635 462 s.add(c);
Chris@1635 463 s.add(d);
Chris@1635 464 s.add(a);
Chris@1635 465 s.add(cc);
Chris@1635 466 s.add(dd);
Chris@1635 467 s.add(e);
Chris@1635 468 QCOMPARE(s.getEventsWithin(2, 7), EventVector({ b, c, cc }));
Chris@1635 469 }
Chris@1635 470
Chris@1639 471 void eventPatternStartingWithin() {
Chris@1639 472
Chris@1639 473 EventSeries s;
Chris@1639 474 Event a(0, 1.0f, 18, QString("a"));
Chris@1639 475 Event b(3, 2.0f, 6, QString("b"));
Chris@1639 476 Event c(5, 3.0f, 2, QString("c"));
Chris@1639 477 Event cc(5, 3.1f, 2, QString("cc"));
Chris@1639 478 Event d(6, 4.0f, 10, QString("d"));
Chris@1639 479 Event dd(6, 4.5f, 10, QString("dd"));
Chris@1639 480 Event e(14, 5.0f, 3, QString("e"));
Chris@1639 481 s.add(b);
Chris@1639 482 s.add(c);
Chris@1639 483 s.add(d);
Chris@1639 484 s.add(a);
Chris@1639 485 s.add(cc);
Chris@1639 486 s.add(dd);
Chris@1639 487 s.add(e);
Chris@1639 488 QCOMPARE(s.getEventsStartingWithin(2, 7),
Chris@1639 489 EventVector({ b, c, cc, d, dd }));
Chris@1639 490 }
Chris@1639 491
Chris@1640 492 void eventPatternEndFrame() {
Chris@1640 493
Chris@1640 494 EventSeries s;
Chris@1640 495 Event a(0, 1.0f, 18, QString("a"));
Chris@1640 496 Event b(3, 2.0f, 6, QString("b"));
Chris@1640 497 Event c(5, 3.0f, 2, QString("c"));
Chris@1640 498 Event cc(5, 3.1f, 2, QString("cc"));
Chris@1640 499 Event d(6, 4.0f, 10, QString("d"));
Chris@1640 500 Event dd(6, 4.5f, 10, QString("dd"));
Chris@1640 501 Event e(14, 5.0f, 3, QString("e"));
Chris@1640 502 s.add(b);
Chris@1640 503 s.add(c);
Chris@1640 504 s.add(d);
Chris@1640 505 s.add(a);
Chris@1640 506 s.add(cc);
Chris@1640 507 s.add(dd);
Chris@1640 508 s.add(e);
Chris@1640 509 QCOMPARE(s.getEndFrame(), 18);
Chris@1640 510 }
Chris@1640 511
Chris@1616 512 void eventPatternAddRemove() {
Chris@1616 513
Chris@1616 514 // This is mostly here to exercise the innards of EventSeries
Chris@1616 515 // and check it doesn't crash out with any internal
Chris@1616 516 // consistency problems
Chris@1616 517
Chris@1616 518 EventSeries s;
Chris@1616 519 Event a(0, 1.0f, 18, QString("a"));
Chris@1616 520 Event b(3, 2.0f, 6, QString("b"));
Chris@1616 521 Event c(5, 3.0f, 2, QString("c"));
Chris@1616 522 Event cc(5, 3.1f, 2, QString("cc"));
Chris@1616 523 Event d(6, 4.0f, 10, QString("d"));
Chris@1616 524 Event dd(6, 4.5f, 10, QString("dd"));
Chris@1616 525 Event e(14, 5.0f, 3, QString("e"));
Chris@1616 526 s.add(b);
Chris@1616 527 s.add(c);
Chris@1616 528 s.add(d);
Chris@1616 529 s.add(a);
Chris@1616 530 s.add(cc);
Chris@1616 531 s.add(dd);
Chris@1616 532 s.add(e);
Chris@1616 533 QCOMPARE(s.count(), 7);
Chris@1616 534 s.remove(d);
Chris@1616 535 QCOMPARE(s.getEventsCovering(8), EventVector({ a, b, dd }));
Chris@1640 536 QCOMPARE(s.getEndFrame(), 18);
Chris@1616 537 s.remove(e);
Chris@1616 538 s.remove(a);
Chris@1616 539 QCOMPARE(s.getEventsCovering(8), EventVector({ b, dd }));
Chris@1640 540 QCOMPARE(s.getEndFrame(), 16);
Chris@1616 541 s.remove(cc);
Chris@1616 542 s.remove(c);
Chris@1616 543 s.remove(dd);
Chris@1616 544 QCOMPARE(s.getEventsCovering(8), EventVector({ b }));
Chris@1640 545 QCOMPARE(s.getEndFrame(), 9);
Chris@1616 546 s.remove(b);
Chris@1616 547 QCOMPARE(s.getEventsCovering(8), EventVector());
Chris@1616 548 QCOMPARE(s.count(), 0);
Chris@1616 549 QCOMPARE(s.isEmpty(), true);
Chris@1640 550 QCOMPARE(s.getEndFrame(), 0);
Chris@1614 551 }
Chris@1632 552
Chris@1632 553 void preceding() {
Chris@1632 554
Chris@1632 555 EventSeries s;
Chris@1632 556 Event a(0, 1.0f, 18, QString("a"));
Chris@1632 557 Event b(3, 2.0f, 6, QString("b"));
Chris@1632 558 Event c(5, 3.0f, 2, QString("c"));
Chris@1632 559 Event cc(5, 3.1f, 2, QString("cc"));
Chris@1632 560 Event d(6, 4.0f, 10, QString("d"));
Chris@1632 561 Event dd(6, 4.5f, 10, QString("dd"));
Chris@1632 562 Event e(14, 5.0f, 3, QString("e"));
Chris@1632 563 s.add(b);
Chris@1632 564 s.add(c);
Chris@1632 565 s.add(d);
Chris@1633 566 s.add(d); // again
Chris@1632 567 s.add(a);
Chris@1632 568 s.add(cc);
Chris@1632 569 s.add(dd);
Chris@1632 570 s.add(e);
Chris@1632 571 Event p;
Chris@1632 572 QCOMPARE(s.getEventPreceding(e, p), true);
Chris@1632 573 QCOMPARE(p, dd);
Chris@1632 574 QCOMPARE(s.getEventPreceding(p, p), true);
Chris@1632 575 QCOMPARE(p, d);
Chris@1632 576 QCOMPARE(s.getEventPreceding(p, p), true);
Chris@1632 577 QCOMPARE(p, cc);
Chris@1632 578 QCOMPARE(s.getEventPreceding(p, p), true);
Chris@1632 579 QCOMPARE(p, c);
Chris@1632 580 QCOMPARE(s.getEventPreceding(p, p), true);
Chris@1632 581 QCOMPARE(p, b);
Chris@1632 582 QCOMPARE(s.getEventPreceding(p, p), true);
Chris@1632 583 QCOMPARE(p, a);
Chris@1632 584 QCOMPARE(s.getEventPreceding(p, p), false);
Chris@1632 585 }
Chris@1632 586
Chris@1632 587 void following() {
Chris@1632 588
Chris@1632 589 EventSeries s;
Chris@1632 590 Event a(0, 1.0f, 18, QString("a"));
Chris@1632 591 Event b(3, 2.0f, 6, QString("b"));
Chris@1632 592 Event c(5, 3.0f, 2, QString("c"));
Chris@1632 593 Event cc(5, 3.1f, 2, QString("cc"));
Chris@1632 594 Event d(6, 4.0f, 10, QString("d"));
Chris@1632 595 Event dd(6, 4.5f, 10, QString("dd"));
Chris@1632 596 Event e(14, 5.0f, 3, QString("e"));
Chris@1632 597 s.add(b);
Chris@1632 598 s.add(c);
Chris@1632 599 s.add(d);
Chris@1633 600 s.add(d); // again
Chris@1632 601 s.add(a);
Chris@1632 602 s.add(cc);
Chris@1632 603 s.add(dd);
Chris@1632 604 s.add(e);
Chris@1632 605 Event p;
Chris@1632 606 QCOMPARE(s.getEventFollowing(a, p), true);
Chris@1632 607 QCOMPARE(p, b);
Chris@1632 608 QCOMPARE(s.getEventFollowing(p, p), true);
Chris@1632 609 QCOMPARE(p, c);
Chris@1632 610 QCOMPARE(s.getEventFollowing(p, p), true);
Chris@1632 611 QCOMPARE(p, cc);
Chris@1632 612 QCOMPARE(s.getEventFollowing(p, p), true);
Chris@1632 613 QCOMPARE(p, d);
Chris@1632 614 QCOMPARE(s.getEventFollowing(p, p), true);
Chris@1632 615 QCOMPARE(p, dd);
Chris@1632 616 QCOMPARE(s.getEventFollowing(p, p), true);
Chris@1632 617 QCOMPARE(p, e);
Chris@1632 618 QCOMPARE(s.getEventFollowing(p, p), false);
Chris@1632 619 }
Chris@1612 620 };
Chris@1612 621
Chris@1612 622 #endif