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

History | View | Annotate | Download (6.37 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
BOOST_AUTO_TEST_SUITE(TestAgentFeeder)
39
40
BOOST_AUTO_TEST_CASE(feederEmpty)
41
{
42
    AgentFeeder f;
43
    f.finish();
44
    AgentFeeder::Hypotheses accepted = f.getAcceptedHypotheses();
45
    BOOST_CHECK(accepted.empty());
46
}
47
48
BOOST_AUTO_TEST_CASE(feederSingle)
49
{
50 54:751b43d119cf Chris
    Est e0(low, ms(0), 1);
51
    Est e10(low, ms(10), 1);
52
    Est e20(low, ms(20), 1);
53
    Est e30(low, ms(30), 1);
54 52:34f42a384a7f Chris
55
    AgentFeeder f;
56
    f.feed(e0);
57
    f.feed(e10);
58
    f.feed(e20);
59
    f.feed(e30);
60
    f.finish();
61
62
    AgentFeeder::Hypotheses accepted = f.getAcceptedHypotheses();
63
64
    BOOST_CHECK_EQUAL(accepted.size(), size_t(1));
65
}
66
67
BOOST_AUTO_TEST_CASE(feederPairSeparate)
68
{
69 54:751b43d119cf Chris
    Est e0(low, ms(0), 1);
70
    Est e10(low, ms(10), 1);
71
    Est e20(low, ms(20), 1);
72
    Est e30(low, ms(30), 1);
73 52:34f42a384a7f Chris
74 54:751b43d119cf Chris
    Est f0(high, ms(2000), 1);
75
    Est f10(high, ms(2010), 1);
76
    Est f20(high, ms(2020), 1);
77
    Est f30(high, ms(2030), 1);
78 52:34f42a384a7f Chris
79
    AgentFeeder f;
80
    f.feed(e0);
81
    f.feed(e10);
82
    f.feed(e20);
83
    f.feed(e30);
84
    f.feed(f0);
85
    f.feed(f10);
86
    f.feed(f20);
87
    f.feed(f30);
88
    f.finish();
89
90
    AgentFeeder::Hypotheses accepted =
91
        f.getAcceptedHypotheses();
92
93
    BOOST_CHECK_EQUAL(accepted.size(), size_t(2));
94
}
95
96
BOOST_AUTO_TEST_CASE(feederPairOverlapping)
97
{
98
    // eeee
99
    //   fffffff
100
101
    // (With fffffff stopping before eeee has expired.)
102
103 54:751b43d119cf Chris
    // This should give us one hypothesis, eeee, because eeee is still
104
    // the current hypothesis by the time fffffff ends.
105 52:34f42a384a7f Chris
106 54:751b43d119cf Chris
    Est e0(low, ms(0), 1);
107
    Est e10(low, ms(10), 1);
108 52:34f42a384a7f Chris
109 54:751b43d119cf Chris
    Est e20(low, ms(20), 1);
110
    Est f20(high, ms(20), 1);
111 52:34f42a384a7f Chris
112 54:751b43d119cf Chris
    Est e30(low, ms(30), 1);
113
    Est f30(high, ms(30), 1);
114 52:34f42a384a7f Chris
115 54:751b43d119cf Chris
    Est f40(high, ms(40), 1);
116
    Est f41(high, ms(41), 1);
117
    Est f42(high, ms(42), 1);
118
    Est f43(high, ms(43), 1);
119
    Est f44(high, ms(44), 1);
120 52:34f42a384a7f Chris
121
    AgentFeeder f;
122
    f.feed(e0);
123
    f.feed(e10);
124
    f.feed(e20);
125
    f.feed(f20);
126
    f.feed(e30);
127
    f.feed(f30);
128
    f.feed(f40);
129 54:751b43d119cf Chris
    f.feed(f41);
130
    f.feed(f42);
131
    f.feed(f43);
132
    f.feed(f44);
133 52:34f42a384a7f Chris
    f.finish();
134
135
    AgentFeeder::Hypotheses accepted = f.getAcceptedHypotheses();
136
137
    BOOST_CHECK_EQUAL(accepted.size(), size_t(1));
138
139
    AgentFeeder::Hypotheses::const_iterator i = accepted.begin();
140
141
    BOOST_CHECK_EQUAL(i->getStartTime(), ms(0));
142
    BOOST_CHECK_EQUAL(i->getAcceptedEstimates().size(), size_t(4));
143
}
144
145
BOOST_AUTO_TEST_CASE(feederPairOverlappingLong)
146
{
147
    // eeee
148
    //   fffffff
149
150
    // (With fffffff continuing until after eeee has expired.)
151
152
    // This should give us two overlapping hypotheses. Even though
153
    // the mono feeder only has one satisfied hypothesis at a
154
    // time, the eeee hypothesis should become satisfied before
155
    // the fffffff hypothesis has been, but when the eeee
156
    // hypothesis ends, the fffffff one should replace it. So,
157
    // both should be recognised.
158
159 54:751b43d119cf Chris
    Est e0(low, ms(0), 1);
160
    Est e10(low, ms(10), 1);
161 52:34f42a384a7f Chris
162 54:751b43d119cf Chris
    Est e20(low, ms(20), 1);
163
    Est f20(high, ms(20), 1);
164 52:34f42a384a7f Chris
165 54:751b43d119cf Chris
    Est e30(low, ms(30), 1);
166
    Est f30(high, ms(30), 1);
167 52:34f42a384a7f Chris
168 54:751b43d119cf Chris
    Est f40(high, ms(40), 1);
169
    Est f50(high, ms(50), 1);
170
    Est f60(high, ms(60), 1);
171
    Est f70(high, ms(70), 1);
172
    Est f80(high, ms(80), 1);
173 52:34f42a384a7f Chris
174
    AgentFeeder f;
175
    f.feed(e0);
176
    f.feed(e10);
177
    f.feed(e20);
178
    f.feed(f20);
179
    f.feed(e30);
180
    f.feed(f30);
181
    f.feed(f40);
182
    f.feed(f50);
183
    f.feed(f60);
184
    f.feed(f70);
185
    f.feed(f80);
186
    f.finish();
187
188
    AgentFeeder::Hypotheses accepted = f.getAcceptedHypotheses();
189
190
    BOOST_CHECK_EQUAL(accepted.size(), size_t(2));
191
192
    AgentFeeder::Hypotheses::const_iterator i = accepted.begin();
193
194
    BOOST_CHECK_EQUAL(i->getStartTime(), ms(0));
195
    BOOST_CHECK_EQUAL(i->getAcceptedEstimates().size(), size_t(4));
196
    ++i;
197
198 54:751b43d119cf Chris
    BOOST_CHECK_EQUAL(i->getStartTime(), ms(20));
199 52:34f42a384a7f Chris
    BOOST_CHECK_EQUAL(i->getAcceptedEstimates().size(), size_t(7));
200
    ++i;
201
}
202
203
204
BOOST_AUTO_TEST_CASE(feederPairContaining)
205
{
206
    // eeeeeeee
207
    //   ffff
208
209
    // This should give us eeeeeeee only. The ffff hypothesis
210
    // (even when satisfied itself) cannot replace the single
211
    // satisfied hypothesis eeeeeeee while it is still in
212
    // progress.
213
214 54:751b43d119cf Chris
    Est e0(low, ms(0), 1);
215
    Est e10(low, ms(10), 1);
216
    Est e20(low, ms(20), 1);
217
    Est e30(low, ms(30), 1);
218
    Est e40(low, ms(40), 1);
219
    Est e50(low, ms(50), 1);
220
    Est e60(low, ms(60), 1);
221
    Est e70(low, ms(70), 1);
222 52:34f42a384a7f Chris
223 54:751b43d119cf Chris
    Est f20(high, ms(20), 1);
224
    Est f30(high, ms(30), 1);
225
    Est f40(high, ms(40), 1);
226
    Est f50(high, ms(50), 1);
227 52:34f42a384a7f Chris
228
    AgentFeeder f;
229
230
    f.feed(e0);
231
    f.feed(e10);
232
233
    f.feed(e20);
234
    f.feed(f20);
235
236
    f.feed(e30);
237
    f.feed(f30);
238
239
    f.feed(e40);
240
    f.feed(f40);
241
242
    f.feed(e50);
243
    f.feed(f50);
244
245
    f.feed(e60);
246
    f.feed(e70);
247
248
    f.finish();
249
250
    AgentFeeder::Hypotheses accepted = f.getAcceptedHypotheses();
251
252
    BOOST_CHECK_EQUAL(accepted.size(), size_t(1));
253
254
    AgentFeeder::Hypotheses::const_iterator i = accepted.begin();
255
256
    BOOST_CHECK_EQUAL(i->getStartTime(), ms(0));
257
    BOOST_CHECK_EQUAL(i->getAcceptedEstimates().size(), size_t(8));
258
    ++i;
259
}
260
261
BOOST_AUTO_TEST_SUITE_END()