annotate base/test/TestEventSeries.h @ 1693:718ce5fb9fec single-point

Merge
author Chris Cannam
date Thu, 25 Apr 2019 11:30:51 +0100
parents e4084bc60fe8
children d32d16e8883f
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@1654 471 void eventPatternWithinWithOverspill() {
Chris@1654 472
Chris@1654 473 EventSeries s;
Chris@1654 474 Event a(0, 1.0f, 18, QString("a"));
Chris@1654 475 Event b(3, 2.0f, 6, QString("b"));
Chris@1654 476 Event c(5, 3.0f, 2, QString("c"));
Chris@1654 477 Event cc(5, 3.1f, 2, QString("cc"));
Chris@1654 478 Event d(6, 4.0f, 10, QString("d"));
Chris@1654 479 Event dd(6, 4.5f, 10, QString("dd"));
Chris@1654 480 Event e(14, 5.0f, 3, QString("e"));
Chris@1654 481 s.add(b);
Chris@1654 482 s.add(c);
Chris@1654 483 s.add(d);
Chris@1654 484 s.add(a);
Chris@1654 485 s.add(cc);
Chris@1654 486 s.add(dd);
Chris@1654 487 s.add(e);
Chris@1654 488 QCOMPARE(s.getEventsWithin(0, 0, 0), EventVector());
Chris@1654 489 QCOMPARE(s.getEventsWithin(0, 0, 1), EventVector({ a }));
Chris@1654 490 QCOMPARE(s.getEventsWithin(0, 0, 2), EventVector({ a, b }));
Chris@1654 491 QCOMPARE(s.getEventsWithin(20, 1, 0), EventVector());
Chris@1654 492 QCOMPARE(s.getEventsWithin(20, 1, 1), EventVector({ e }));
Chris@1654 493 QCOMPARE(s.getEventsWithin(20, 1, 2), EventVector({ dd, e }));
Chris@1654 494 QCOMPARE(s.getEventsWithin(2, 7, 0), EventVector({ b, c, cc }));
Chris@1654 495 QCOMPARE(s.getEventsWithin(2, 7, 1), EventVector({ a, b, c, cc, d }));
Chris@1654 496 QCOMPARE(s.getEventsWithin(2, 7, 2), EventVector({ a, b, c, cc, d, dd }));
Chris@1654 497 QCOMPARE(s.getEventsWithin(2, 7, 3), EventVector({ a, b, c, cc, d, dd, e }));
Chris@1654 498 QCOMPARE(s.getEventsWithin(2, 7, 4), EventVector({ a, b, c, cc, d, dd, e }));
Chris@1654 499 }
Chris@1654 500
Chris@1639 501 void eventPatternStartingWithin() {
Chris@1639 502
Chris@1639 503 EventSeries s;
Chris@1639 504 Event a(0, 1.0f, 18, QString("a"));
Chris@1639 505 Event b(3, 2.0f, 6, QString("b"));
Chris@1639 506 Event c(5, 3.0f, 2, QString("c"));
Chris@1639 507 Event cc(5, 3.1f, 2, QString("cc"));
Chris@1639 508 Event d(6, 4.0f, 10, QString("d"));
Chris@1639 509 Event dd(6, 4.5f, 10, QString("dd"));
Chris@1639 510 Event e(14, 5.0f, 3, QString("e"));
Chris@1639 511 s.add(b);
Chris@1639 512 s.add(c);
Chris@1639 513 s.add(d);
Chris@1639 514 s.add(a);
Chris@1639 515 s.add(cc);
Chris@1639 516 s.add(dd);
Chris@1639 517 s.add(e);
Chris@1639 518 QCOMPARE(s.getEventsStartingWithin(2, 7),
Chris@1639 519 EventVector({ b, c, cc, d, dd }));
Chris@1639 520 }
Chris@1639 521
Chris@1656 522 void eventPatternStartingAt() {
Chris@1656 523
Chris@1656 524 EventSeries s;
Chris@1656 525 Event a(0, 1.0f, 18, QString("a"));
Chris@1656 526 Event b(3, 2.0f, 6, QString("b"));
Chris@1656 527 Event c(5, 3.0f, 2, QString("c"));
Chris@1656 528 Event cc(5, 3.1f, 2, QString("cc"));
Chris@1656 529 Event d(6, 4.0f, 10, QString("d"));
Chris@1656 530 Event dd(6, 4.5f, 10, QString("dd"));
Chris@1656 531 Event e(14, 5.0f, 3, QString("e"));
Chris@1656 532 s.add(b);
Chris@1656 533 s.add(c);
Chris@1656 534 s.add(d);
Chris@1656 535 s.add(a);
Chris@1656 536 s.add(cc);
Chris@1656 537 s.add(dd);
Chris@1656 538 s.add(e);
Chris@1656 539 QCOMPARE(s.getEventsStartingAt(2), EventVector());
Chris@1656 540 QCOMPARE(s.getEventsStartingAt(5), EventVector({ c, cc }));
Chris@1656 541 }
Chris@1656 542
Chris@1640 543 void eventPatternEndFrame() {
Chris@1640 544
Chris@1640 545 EventSeries s;
Chris@1640 546 Event a(0, 1.0f, 18, QString("a"));
Chris@1640 547 Event b(3, 2.0f, 6, QString("b"));
Chris@1640 548 Event c(5, 3.0f, 2, QString("c"));
Chris@1640 549 Event cc(5, 3.1f, 2, QString("cc"));
Chris@1640 550 Event d(6, 4.0f, 10, QString("d"));
Chris@1640 551 Event dd(6, 4.5f, 10, QString("dd"));
Chris@1640 552 Event e(14, 5.0f, 3, QString("e"));
Chris@1640 553 s.add(b);
Chris@1640 554 s.add(c);
Chris@1640 555 s.add(d);
Chris@1640 556 s.add(a);
Chris@1640 557 s.add(cc);
Chris@1640 558 s.add(dd);
Chris@1640 559 s.add(e);
Chris@1640 560 QCOMPARE(s.getEndFrame(), 18);
Chris@1640 561 }
Chris@1640 562
Chris@1616 563 void eventPatternAddRemove() {
Chris@1616 564
Chris@1616 565 // This is mostly here to exercise the innards of EventSeries
Chris@1616 566 // and check it doesn't crash out with any internal
Chris@1616 567 // consistency problems
Chris@1616 568
Chris@1616 569 EventSeries s;
Chris@1616 570 Event a(0, 1.0f, 18, QString("a"));
Chris@1616 571 Event b(3, 2.0f, 6, QString("b"));
Chris@1616 572 Event c(5, 3.0f, 2, QString("c"));
Chris@1616 573 Event cc(5, 3.1f, 2, QString("cc"));
Chris@1616 574 Event d(6, 4.0f, 10, QString("d"));
Chris@1616 575 Event dd(6, 4.5f, 10, QString("dd"));
Chris@1616 576 Event e(14, 5.0f, 3, QString("e"));
Chris@1616 577 s.add(b);
Chris@1616 578 s.add(c);
Chris@1616 579 s.add(d);
Chris@1616 580 s.add(a);
Chris@1616 581 s.add(cc);
Chris@1616 582 s.add(dd);
Chris@1616 583 s.add(e);
Chris@1616 584 QCOMPARE(s.count(), 7);
Chris@1616 585 s.remove(d);
Chris@1616 586 QCOMPARE(s.getEventsCovering(8), EventVector({ a, b, dd }));
Chris@1640 587 QCOMPARE(s.getEndFrame(), 18);
Chris@1616 588 s.remove(e);
Chris@1616 589 s.remove(a);
Chris@1616 590 QCOMPARE(s.getEventsCovering(8), EventVector({ b, dd }));
Chris@1640 591 QCOMPARE(s.getEndFrame(), 16);
Chris@1616 592 s.remove(cc);
Chris@1616 593 s.remove(c);
Chris@1616 594 s.remove(dd);
Chris@1616 595 QCOMPARE(s.getEventsCovering(8), EventVector({ b }));
Chris@1640 596 QCOMPARE(s.getEndFrame(), 9);
Chris@1616 597 s.remove(b);
Chris@1616 598 QCOMPARE(s.getEventsCovering(8), EventVector());
Chris@1616 599 QCOMPARE(s.count(), 0);
Chris@1616 600 QCOMPARE(s.isEmpty(), true);
Chris@1640 601 QCOMPARE(s.getEndFrame(), 0);
Chris@1614 602 }
Chris@1632 603
Chris@1632 604 void preceding() {
Chris@1632 605
Chris@1632 606 EventSeries s;
Chris@1632 607 Event a(0, 1.0f, 18, QString("a"));
Chris@1632 608 Event b(3, 2.0f, 6, QString("b"));
Chris@1632 609 Event c(5, 3.0f, 2, QString("c"));
Chris@1632 610 Event cc(5, 3.1f, 2, QString("cc"));
Chris@1632 611 Event d(6, 4.0f, 10, QString("d"));
Chris@1632 612 Event dd(6, 4.5f, 10, QString("dd"));
Chris@1632 613 Event e(14, 5.0f, 3, QString("e"));
Chris@1632 614 s.add(b);
Chris@1632 615 s.add(c);
Chris@1632 616 s.add(d);
Chris@1633 617 s.add(d); // again
Chris@1632 618 s.add(a);
Chris@1632 619 s.add(cc);
Chris@1632 620 s.add(dd);
Chris@1632 621 s.add(e);
Chris@1632 622 Event p;
Chris@1632 623 QCOMPARE(s.getEventPreceding(e, p), true);
Chris@1632 624 QCOMPARE(p, dd);
Chris@1632 625 QCOMPARE(s.getEventPreceding(p, p), true);
Chris@1632 626 QCOMPARE(p, d);
Chris@1632 627 QCOMPARE(s.getEventPreceding(p, p), true);
Chris@1632 628 QCOMPARE(p, cc);
Chris@1632 629 QCOMPARE(s.getEventPreceding(p, p), true);
Chris@1632 630 QCOMPARE(p, c);
Chris@1632 631 QCOMPARE(s.getEventPreceding(p, p), true);
Chris@1632 632 QCOMPARE(p, b);
Chris@1632 633 QCOMPARE(s.getEventPreceding(p, p), true);
Chris@1632 634 QCOMPARE(p, a);
Chris@1632 635 QCOMPARE(s.getEventPreceding(p, p), false);
Chris@1632 636 }
Chris@1632 637
Chris@1632 638 void following() {
Chris@1632 639
Chris@1632 640 EventSeries s;
Chris@1632 641 Event a(0, 1.0f, 18, QString("a"));
Chris@1632 642 Event b(3, 2.0f, 6, QString("b"));
Chris@1632 643 Event c(5, 3.0f, 2, QString("c"));
Chris@1632 644 Event cc(5, 3.1f, 2, QString("cc"));
Chris@1632 645 Event d(6, 4.0f, 10, QString("d"));
Chris@1632 646 Event dd(6, 4.5f, 10, QString("dd"));
Chris@1632 647 Event e(14, 5.0f, 3, QString("e"));
Chris@1632 648 s.add(b);
Chris@1632 649 s.add(c);
Chris@1632 650 s.add(d);
Chris@1633 651 s.add(d); // again
Chris@1632 652 s.add(a);
Chris@1632 653 s.add(cc);
Chris@1632 654 s.add(dd);
Chris@1632 655 s.add(e);
Chris@1632 656 Event p;
Chris@1632 657 QCOMPARE(s.getEventFollowing(a, p), true);
Chris@1632 658 QCOMPARE(p, b);
Chris@1632 659 QCOMPARE(s.getEventFollowing(p, p), true);
Chris@1632 660 QCOMPARE(p, c);
Chris@1632 661 QCOMPARE(s.getEventFollowing(p, p), true);
Chris@1632 662 QCOMPARE(p, cc);
Chris@1632 663 QCOMPARE(s.getEventFollowing(p, p), true);
Chris@1632 664 QCOMPARE(p, d);
Chris@1632 665 QCOMPARE(s.getEventFollowing(p, p), true);
Chris@1632 666 QCOMPARE(p, dd);
Chris@1632 667 QCOMPARE(s.getEventFollowing(p, p), true);
Chris@1632 668 QCOMPARE(p, e);
Chris@1632 669 QCOMPARE(s.getEventFollowing(p, p), false);
Chris@1632 670 }
Chris@1653 671
Chris@1653 672 void matchingForward() {
Chris@1653 673
Chris@1653 674 EventSeries s;
Chris@1653 675 Event p;
Chris@1653 676 QCOMPARE(s.getNearestEventMatching
Chris@1654 677 (6, [](Event e) { return e.getDuration() < 4; },
Chris@1653 678 EventSeries::Forward, p), false);
Chris@1653 679 Event a(0, 1.0f, 18, QString("a"));
Chris@1653 680 Event b(3, 2.0f, 6, QString("b"));
Chris@1653 681 Event c(5, 3.0f, 2, QString("c"));
Chris@1653 682 Event cc(5, 3.1f, 2, QString("cc"));
Chris@1653 683 Event d(6, 4.0f, 10, QString("d"));
Chris@1653 684 Event dd(6, 4.5f, 10, QString("dd"));
Chris@1653 685 Event e(14, 5.0f, 3, QString("e"));
Chris@1653 686 s.add(b);
Chris@1653 687 s.add(c);
Chris@1653 688 s.add(d);
Chris@1653 689 s.add(d); // again
Chris@1653 690 s.add(a);
Chris@1653 691 s.add(cc);
Chris@1653 692 s.add(dd);
Chris@1653 693 s.add(e);
Chris@1653 694 QCOMPARE(s.getNearestEventMatching
Chris@1654 695 (0, [](Event e) { return e.getDuration() < 4; },
Chris@1653 696 EventSeries::Forward, p), true);
Chris@1653 697 QCOMPARE(p, c);
Chris@1653 698 QCOMPARE(s.getNearestEventMatching
Chris@1654 699 (6, [](Event e) { return e.getDuration() < 4; },
Chris@1653 700 EventSeries::Forward, p), true);
Chris@1653 701 QCOMPARE(p, e);
Chris@1653 702 QCOMPARE(s.getNearestEventMatching
Chris@1654 703 (6, [](Event e) { return e.getDuration() > 4; },
Chris@1653 704 EventSeries::Forward, p), true);
Chris@1653 705 QCOMPARE(p, d);
Chris@1653 706 QCOMPARE(s.getNearestEventMatching
Chris@1654 707 (20, [](Event e) { return e.getDuration() > 4; },
Chris@1653 708 EventSeries::Forward, p), false);
Chris@1653 709 }
Chris@1653 710
Chris@1653 711 void matchingBackward() {
Chris@1653 712
Chris@1653 713 EventSeries s;
Chris@1653 714 Event p;
Chris@1653 715 QCOMPARE(s.getNearestEventMatching
Chris@1654 716 (6, [](Event e) { return e.getDuration() < 4; },
Chris@1653 717 EventSeries::Backward, p), false);
Chris@1653 718 Event a(0, 1.0f, 18, QString("a"));
Chris@1653 719 Event b(3, 2.0f, 6, QString("b"));
Chris@1653 720 Event c(5, 3.0f, 2, QString("c"));
Chris@1653 721 Event cc(5, 3.1f, 2, QString("cc"));
Chris@1653 722 Event d(6, 4.0f, 10, QString("d"));
Chris@1653 723 Event dd(6, 4.5f, 10, QString("dd"));
Chris@1653 724 Event e(14, 5.0f, 3, QString("e"));
Chris@1653 725 s.add(b);
Chris@1653 726 s.add(c);
Chris@1653 727 s.add(d);
Chris@1653 728 s.add(d); // again
Chris@1653 729 s.add(a);
Chris@1653 730 s.add(cc);
Chris@1653 731 s.add(dd);
Chris@1653 732 s.add(e);
Chris@1653 733 QCOMPARE(s.getNearestEventMatching
Chris@1654 734 (0, [](Event e) { return e.getDuration() < 4; },
Chris@1653 735 EventSeries::Backward, p), false);
Chris@1653 736 QCOMPARE(s.getNearestEventMatching
Chris@1654 737 (6, [](Event e) { return e.getDuration() > 4; },
Chris@1653 738 EventSeries::Backward, p), true);
Chris@1653 739 QCOMPARE(p, b);
Chris@1653 740 QCOMPARE(s.getNearestEventMatching
Chris@1654 741 (20, [](Event e) { return e.getDuration() > 4; },
Chris@1653 742 EventSeries::Backward, p), true);
Chris@1653 743 QCOMPARE(p, dd);
Chris@1653 744 }
Chris@1612 745 };
Chris@1612 746
Chris@1612 747 #endif