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@1615
|
40 QCOMPARE(s.getEventsSpanning(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@1612
|
54 QCOMPARE(s.contains(p), false);
|
Chris@1612
|
55 }
|
Chris@1612
|
56
|
Chris@1615
|
57 void singleEventSpan() {
|
Chris@1612
|
58
|
Chris@1615
|
59 EventSeries s;
|
Chris@1615
|
60 Event p(10, QString());
|
Chris@1612
|
61 s.add(p);
|
Chris@1615
|
62 EventVector span;
|
Chris@1612
|
63 span.push_back(p);
|
Chris@1615
|
64 QCOMPARE(s.getEventsSpanning(10), span);
|
Chris@1615
|
65 QCOMPARE(s.getEventsSpanning(11), EventVector());
|
Chris@1615
|
66 QCOMPARE(s.getEventsSpanning(9), EventVector());
|
Chris@1612
|
67 }
|
Chris@1612
|
68
|
Chris@1615
|
69 void singleEventWithDurationSpan() {
|
Chris@1612
|
70
|
Chris@1615
|
71 EventSeries s;
|
Chris@1615
|
72 Event p(10, 1.0, 20, QString());
|
Chris@1612
|
73 s.add(p);
|
Chris@1615
|
74 EventVector span;
|
Chris@1612
|
75 span.push_back(p);
|
Chris@1615
|
76 QCOMPARE(s.getEventsSpanning(10), span);
|
Chris@1615
|
77 QCOMPARE(s.getEventsSpanning(11), span);
|
Chris@1615
|
78 QCOMPARE(s.getEventsSpanning(29), span);
|
Chris@1615
|
79 QCOMPARE(s.getEventsSpanning(30), EventVector());
|
Chris@1615
|
80 QCOMPARE(s.getEventsSpanning(9), EventVector());
|
Chris@1612
|
81 }
|
Chris@1614
|
82
|
Chris@1615
|
83 void identicalEventsSpan() {
|
Chris@1614
|
84
|
Chris@1615
|
85 EventSeries s;
|
Chris@1615
|
86 Event p(10, QString());
|
Chris@1614
|
87 s.add(p);
|
Chris@1614
|
88 s.add(p);
|
Chris@1614
|
89
|
Chris@1615
|
90 EventVector span;
|
Chris@1614
|
91 span.push_back(p);
|
Chris@1614
|
92 span.push_back(p);
|
Chris@1615
|
93 QCOMPARE(s.getEventsSpanning(10), span);
|
Chris@1615
|
94 QCOMPARE(s.getEventsSpanning(11), EventVector());
|
Chris@1615
|
95 QCOMPARE(s.getEventsSpanning(9), EventVector());
|
Chris@1614
|
96
|
Chris@1614
|
97 s.remove(p);
|
Chris@1614
|
98 span.clear();
|
Chris@1614
|
99 span.push_back(p);
|
Chris@1615
|
100 QCOMPARE(s.getEventsSpanning(10), span);
|
Chris@1615
|
101 QCOMPARE(s.getEventsSpanning(11), EventVector());
|
Chris@1615
|
102 QCOMPARE(s.getEventsSpanning(9), EventVector());
|
Chris@1614
|
103 }
|
Chris@1614
|
104
|
Chris@1615
|
105 void identicalEventsWithDurationSpan() {
|
Chris@1614
|
106
|
Chris@1615
|
107 EventSeries s;
|
Chris@1615
|
108 Event p(10, 1.0, 20, QString());
|
Chris@1614
|
109 s.add(p);
|
Chris@1614
|
110 s.add(p);
|
Chris@1615
|
111 EventVector span;
|
Chris@1614
|
112 span.push_back(p);
|
Chris@1614
|
113 span.push_back(p);
|
Chris@1615
|
114 QCOMPARE(s.getEventsSpanning(10), span);
|
Chris@1615
|
115 QCOMPARE(s.getEventsSpanning(11), span);
|
Chris@1615
|
116 QCOMPARE(s.getEventsSpanning(29), span);
|
Chris@1615
|
117 QCOMPARE(s.getEventsSpanning(30), EventVector());
|
Chris@1615
|
118 QCOMPARE(s.getEventsSpanning(9), EventVector());
|
Chris@1614
|
119
|
Chris@1614
|
120 s.remove(p);
|
Chris@1614
|
121 span.clear();
|
Chris@1614
|
122 span.push_back(p);
|
Chris@1615
|
123 QCOMPARE(s.getEventsSpanning(10), span);
|
Chris@1615
|
124 QCOMPARE(s.getEventsSpanning(11), span);
|
Chris@1615
|
125 QCOMPARE(s.getEventsSpanning(29), span);
|
Chris@1615
|
126 QCOMPARE(s.getEventsSpanning(30), EventVector());
|
Chris@1615
|
127 QCOMPARE(s.getEventsSpanning(9), EventVector());
|
Chris@1614
|
128 }
|
Chris@1614
|
129
|
Chris@1615
|
130 void multipleEventsSpan() {
|
Chris@1614
|
131
|
Chris@1615
|
132 EventSeries s;
|
Chris@1615
|
133 Event a(10, QString("a"));
|
Chris@1615
|
134 Event b(11, QString("b"));
|
Chris@1615
|
135 Event c(40, QString("c"));
|
Chris@1614
|
136 s.add(c);
|
Chris@1614
|
137 s.add(a);
|
Chris@1614
|
138 s.add(b);
|
Chris@1614
|
139 s.remove(a);
|
Chris@1614
|
140 s.add(a);
|
Chris@1614
|
141 s.add(c);
|
Chris@1614
|
142 s.remove(c);
|
Chris@1614
|
143 QCOMPARE(s.count(), 3);
|
Chris@1615
|
144 EventVector span;
|
Chris@1614
|
145 span.push_back(a);
|
Chris@1615
|
146 QCOMPARE(s.getEventsSpanning(10), span);
|
Chris@1614
|
147 span.clear();
|
Chris@1614
|
148 span.push_back(c);
|
Chris@1615
|
149 QCOMPARE(s.getEventsSpanning(40), span);
|
Chris@1615
|
150 QCOMPARE(s.getEventsSpanning(9), EventVector());
|
Chris@1614
|
151 }
|
Chris@1614
|
152
|
Chris@1615
|
153 void disjointEventsWithDurationSpan() {
|
Chris@1614
|
154
|
Chris@1615
|
155 EventSeries s;
|
Chris@1615
|
156 Event a(10, 1.0f, 20, QString("a"));
|
Chris@1615
|
157 Event b(100, 1.2f, 30, QString("b"));
|
Chris@1614
|
158 s.add(a);
|
Chris@1614
|
159 s.add(b);
|
Chris@1615
|
160 QCOMPARE(s.getEventsSpanning(0), EventVector());
|
Chris@1615
|
161 QCOMPARE(s.getEventsSpanning(10), EventVector({ a }));
|
Chris@1615
|
162 QCOMPARE(s.getEventsSpanning(15), EventVector({ a }));
|
Chris@1615
|
163 QCOMPARE(s.getEventsSpanning(30), EventVector());
|
Chris@1615
|
164 QCOMPARE(s.getEventsSpanning(99), EventVector());
|
Chris@1615
|
165 QCOMPARE(s.getEventsSpanning(100), EventVector({ b }));
|
Chris@1615
|
166 QCOMPARE(s.getEventsSpanning(120), EventVector({ b }));
|
Chris@1615
|
167 QCOMPARE(s.getEventsSpanning(130), EventVector());
|
Chris@1614
|
168 }
|
Chris@1614
|
169
|
Chris@1615
|
170 void overlappingEventsWithAndWithoutDurationSpan() {
|
Chris@1614
|
171
|
Chris@1615
|
172 EventSeries s;
|
Chris@1615
|
173 Event p(20, QString("p"));
|
Chris@1615
|
174 Event a(10, 1.0, 20, QString("a"));
|
Chris@1614
|
175 s.add(p);
|
Chris@1614
|
176 s.add(a);
|
Chris@1615
|
177 EventVector span;
|
Chris@1614
|
178 span.push_back(a);
|
Chris@1615
|
179 QCOMPARE(s.getEventsSpanning(15), span);
|
Chris@1615
|
180 QCOMPARE(s.getEventsSpanning(25), span);
|
Chris@1614
|
181 span.clear();
|
Chris@1614
|
182 span.push_back(p);
|
Chris@1614
|
183 span.push_back(a);
|
Chris@1615
|
184 QCOMPARE(s.getEventsSpanning(20), span);
|
Chris@1614
|
185 }
|
Chris@1614
|
186
|
Chris@1615
|
187 void overlappingEventsWithDurationSpan() {
|
Chris@1614
|
188
|
Chris@1615
|
189 EventSeries s;
|
Chris@1615
|
190 Event a(20, 1.0, 10, QString("a"));
|
Chris@1615
|
191 Event b(10, 1.0, 20, QString("b"));
|
Chris@1615
|
192 Event c(10, 1.0, 40, QString("c"));
|
Chris@1614
|
193 s.add(a);
|
Chris@1614
|
194 s.add(b);
|
Chris@1614
|
195 s.add(c);
|
Chris@1615
|
196 QCOMPARE(s.getEventsSpanning(10), EventVector({ b, c }));
|
Chris@1615
|
197 QCOMPARE(s.getEventsSpanning(20), EventVector({ b, c, a }));
|
Chris@1615
|
198 QCOMPARE(s.getEventsSpanning(25), EventVector({ b, c, a }));
|
Chris@1615
|
199 QCOMPARE(s.getEventsSpanning(30), EventVector({ c }));
|
Chris@1615
|
200 QCOMPARE(s.getEventsSpanning(40), EventVector({ c }));
|
Chris@1615
|
201 QCOMPARE(s.getEventsSpanning(50), EventVector());
|
Chris@1614
|
202 }
|
Chris@1614
|
203
|
Chris@1615
|
204 void eventPatternSpan() {
|
Chris@1614
|
205
|
Chris@1615
|
206 EventSeries s;
|
Chris@1615
|
207 Event a(0, 1.0, 18, QString("a"));
|
Chris@1615
|
208 Event b(3, 2.0, 6, QString("b"));
|
Chris@1615
|
209 Event c(5, 3.0, 2, QString("c"));
|
Chris@1615
|
210 Event d(6, 4.0, 10, QString("d"));
|
Chris@1615
|
211 Event e(14, 5.0, 3, QString("e"));
|
Chris@1614
|
212 s.add(b);
|
Chris@1614
|
213 s.add(c);
|
Chris@1614
|
214 s.add(d);
|
Chris@1614
|
215 s.add(a);
|
Chris@1614
|
216 s.add(e);
|
Chris@1615
|
217 QCOMPARE(s.getEventsSpanning(8), EventVector({ a, b, d }));
|
Chris@1614
|
218 }
|
Chris@1612
|
219 };
|
Chris@1612
|
220
|
Chris@1612
|
221 #endif
|