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@1616
|
91 void similarEventsCover() {
|
Chris@1616
|
92
|
Chris@1616
|
93 EventSeries s;
|
Chris@1616
|
94 Event a(10, QString("a"));
|
Chris@1616
|
95 Event b(10, QString("b"));
|
Chris@1616
|
96 s.add(a);
|
Chris@1616
|
97 s.add(b);
|
Chris@1616
|
98 EventVector cover;
|
Chris@1616
|
99 cover.push_back(a);
|
Chris@1616
|
100 cover.push_back(b);
|
Chris@1616
|
101 QCOMPARE(s.getEventsCovering(10), cover);
|
Chris@1616
|
102 QCOMPARE(s.getEventsCovering(11), EventVector());
|
Chris@1616
|
103 QCOMPARE(s.getEventsCovering(9), EventVector());
|
Chris@1616
|
104 }
|
Chris@1616
|
105
|
Chris@1616
|
106 void singleEventWithDurationCover() {
|
Chris@1612
|
107
|
Chris@1615
|
108 EventSeries s;
|
Chris@1615
|
109 Event p(10, 1.0, 20, QString());
|
Chris@1612
|
110 s.add(p);
|
Chris@1616
|
111 EventVector cover;
|
Chris@1616
|
112 cover.push_back(p);
|
Chris@1616
|
113 QCOMPARE(s.getEventsCovering(10), cover);
|
Chris@1616
|
114 QCOMPARE(s.getEventsCovering(11), cover);
|
Chris@1616
|
115 QCOMPARE(s.getEventsCovering(29), cover);
|
Chris@1616
|
116 QCOMPARE(s.getEventsCovering(30), EventVector());
|
Chris@1616
|
117 QCOMPARE(s.getEventsCovering(9), EventVector());
|
Chris@1612
|
118 }
|
Chris@1614
|
119
|
Chris@1616
|
120 void identicalEventsCover() {
|
Chris@1614
|
121
|
Chris@1615
|
122 EventSeries s;
|
Chris@1615
|
123 Event p(10, QString());
|
Chris@1614
|
124 s.add(p);
|
Chris@1614
|
125 s.add(p);
|
Chris@1614
|
126
|
Chris@1616
|
127 EventVector cover;
|
Chris@1616
|
128 cover.push_back(p);
|
Chris@1616
|
129 cover.push_back(p);
|
Chris@1616
|
130 QCOMPARE(s.getEventsCovering(10), cover);
|
Chris@1616
|
131 QCOMPARE(s.getEventsCovering(11), EventVector());
|
Chris@1616
|
132 QCOMPARE(s.getEventsCovering(9), EventVector());
|
Chris@1614
|
133
|
Chris@1614
|
134 s.remove(p);
|
Chris@1616
|
135 cover.clear();
|
Chris@1616
|
136 cover.push_back(p);
|
Chris@1616
|
137 QCOMPARE(s.getEventsCovering(10), cover);
|
Chris@1616
|
138 QCOMPARE(s.getEventsCovering(11), EventVector());
|
Chris@1616
|
139 QCOMPARE(s.getEventsCovering(9), EventVector());
|
Chris@1614
|
140 }
|
Chris@1614
|
141
|
Chris@1616
|
142 void identicalEventsWithDurationCover() {
|
Chris@1614
|
143
|
Chris@1615
|
144 EventSeries s;
|
Chris@1615
|
145 Event p(10, 1.0, 20, QString());
|
Chris@1614
|
146 s.add(p);
|
Chris@1614
|
147 s.add(p);
|
Chris@1616
|
148 EventVector cover;
|
Chris@1616
|
149 cover.push_back(p);
|
Chris@1616
|
150 cover.push_back(p);
|
Chris@1616
|
151 QCOMPARE(s.getEventsCovering(10), cover);
|
Chris@1616
|
152 QCOMPARE(s.getEventsCovering(11), cover);
|
Chris@1616
|
153 QCOMPARE(s.getEventsCovering(29), cover);
|
Chris@1616
|
154 QCOMPARE(s.getEventsCovering(30), EventVector());
|
Chris@1616
|
155 QCOMPARE(s.getEventsCovering(9), EventVector());
|
Chris@1614
|
156
|
Chris@1614
|
157 s.remove(p);
|
Chris@1616
|
158 cover.clear();
|
Chris@1616
|
159 cover.push_back(p);
|
Chris@1616
|
160 QCOMPARE(s.getEventsCovering(10), cover);
|
Chris@1616
|
161 QCOMPARE(s.getEventsCovering(11), cover);
|
Chris@1616
|
162 QCOMPARE(s.getEventsCovering(29), cover);
|
Chris@1616
|
163 QCOMPARE(s.getEventsCovering(30), EventVector());
|
Chris@1616
|
164 QCOMPARE(s.getEventsCovering(9), EventVector());
|
Chris@1614
|
165 }
|
Chris@1614
|
166
|
Chris@1616
|
167 void multipleEventsCover() {
|
Chris@1614
|
168
|
Chris@1615
|
169 EventSeries s;
|
Chris@1615
|
170 Event a(10, QString("a"));
|
Chris@1615
|
171 Event b(11, QString("b"));
|
Chris@1615
|
172 Event c(40, QString("c"));
|
Chris@1614
|
173 s.add(c);
|
Chris@1614
|
174 s.add(a);
|
Chris@1614
|
175 s.add(b);
|
Chris@1614
|
176 s.remove(a);
|
Chris@1614
|
177 s.add(a);
|
Chris@1614
|
178 s.add(c);
|
Chris@1614
|
179 s.remove(c);
|
Chris@1614
|
180 QCOMPARE(s.count(), 3);
|
Chris@1616
|
181 EventVector cover;
|
Chris@1616
|
182 cover.push_back(a);
|
Chris@1616
|
183 QCOMPARE(s.getEventsCovering(10), cover);
|
Chris@1616
|
184 cover.clear();
|
Chris@1616
|
185 cover.push_back(c);
|
Chris@1616
|
186 QCOMPARE(s.getEventsCovering(40), cover);
|
Chris@1616
|
187 QCOMPARE(s.getEventsCovering(9), EventVector());
|
Chris@1614
|
188 }
|
Chris@1614
|
189
|
Chris@1616
|
190 void disjointEventsWithDurationCover() {
|
Chris@1614
|
191
|
Chris@1615
|
192 EventSeries s;
|
Chris@1615
|
193 Event a(10, 1.0f, 20, QString("a"));
|
Chris@1615
|
194 Event b(100, 1.2f, 30, QString("b"));
|
Chris@1614
|
195 s.add(a);
|
Chris@1614
|
196 s.add(b);
|
Chris@1616
|
197 QCOMPARE(s.getEventsCovering(0), EventVector());
|
Chris@1616
|
198 QCOMPARE(s.getEventsCovering(10), EventVector({ a }));
|
Chris@1616
|
199 QCOMPARE(s.getEventsCovering(15), EventVector({ a }));
|
Chris@1616
|
200 QCOMPARE(s.getEventsCovering(30), EventVector());
|
Chris@1616
|
201 QCOMPARE(s.getEventsCovering(99), EventVector());
|
Chris@1616
|
202 QCOMPARE(s.getEventsCovering(100), EventVector({ b }));
|
Chris@1616
|
203 QCOMPARE(s.getEventsCovering(120), EventVector({ b }));
|
Chris@1616
|
204 QCOMPARE(s.getEventsCovering(130), EventVector());
|
Chris@1614
|
205 }
|
Chris@1614
|
206
|
Chris@1616
|
207 void overlappingEventsWithAndWithoutDurationCover() {
|
Chris@1614
|
208
|
Chris@1615
|
209 EventSeries s;
|
Chris@1615
|
210 Event p(20, QString("p"));
|
Chris@1616
|
211 Event a(10, 1.0f, 20, QString("a"));
|
Chris@1614
|
212 s.add(p);
|
Chris@1614
|
213 s.add(a);
|
Chris@1616
|
214 EventVector cover;
|
Chris@1616
|
215 cover.push_back(a);
|
Chris@1616
|
216 QCOMPARE(s.getEventsCovering(15), cover);
|
Chris@1616
|
217 QCOMPARE(s.getEventsCovering(25), cover);
|
Chris@1616
|
218 cover.clear();
|
Chris@1616
|
219 cover.push_back(p);
|
Chris@1616
|
220 cover.push_back(a);
|
Chris@1616
|
221 QCOMPARE(s.getEventsCovering(20), cover);
|
Chris@1614
|
222 }
|
Chris@1614
|
223
|
Chris@1616
|
224 void overlappingEventsWithDurationCover() {
|
Chris@1614
|
225
|
Chris@1615
|
226 EventSeries s;
|
Chris@1616
|
227 Event a(20, 1.0f, 10, QString("a"));
|
Chris@1616
|
228 Event b(10, 1.0f, 20, QString("b"));
|
Chris@1616
|
229 Event c(10, 1.0f, 40, QString("c"));
|
Chris@1614
|
230 s.add(a);
|
Chris@1614
|
231 s.add(b);
|
Chris@1614
|
232 s.add(c);
|
Chris@1616
|
233 QCOMPARE(s.getEventsCovering(10), EventVector({ b, c }));
|
Chris@1616
|
234 QCOMPARE(s.getEventsCovering(20), EventVector({ b, c, a }));
|
Chris@1616
|
235 QCOMPARE(s.getEventsCovering(25), EventVector({ b, c, a }));
|
Chris@1616
|
236 QCOMPARE(s.getEventsCovering(30), EventVector({ c }));
|
Chris@1616
|
237 QCOMPARE(s.getEventsCovering(40), EventVector({ c }));
|
Chris@1616
|
238 QCOMPARE(s.getEventsCovering(50), EventVector());
|
Chris@1614
|
239 }
|
Chris@1614
|
240
|
Chris@1616
|
241 void eventPatternCover() {
|
Chris@1614
|
242
|
Chris@1615
|
243 EventSeries s;
|
Chris@1616
|
244 Event a(0, 1.0f, 18, QString("a"));
|
Chris@1616
|
245 Event b(3, 2.0f, 6, QString("b"));
|
Chris@1616
|
246 Event c(5, 3.0f, 2, QString("c"));
|
Chris@1616
|
247 Event cc(5, 3.1f, 2, QString("cc"));
|
Chris@1616
|
248 Event d(6, 4.0f, 10, QString("d"));
|
Chris@1616
|
249 Event dd(6, 4.5f, 10, QString("dd"));
|
Chris@1616
|
250 Event e(14, 5.0f, 3, QString("e"));
|
Chris@1614
|
251 s.add(b);
|
Chris@1614
|
252 s.add(c);
|
Chris@1614
|
253 s.add(d);
|
Chris@1614
|
254 s.add(a);
|
Chris@1616
|
255 s.add(cc);
|
Chris@1616
|
256 s.add(dd);
|
Chris@1614
|
257 s.add(e);
|
Chris@1616
|
258 QCOMPARE(s.getEventsCovering(8), EventVector({ a, b, d, dd }));
|
Chris@1616
|
259 }
|
Chris@1616
|
260
|
Chris@1616
|
261 void eventPatternAddRemove() {
|
Chris@1616
|
262
|
Chris@1616
|
263 // This is mostly here to exercise the innards of EventSeries
|
Chris@1616
|
264 // and check it doesn't crash out with any internal
|
Chris@1616
|
265 // consistency problems
|
Chris@1616
|
266
|
Chris@1616
|
267 EventSeries s;
|
Chris@1616
|
268 Event a(0, 1.0f, 18, QString("a"));
|
Chris@1616
|
269 Event b(3, 2.0f, 6, QString("b"));
|
Chris@1616
|
270 Event c(5, 3.0f, 2, QString("c"));
|
Chris@1616
|
271 Event cc(5, 3.1f, 2, QString("cc"));
|
Chris@1616
|
272 Event d(6, 4.0f, 10, QString("d"));
|
Chris@1616
|
273 Event dd(6, 4.5f, 10, QString("dd"));
|
Chris@1616
|
274 Event e(14, 5.0f, 3, QString("e"));
|
Chris@1616
|
275 s.add(b);
|
Chris@1616
|
276 s.add(c);
|
Chris@1616
|
277 s.add(d);
|
Chris@1616
|
278 s.add(a);
|
Chris@1616
|
279 s.add(cc);
|
Chris@1616
|
280 s.add(dd);
|
Chris@1616
|
281 s.add(e);
|
Chris@1616
|
282 QCOMPARE(s.count(), 7);
|
Chris@1616
|
283 s.remove(d);
|
Chris@1616
|
284 QCOMPARE(s.getEventsCovering(8), EventVector({ a, b, dd }));
|
Chris@1616
|
285 s.remove(e);
|
Chris@1616
|
286 s.remove(a);
|
Chris@1616
|
287 QCOMPARE(s.getEventsCovering(8), EventVector({ b, dd }));
|
Chris@1616
|
288 s.remove(cc);
|
Chris@1616
|
289 s.remove(c);
|
Chris@1616
|
290 s.remove(dd);
|
Chris@1616
|
291 QCOMPARE(s.getEventsCovering(8), EventVector({ b }));
|
Chris@1616
|
292 s.remove(b);
|
Chris@1616
|
293 QCOMPARE(s.getEventsCovering(8), EventVector());
|
Chris@1616
|
294 QCOMPARE(s.count(), 0);
|
Chris@1616
|
295 QCOMPARE(s.isEmpty(), true);
|
Chris@1614
|
296 }
|
Chris@1612
|
297 };
|
Chris@1612
|
298
|
Chris@1612
|
299 #endif
|