To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / test / TestAgentFeeder.cpp @ 66:7ad142c710c6

History | View | Annotate | Download (6.5 KB)

1 52:34f42a384a7f Chris
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
2
/*
3
    This file is Copyright (c) 2012 Chris Cannam
4

5
    Permission is hereby granted, free of charge, to any person
6
    obtaining a copy of this software and associated documentation
7
    files (the "Software"), to deal in the Software without
8
    restriction, including without limitation the rights to use, copy,
9
    modify, merge, publish, distribute, sublicense, and/or sell copies
10
    of the Software, and to permit persons to whom the Software is
11
    furnished to do so, subject to the following conditions:
12

13
    The above copyright notice and this permission notice shall be
14
    included in all copies or substantial portions of the Software.
15

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