Chris@52
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@52
|
2 /*
|
Chris@52
|
3 This file is Copyright (c) 2012 Chris Cannam
|
Chris@52
|
4
|
Chris@52
|
5 Permission is hereby granted, free of charge, to any person
|
Chris@52
|
6 obtaining a copy of this software and associated documentation
|
Chris@52
|
7 files (the "Software"), to deal in the Software without
|
Chris@52
|
8 restriction, including without limitation the rights to use, copy,
|
Chris@52
|
9 modify, merge, publish, distribute, sublicense, and/or sell copies
|
Chris@52
|
10 of the Software, and to permit persons to whom the Software is
|
Chris@52
|
11 furnished to do so, subject to the following conditions:
|
Chris@52
|
12
|
Chris@52
|
13 The above copyright notice and this permission notice shall be
|
Chris@52
|
14 included in all copies or substantial portions of the Software.
|
Chris@52
|
15
|
Chris@52
|
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
Chris@52
|
17 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
Chris@52
|
18 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
Chris@52
|
19 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
|
Chris@52
|
20 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
Chris@52
|
21 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
Chris@52
|
22 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
Chris@52
|
23 */
|
Chris@52
|
24
|
Chris@52
|
25 #include "AgentFeeder.h"
|
Chris@52
|
26
|
Chris@52
|
27 #define BOOST_TEST_DYN_LINK
|
Chris@52
|
28 #define BOOST_TEST_MAIN
|
Chris@52
|
29
|
Chris@52
|
30 #include <boost/test/unit_test.hpp>
|
Chris@52
|
31
|
Chris@52
|
32 static Vamp::RealTime ms(int n) { return Vamp::RealTime::fromMilliseconds(n); }
|
Chris@52
|
33
|
Chris@54
|
34 static const int low = 500, high = 700;
|
Chris@54
|
35
|
Chris@52
|
36 typedef NoteHypothesis::Estimate Est;
|
Chris@52
|
37
|
Chris@52
|
38 BOOST_AUTO_TEST_SUITE(TestAgentFeeder)
|
Chris@52
|
39
|
Chris@52
|
40 BOOST_AUTO_TEST_CASE(feederEmpty)
|
Chris@52
|
41 {
|
Chris@52
|
42 AgentFeeder f;
|
Chris@52
|
43 f.finish();
|
Chris@52
|
44 AgentFeeder::Hypotheses accepted = f.getAcceptedHypotheses();
|
Chris@52
|
45 BOOST_CHECK(accepted.empty());
|
Chris@52
|
46 }
|
Chris@52
|
47
|
Chris@52
|
48 BOOST_AUTO_TEST_CASE(feederSingle)
|
Chris@52
|
49 {
|
Chris@54
|
50 Est e0(low, ms(0), 1);
|
Chris@54
|
51 Est e10(low, ms(10), 1);
|
Chris@54
|
52 Est e20(low, ms(20), 1);
|
Chris@54
|
53 Est e30(low, ms(30), 1);
|
Chris@52
|
54
|
Chris@52
|
55 AgentFeeder f;
|
Chris@52
|
56 f.feed(e0);
|
Chris@52
|
57 f.feed(e10);
|
Chris@52
|
58 f.feed(e20);
|
Chris@52
|
59 f.feed(e30);
|
Chris@52
|
60 f.finish();
|
Chris@52
|
61
|
Chris@52
|
62 AgentFeeder::Hypotheses accepted = f.getAcceptedHypotheses();
|
Chris@52
|
63
|
Chris@52
|
64 BOOST_CHECK_EQUAL(accepted.size(), size_t(1));
|
Chris@52
|
65 }
|
Chris@52
|
66
|
Chris@52
|
67 BOOST_AUTO_TEST_CASE(feederPairSeparate)
|
Chris@52
|
68 {
|
Chris@54
|
69 Est e0(low, ms(0), 1);
|
Chris@54
|
70 Est e10(low, ms(10), 1);
|
Chris@54
|
71 Est e20(low, ms(20), 1);
|
Chris@54
|
72 Est e30(low, ms(30), 1);
|
Chris@52
|
73
|
Chris@54
|
74 Est f0(high, ms(2000), 1);
|
Chris@54
|
75 Est f10(high, ms(2010), 1);
|
Chris@54
|
76 Est f20(high, ms(2020), 1);
|
Chris@54
|
77 Est f30(high, ms(2030), 1);
|
Chris@52
|
78
|
Chris@52
|
79 AgentFeeder f;
|
Chris@52
|
80 f.feed(e0);
|
Chris@52
|
81 f.feed(e10);
|
Chris@52
|
82 f.feed(e20);
|
Chris@52
|
83 f.feed(e30);
|
Chris@52
|
84 f.feed(f0);
|
Chris@52
|
85 f.feed(f10);
|
Chris@52
|
86 f.feed(f20);
|
Chris@52
|
87 f.feed(f30);
|
Chris@52
|
88 f.finish();
|
Chris@52
|
89
|
Chris@52
|
90 AgentFeeder::Hypotheses accepted =
|
Chris@52
|
91 f.getAcceptedHypotheses();
|
Chris@52
|
92
|
Chris@52
|
93 BOOST_CHECK_EQUAL(accepted.size(), size_t(2));
|
Chris@52
|
94 }
|
Chris@52
|
95
|
Chris@52
|
96 BOOST_AUTO_TEST_CASE(feederPairOverlapping)
|
Chris@52
|
97 {
|
Chris@52
|
98 // eeee
|
Chris@52
|
99 // fffffff
|
Chris@52
|
100
|
Chris@52
|
101 // (With fffffff stopping before eeee has expired.)
|
Chris@52
|
102
|
Chris@54
|
103 // This should give us one hypothesis, eeee, because eeee is still
|
Chris@54
|
104 // the current hypothesis by the time fffffff ends.
|
Chris@52
|
105
|
Chris@54
|
106 Est e0(low, ms(0), 1);
|
Chris@54
|
107 Est e10(low, ms(10), 1);
|
Chris@52
|
108
|
Chris@54
|
109 Est e20(low, ms(20), 1);
|
Chris@54
|
110 Est f20(high, ms(20), 1);
|
Chris@52
|
111
|
Chris@54
|
112 Est e30(low, ms(30), 1);
|
Chris@54
|
113 Est f30(high, ms(30), 1);
|
Chris@52
|
114
|
Chris@54
|
115 Est f40(high, ms(40), 1);
|
Chris@54
|
116 Est f41(high, ms(41), 1);
|
Chris@54
|
117 Est f42(high, ms(42), 1);
|
Chris@54
|
118 Est f43(high, ms(43), 1);
|
Chris@54
|
119 Est f44(high, ms(44), 1);
|
Chris@52
|
120
|
Chris@52
|
121 AgentFeeder f;
|
Chris@52
|
122 f.feed(e0);
|
Chris@52
|
123 f.feed(e10);
|
Chris@52
|
124 f.feed(e20);
|
Chris@52
|
125 f.feed(f20);
|
Chris@52
|
126 f.feed(e30);
|
Chris@52
|
127 f.feed(f30);
|
Chris@52
|
128 f.feed(f40);
|
Chris@54
|
129 f.feed(f41);
|
Chris@54
|
130 f.feed(f42);
|
Chris@54
|
131 f.feed(f43);
|
Chris@54
|
132 f.feed(f44);
|
Chris@52
|
133 f.finish();
|
Chris@52
|
134
|
Chris@52
|
135 AgentFeeder::Hypotheses accepted = f.getAcceptedHypotheses();
|
Chris@52
|
136
|
Chris@52
|
137 BOOST_CHECK_EQUAL(accepted.size(), size_t(1));
|
Chris@52
|
138
|
Chris@52
|
139 AgentFeeder::Hypotheses::const_iterator i = accepted.begin();
|
Chris@52
|
140
|
Chris@52
|
141 BOOST_CHECK_EQUAL(i->getStartTime(), ms(0));
|
Chris@52
|
142 BOOST_CHECK_EQUAL(i->getAcceptedEstimates().size(), size_t(4));
|
Chris@52
|
143 }
|
Chris@52
|
144
|
Chris@52
|
145 BOOST_AUTO_TEST_CASE(feederPairOverlappingLong)
|
Chris@52
|
146 {
|
Chris@52
|
147 // eeee
|
Chris@52
|
148 // fffffff
|
Chris@52
|
149
|
Chris@52
|
150 // (With fffffff continuing until after eeee has expired.)
|
Chris@52
|
151
|
Chris@52
|
152 // This should give us two overlapping hypotheses. Even though
|
Chris@52
|
153 // the mono feeder only has one satisfied hypothesis at a
|
Chris@52
|
154 // time, the eeee hypothesis should become satisfied before
|
Chris@52
|
155 // the fffffff hypothesis has been, but when the eeee
|
Chris@52
|
156 // hypothesis ends, the fffffff one should replace it. So,
|
Chris@52
|
157 // both should be recognised.
|
Chris@52
|
158
|
Chris@54
|
159 Est e0(low, ms(0), 1);
|
Chris@54
|
160 Est e10(low, ms(10), 1);
|
Chris@52
|
161
|
Chris@54
|
162 Est e20(low, ms(20), 1);
|
Chris@54
|
163 Est f20(high, ms(20), 1);
|
Chris@52
|
164
|
Chris@54
|
165 Est e30(low, ms(30), 1);
|
Chris@54
|
166 Est f30(high, ms(30), 1);
|
Chris@52
|
167
|
Chris@54
|
168 Est f40(high, ms(40), 1);
|
Chris@54
|
169 Est f50(high, ms(50), 1);
|
Chris@54
|
170 Est f60(high, ms(60), 1);
|
Chris@54
|
171 Est f70(high, ms(70), 1);
|
Chris@54
|
172 Est f80(high, ms(80), 1);
|
Chris@52
|
173
|
Chris@52
|
174 AgentFeeder f;
|
Chris@52
|
175 f.feed(e0);
|
Chris@52
|
176 f.feed(e10);
|
Chris@52
|
177 f.feed(e20);
|
Chris@52
|
178 f.feed(f20);
|
Chris@52
|
179 f.feed(e30);
|
Chris@52
|
180 f.feed(f30);
|
Chris@52
|
181 f.feed(f40);
|
Chris@52
|
182 f.feed(f50);
|
Chris@52
|
183 f.feed(f60);
|
Chris@52
|
184 f.feed(f70);
|
Chris@52
|
185 f.feed(f80);
|
Chris@52
|
186 f.finish();
|
Chris@52
|
187
|
Chris@52
|
188 AgentFeeder::Hypotheses accepted = f.getAcceptedHypotheses();
|
Chris@52
|
189
|
Chris@52
|
190 BOOST_CHECK_EQUAL(accepted.size(), size_t(2));
|
Chris@52
|
191
|
Chris@52
|
192 AgentFeeder::Hypotheses::const_iterator i = accepted.begin();
|
Chris@52
|
193
|
Chris@52
|
194 BOOST_CHECK_EQUAL(i->getStartTime(), ms(0));
|
Chris@52
|
195 BOOST_CHECK_EQUAL(i->getAcceptedEstimates().size(), size_t(4));
|
Chris@52
|
196 ++i;
|
Chris@52
|
197
|
Chris@54
|
198 BOOST_CHECK_EQUAL(i->getStartTime(), ms(20));
|
Chris@52
|
199 BOOST_CHECK_EQUAL(i->getAcceptedEstimates().size(), size_t(7));
|
Chris@52
|
200 ++i;
|
Chris@52
|
201 }
|
Chris@52
|
202
|
Chris@52
|
203
|
Chris@52
|
204 BOOST_AUTO_TEST_CASE(feederPairContaining)
|
Chris@52
|
205 {
|
Chris@52
|
206 // eeeeeeee
|
Chris@52
|
207 // ffff
|
Chris@52
|
208
|
Chris@52
|
209 // This should give us eeeeeeee only. The ffff hypothesis
|
Chris@52
|
210 // (even when satisfied itself) cannot replace the single
|
Chris@52
|
211 // satisfied hypothesis eeeeeeee while it is still in
|
Chris@52
|
212 // progress.
|
Chris@52
|
213
|
Chris@54
|
214 Est e0(low, ms(0), 1);
|
Chris@54
|
215 Est e10(low, ms(10), 1);
|
Chris@54
|
216 Est e20(low, ms(20), 1);
|
Chris@54
|
217 Est e30(low, ms(30), 1);
|
Chris@54
|
218 Est e40(low, ms(40), 1);
|
Chris@54
|
219 Est e50(low, ms(50), 1);
|
Chris@54
|
220 Est e60(low, ms(60), 1);
|
Chris@54
|
221 Est e70(low, ms(70), 1);
|
Chris@52
|
222
|
Chris@54
|
223 Est f20(high, ms(20), 1);
|
Chris@54
|
224 Est f30(high, ms(30), 1);
|
Chris@54
|
225 Est f40(high, ms(40), 1);
|
Chris@54
|
226 Est f50(high, ms(50), 1);
|
Chris@52
|
227
|
Chris@52
|
228 AgentFeeder f;
|
Chris@52
|
229
|
Chris@52
|
230 f.feed(e0);
|
Chris@52
|
231 f.feed(e10);
|
Chris@52
|
232
|
Chris@52
|
233 f.feed(e20);
|
Chris@52
|
234 f.feed(f20);
|
Chris@52
|
235
|
Chris@52
|
236 f.feed(e30);
|
Chris@52
|
237 f.feed(f30);
|
Chris@52
|
238
|
Chris@52
|
239 f.feed(e40);
|
Chris@52
|
240 f.feed(f40);
|
Chris@52
|
241
|
Chris@52
|
242 f.feed(e50);
|
Chris@52
|
243 f.feed(f50);
|
Chris@52
|
244
|
Chris@52
|
245 f.feed(e60);
|
Chris@52
|
246 f.feed(e70);
|
Chris@52
|
247
|
Chris@52
|
248 f.finish();
|
Chris@52
|
249
|
Chris@52
|
250 AgentFeeder::Hypotheses accepted = f.getAcceptedHypotheses();
|
Chris@52
|
251
|
Chris@52
|
252 BOOST_CHECK_EQUAL(accepted.size(), size_t(1));
|
Chris@52
|
253
|
Chris@52
|
254 AgentFeeder::Hypotheses::const_iterator i = accepted.begin();
|
Chris@52
|
255
|
Chris@52
|
256 BOOST_CHECK_EQUAL(i->getStartTime(), ms(0));
|
Chris@52
|
257 BOOST_CHECK_EQUAL(i->getAcceptedEstimates().size(), size_t(8));
|
Chris@52
|
258 ++i;
|
Chris@52
|
259 }
|
Chris@52
|
260
|
Chris@52
|
261 BOOST_AUTO_TEST_SUITE_END()
|
Chris@52
|
262
|