comparison base/test/TestEventSeries.h @ 1615:24dc8cb42755 single-point

Rename a number of classes and methods (including Point -> Event); comments
author Chris Cannam
date Thu, 07 Mar 2019 15:44:09 +0000
parents base/test/TestPointSeries.h@2e14a7876945
children de446dd905e6
comparison
equal deleted inserted replaced
1614:2e14a7876945 1615:24dc8cb42755
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2
3 /*
4 Sonic Visualiser
5 An audio file viewer and annotation editor.
6 Centre for Digital Music, Queen Mary, University of London.
7
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2 of the
11 License, or (at your option) any later version. See the file
12 COPYING included with this distribution for more information.
13 */
14
15 #ifndef TEST_EVENT_SERIES_H
16 #define TEST_EVENT_SERIES_H
17
18 #include "../EventSeries.h"
19
20 #include <QObject>
21 #include <QtTest>
22
23 #include <iostream>
24
25 using namespace std;
26
27 class TestEventSeries : public QObject
28 {
29 Q_OBJECT
30
31 private slots:
32 void empty() {
33
34 EventSeries s;
35 QCOMPARE(s.isEmpty(), true);
36 QCOMPARE(s.count(), 0);
37
38 Event p(10, QString());
39 QCOMPARE(s.contains(p), false);
40 QCOMPARE(s.getEventsSpanning(400), EventVector());
41 }
42
43 void singleEvent() {
44
45 EventSeries s;
46 Event p(10, QString());
47 s.add(p);
48 QCOMPARE(s.isEmpty(), false);
49 QCOMPARE(s.count(), 1);
50 QCOMPARE(s.contains(p), true);
51
52 s.remove(p);
53 QCOMPARE(s.isEmpty(), true);
54 QCOMPARE(s.contains(p), false);
55 }
56
57 void singleEventSpan() {
58
59 EventSeries s;
60 Event p(10, QString());
61 s.add(p);
62 EventVector span;
63 span.push_back(p);
64 QCOMPARE(s.getEventsSpanning(10), span);
65 QCOMPARE(s.getEventsSpanning(11), EventVector());
66 QCOMPARE(s.getEventsSpanning(9), EventVector());
67 }
68
69 void singleEventWithDurationSpan() {
70
71 EventSeries s;
72 Event p(10, 1.0, 20, QString());
73 s.add(p);
74 EventVector span;
75 span.push_back(p);
76 QCOMPARE(s.getEventsSpanning(10), span);
77 QCOMPARE(s.getEventsSpanning(11), span);
78 QCOMPARE(s.getEventsSpanning(29), span);
79 QCOMPARE(s.getEventsSpanning(30), EventVector());
80 QCOMPARE(s.getEventsSpanning(9), EventVector());
81 }
82
83 void identicalEventsSpan() {
84
85 EventSeries s;
86 Event p(10, QString());
87 s.add(p);
88 s.add(p);
89
90 EventVector span;
91 span.push_back(p);
92 span.push_back(p);
93 QCOMPARE(s.getEventsSpanning(10), span);
94 QCOMPARE(s.getEventsSpanning(11), EventVector());
95 QCOMPARE(s.getEventsSpanning(9), EventVector());
96
97 s.remove(p);
98 span.clear();
99 span.push_back(p);
100 QCOMPARE(s.getEventsSpanning(10), span);
101 QCOMPARE(s.getEventsSpanning(11), EventVector());
102 QCOMPARE(s.getEventsSpanning(9), EventVector());
103 }
104
105 void identicalEventsWithDurationSpan() {
106
107 EventSeries s;
108 Event p(10, 1.0, 20, QString());
109 s.add(p);
110 s.add(p);
111 EventVector span;
112 span.push_back(p);
113 span.push_back(p);
114 QCOMPARE(s.getEventsSpanning(10), span);
115 QCOMPARE(s.getEventsSpanning(11), span);
116 QCOMPARE(s.getEventsSpanning(29), span);
117 QCOMPARE(s.getEventsSpanning(30), EventVector());
118 QCOMPARE(s.getEventsSpanning(9), EventVector());
119
120 s.remove(p);
121 span.clear();
122 span.push_back(p);
123 QCOMPARE(s.getEventsSpanning(10), span);
124 QCOMPARE(s.getEventsSpanning(11), span);
125 QCOMPARE(s.getEventsSpanning(29), span);
126 QCOMPARE(s.getEventsSpanning(30), EventVector());
127 QCOMPARE(s.getEventsSpanning(9), EventVector());
128 }
129
130 void multipleEventsSpan() {
131
132 EventSeries s;
133 Event a(10, QString("a"));
134 Event b(11, QString("b"));
135 Event c(40, QString("c"));
136 s.add(c);
137 s.add(a);
138 s.add(b);
139 s.remove(a);
140 s.add(a);
141 s.add(c);
142 s.remove(c);
143 QCOMPARE(s.count(), 3);
144 EventVector span;
145 span.push_back(a);
146 QCOMPARE(s.getEventsSpanning(10), span);
147 span.clear();
148 span.push_back(c);
149 QCOMPARE(s.getEventsSpanning(40), span);
150 QCOMPARE(s.getEventsSpanning(9), EventVector());
151 }
152
153 void disjointEventsWithDurationSpan() {
154
155 EventSeries s;
156 Event a(10, 1.0f, 20, QString("a"));
157 Event b(100, 1.2f, 30, QString("b"));
158 s.add(a);
159 s.add(b);
160 QCOMPARE(s.getEventsSpanning(0), EventVector());
161 QCOMPARE(s.getEventsSpanning(10), EventVector({ a }));
162 QCOMPARE(s.getEventsSpanning(15), EventVector({ a }));
163 QCOMPARE(s.getEventsSpanning(30), EventVector());
164 QCOMPARE(s.getEventsSpanning(99), EventVector());
165 QCOMPARE(s.getEventsSpanning(100), EventVector({ b }));
166 QCOMPARE(s.getEventsSpanning(120), EventVector({ b }));
167 QCOMPARE(s.getEventsSpanning(130), EventVector());
168 }
169
170 void overlappingEventsWithAndWithoutDurationSpan() {
171
172 EventSeries s;
173 Event p(20, QString("p"));
174 Event a(10, 1.0, 20, QString("a"));
175 s.add(p);
176 s.add(a);
177 EventVector span;
178 span.push_back(a);
179 QCOMPARE(s.getEventsSpanning(15), span);
180 QCOMPARE(s.getEventsSpanning(25), span);
181 span.clear();
182 span.push_back(p);
183 span.push_back(a);
184 QCOMPARE(s.getEventsSpanning(20), span);
185 }
186
187 void overlappingEventsWithDurationSpan() {
188
189 EventSeries s;
190 Event a(20, 1.0, 10, QString("a"));
191 Event b(10, 1.0, 20, QString("b"));
192 Event c(10, 1.0, 40, QString("c"));
193 s.add(a);
194 s.add(b);
195 s.add(c);
196 QCOMPARE(s.getEventsSpanning(10), EventVector({ b, c }));
197 QCOMPARE(s.getEventsSpanning(20), EventVector({ b, c, a }));
198 QCOMPARE(s.getEventsSpanning(25), EventVector({ b, c, a }));
199 QCOMPARE(s.getEventsSpanning(30), EventVector({ c }));
200 QCOMPARE(s.getEventsSpanning(40), EventVector({ c }));
201 QCOMPARE(s.getEventsSpanning(50), EventVector());
202 }
203
204 void eventPatternSpan() {
205
206 EventSeries s;
207 Event a(0, 1.0, 18, QString("a"));
208 Event b(3, 2.0, 6, QString("b"));
209 Event c(5, 3.0, 2, QString("c"));
210 Event d(6, 4.0, 10, QString("d"));
211 Event e(14, 5.0, 3, QString("e"));
212 s.add(b);
213 s.add(c);
214 s.add(d);
215 s.add(a);
216 s.add(e);
217 QCOMPARE(s.getEventsSpanning(8), EventVector({ a, b, d }));
218 }
219 };
220
221 #endif