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 @ 52:34f42a384a7f

History | View | Annotate | Download (6.16 KB)

1
/* -*- 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
typedef NoteHypothesis::Estimate Est;
35

    
36
BOOST_AUTO_TEST_SUITE(TestAgentFeeder)
37

    
38
BOOST_AUTO_TEST_CASE(feederEmpty)
39
{
40
    AgentFeeder f;
41
    f.finish();
42
    AgentFeeder::Hypotheses accepted = f.getAcceptedHypotheses();
43
    BOOST_CHECK(accepted.empty());
44
}
45

    
46
BOOST_AUTO_TEST_CASE(feederSingle)
47
{
48
    Est e0(1, ms(0), 1);
49
    Est e10(1, ms(10), 1);
50
    Est e20(1, ms(20), 1);
51
    Est e30(1, ms(30), 1);
52

    
53
    AgentFeeder f;
54
    f.feed(e0);
55
    f.feed(e10);
56
    f.feed(e20);
57
    f.feed(e30);
58
    f.finish();
59

    
60
    AgentFeeder::Hypotheses accepted = f.getAcceptedHypotheses();
61
    
62
    BOOST_CHECK_EQUAL(accepted.size(), size_t(1));
63
}
64

    
65
BOOST_AUTO_TEST_CASE(feederPairSeparate)
66
{
67
    Est e0(1, ms(0), 1);
68
    Est e10(1, ms(10), 1);
69
    Est e20(1, ms(20), 1);
70
    Est e30(1, ms(30), 1);
71

    
72
    Est f0(3, ms(2000), 1);
73
    Est f10(3, ms(2010), 1);
74
    Est f20(3, ms(2020), 1);
75
    Est f30(3, ms(2030), 1);
76

    
77
    AgentFeeder f;
78
    f.feed(e0);
79
    f.feed(e10);
80
    f.feed(e20);
81
    f.feed(e30);
82
    f.feed(f0);
83
    f.feed(f10);
84
    f.feed(f20);
85
    f.feed(f30);
86
    f.finish();
87

    
88
    AgentFeeder::Hypotheses accepted =
89
        f.getAcceptedHypotheses();
90
    
91
    BOOST_CHECK_EQUAL(accepted.size(), size_t(2));
92
}
93

    
94
BOOST_AUTO_TEST_CASE(feederPairOverlapping)
95
{
96
    // eeee
97
    //   fffffff
98

    
99
    // (With fffffff stopping before eeee has expired.)
100

    
101
    // This should give us one hypothesis, eeee.
102

    
103
    Est e0(1, ms(0), 1);
104
    Est e10(1, ms(10), 1);
105

    
106
    Est e20(1, ms(20), 1);
107
    Est f20(3, ms(20), 1);
108

    
109
    Est e30(1, ms(30), 1);
110
    Est f30(3, ms(30), 1);
111

    
112
    Est f40(3, ms(40), 1);
113
    Est f50(3, ms(50), 1);
114
    Est f60(3, ms(60), 1);
115
    Est f70(3, ms(70), 1);
116
    Est f80(3, ms(80), 1);
117

    
118
    AgentFeeder f;
119
    f.feed(e0);
120
    f.feed(e10);
121
    f.feed(e20);
122
    f.feed(f20);
123
    f.feed(e30);
124
    f.feed(f30);
125
    f.feed(f40);
126
    f.feed(f50);
127
    f.feed(f60);
128
    f.feed(f70);
129
    f.feed(f80);
130
    f.finish();
131

    
132
    AgentFeeder::Hypotheses accepted = f.getAcceptedHypotheses();
133
    
134
    BOOST_CHECK_EQUAL(accepted.size(), size_t(1));
135

    
136
    AgentFeeder::Hypotheses::const_iterator i = accepted.begin();
137

    
138
    BOOST_CHECK_EQUAL(i->getStartTime(), ms(0)); 
139
    BOOST_CHECK_EQUAL(i->getAcceptedEstimates().size(), size_t(4));
140
}
141
        
142
BOOST_AUTO_TEST_CASE(feederPairOverlappingLong)
143
{
144
    // eeee
145
    //   fffffff
146

    
147
    // (With fffffff continuing until after eeee has expired.)
148

    
149
    // This should give us two overlapping hypotheses. Even though
150
    // the mono feeder only has one satisfied hypothesis at a
151
    // time, the eeee hypothesis should become satisfied before
152
    // the fffffff hypothesis has been, but when the eeee
153
    // hypothesis ends, the fffffff one should replace it. So,
154
    // both should be recognised.
155

    
156
    Est e0(1, ms(0), 1);
157
    Est e10(1, ms(500), 1);
158

    
159
    Est e20(1, ms(1000), 1);
160
    Est f20(3, ms(1000), 1);
161

    
162
    Est e30(1, ms(1500), 1);
163
    Est f30(3, ms(1500), 1);
164

    
165
    Est f40(3, ms(2000), 1);
166
    Est f50(3, ms(2500), 1);
167
    Est f60(3, ms(3000), 1);
168
    Est f70(3, ms(3500), 1);
169
    Est f80(3, ms(4000), 1);
170

    
171
    AgentFeeder f;
172
    f.feed(e0);
173
    f.feed(e10);
174
    f.feed(e20);
175
    f.feed(f20);
176
    f.feed(e30);
177
    f.feed(f30);
178
    f.feed(f40);
179
    f.feed(f50);
180
    f.feed(f60);
181
    f.feed(f70);
182
    f.feed(f80);
183
    f.finish();
184

    
185
    AgentFeeder::Hypotheses accepted = f.getAcceptedHypotheses();
186
    
187
    BOOST_CHECK_EQUAL(accepted.size(), size_t(2));
188

    
189
    AgentFeeder::Hypotheses::const_iterator i = accepted.begin();
190

    
191
    BOOST_CHECK_EQUAL(i->getStartTime(), ms(0)); 
192
    BOOST_CHECK_EQUAL(i->getAcceptedEstimates().size(), size_t(4));
193
    ++i;
194

    
195
    BOOST_CHECK_EQUAL(i->getStartTime(), ms(1000)); 
196
    BOOST_CHECK_EQUAL(i->getAcceptedEstimates().size(), size_t(7));
197
    ++i;
198
}
199
        
200

    
201
BOOST_AUTO_TEST_CASE(feederPairContaining)
202
{
203
    // eeeeeeee
204
    //   ffff
205

    
206
    // This should give us eeeeeeee only. The ffff hypothesis
207
    // (even when satisfied itself) cannot replace the single
208
    // satisfied hypothesis eeeeeeee while it is still in
209
    // progress.
210

    
211
    Est e0(1, ms(0), 1);
212
    Est e10(1, ms(10), 1);
213
    Est e20(1, ms(20), 1);
214
    Est e30(1, ms(30), 1);
215
    Est e40(1, ms(40), 1);
216
    Est e50(1, ms(50), 1);
217
    Est e60(1, ms(60), 1);
218
    Est e70(1, ms(70), 1);
219

    
220
    Est f20(3, ms(20), 1);
221
    Est f30(3, ms(30), 1);
222
    Est f40(3, ms(40), 1);
223
    Est f50(3, ms(50), 1);
224

    
225
    AgentFeeder f;
226

    
227
    f.feed(e0);
228
    f.feed(e10);
229

    
230
    f.feed(e20);
231
    f.feed(f20);
232

    
233
    f.feed(e30);
234
    f.feed(f30);
235

    
236
    f.feed(e40);
237
    f.feed(f40);
238

    
239
    f.feed(e50);
240
    f.feed(f50);
241

    
242
    f.feed(e60);
243
    f.feed(e70);
244

    
245
    f.finish();
246

    
247
    AgentFeeder::Hypotheses accepted = f.getAcceptedHypotheses();
248
    
249
    BOOST_CHECK_EQUAL(accepted.size(), size_t(1));
250
   
251
    AgentFeeder::Hypotheses::const_iterator i = accepted.begin();
252

    
253
    BOOST_CHECK_EQUAL(i->getStartTime(), ms(0));
254
    BOOST_CHECK_EQUAL(i->getAcceptedEstimates().size(), size_t(8));
255
    ++i;
256
}
257
        
258
BOOST_AUTO_TEST_SUITE_END()
259