Revision 66:7ad142c710c6 test

View differences:

test/TestAgentFeeder.cpp
35 35

  
36 36
typedef NoteHypothesis::Estimate Est;
37 37

  
38
#define DEFAULT_SLACK_MS 40
39

  
38 40
BOOST_AUTO_TEST_SUITE(TestAgentFeeder)
39 41

  
40 42
BOOST_AUTO_TEST_CASE(feederEmpty)
41 43
{
42
    AgentFeeder f;
44
    AgentFeeder f(DEFAULT_SLACK_MS);
43 45
    f.finish();
44 46
    AgentFeeder::Hypotheses accepted = f.getAcceptedHypotheses();
45 47
    BOOST_CHECK(accepted.empty());
......
52 54
    Est e20(low, ms(20), 1);
53 55
    Est e30(low, ms(30), 1);
54 56

  
55
    AgentFeeder f;
57
    AgentFeeder f(DEFAULT_SLACK_MS);
56 58
    f.feed(e0);
57 59
    f.feed(e10);
58 60
    f.feed(e20);
......
76 78
    Est f20(high, ms(2020), 1);
77 79
    Est f30(high, ms(2030), 1);
78 80

  
79
    AgentFeeder f;
81
    AgentFeeder f(DEFAULT_SLACK_MS);
80 82
    f.feed(e0);
81 83
    f.feed(e10);
82 84
    f.feed(e20);
......
118 120
    Est f43(high, ms(43), 1);
119 121
    Est f44(high, ms(44), 1);
120 122

  
121
    AgentFeeder f;
123
    AgentFeeder f(DEFAULT_SLACK_MS);
122 124
    f.feed(e0);
123 125
    f.feed(e10);
124 126
    f.feed(e20);
......
171 173
    Est f70(high, ms(70), 1);
172 174
    Est f80(high, ms(80), 1);
173 175

  
174
    AgentFeeder f;
176
    AgentFeeder f(DEFAULT_SLACK_MS);
175 177
    f.feed(e0);
176 178
    f.feed(e10);
177 179
    f.feed(e20);
......
225 227
    Est f40(high, ms(40), 1);
226 228
    Est f50(high, ms(50), 1);
227 229

  
228
    AgentFeeder f;
230
    AgentFeeder f(DEFAULT_SLACK_MS);
229 231

  
230 232
    f.feed(e0);
231 233
    f.feed(e10);
test/TestNoteHypothesis.cpp
49 49

  
50 50
using Vamp::RealTime;
51 51

  
52
#define DEFAULT_SLACK_MS 40
53

  
52 54
BOOST_AUTO_TEST_SUITE(TestNoteHypothesis)
53 55

  
54 56
BOOST_AUTO_TEST_CASE(emptyAccept)
55 57
{
56 58
    // An empty hypothesis should accept any estimate with a
57 59
    // non-negligible confidence, and enter provisional state
58
    NoteHypothesis h;
60
    NoteHypothesis h(DEFAULT_SLACK_MS);
59 61
    NoteHypothesis::Estimate e; // default estimate has confidence 1
60 62
    BOOST_CHECK_EQUAL(h.getState(), NoteHypothesis::New);
61 63
    BOOST_CHECK(h.accept(e));
......
66 68
{
67 69
    // A hypothesis should reject any estimate that has a negligible
68 70
    // confidence
69
    NoteHypothesis h;
71
    NoteHypothesis h(DEFAULT_SLACK_MS);
70 72
    NoteHypothesis::Estimate e;
71 73
    e.confidence = 0;
72 74
    BOOST_CHECK_EQUAL(h.getState(), NoteHypothesis::New);
......
78 80
{
79 81
    // But if we're already in process we don't go to rejected state,
80 82
    // we just ignore this hypothesis
81
    NoteHypothesis h;
83
    NoteHypothesis h(DEFAULT_SLACK_MS);
82 84
    NoteHypothesis::Estimate e;
83 85
    BOOST_CHECK_EQUAL(h.getState(), NoteHypothesis::New);
84 86
    BOOST_CHECK(h.accept(e));
......
92 94
{
93 95
    // Having accepted a first estimate, a hypothesis should reject a
94 96
    // second (and enter rejected state) if there is too long a gap
95
    // between them for them to belong to a single note
96
    NoteHypothesis h;
97
    // between them for them to belong to a single note. Test this
98
    // with more than one slack parameter, since that's what
99
    // determines how long the gap can be.
100

  
101
    {
102
    NoteHypothesis h(40);
97 103
    NoteHypothesis::Estimate e1(500, RealTime::fromMilliseconds(0), 1);
98 104
    NoteHypothesis::Estimate e2(500, RealTime::fromMilliseconds(50), 1);
99 105
    BOOST_CHECK_EQUAL(h.getState(), NoteHypothesis::New);
......
101 107
    BOOST_CHECK_EQUAL(h.getState(), NoteHypothesis::Provisional);
102 108
    BOOST_CHECK(!h.accept(e2));
103 109
    BOOST_CHECK_EQUAL(h.getState(), NoteHypothesis::Rejected);
110
    }
111
    {
112
    NoteHypothesis h(100);
113
    NoteHypothesis::Estimate e1(500, RealTime::fromMilliseconds(0), 1);
114
    NoteHypothesis::Estimate e2(500, RealTime::fromMilliseconds(50), 1);
115
    BOOST_CHECK_EQUAL(h.getState(), NoteHypothesis::New);
116
    BOOST_CHECK(h.accept(e1));
117
    BOOST_CHECK_EQUAL(h.getState(), NoteHypothesis::Provisional);
118
    BOOST_CHECK(h.accept(e2));
119
    BOOST_CHECK_EQUAL(h.getState(), NoteHypothesis::Provisional);
120
    }
104 121
}
105 122

  
106 123
BOOST_AUTO_TEST_CASE(simpleSatisfy)
......
108 125
    // A hypothesis should enter satisfied state after accepting three
109 126
    // consistent estimates, and then remain satisfied while accepting
110 127
    // further consistent estimates
111
    NoteHypothesis h;
128
    NoteHypothesis h(DEFAULT_SLACK_MS);
112 129
    NoteHypothesis::Estimate e1(500, RealTime::fromMilliseconds(0), 1);
113 130
    NoteHypothesis::Estimate e2(500, RealTime::fromMilliseconds(10), 1);
114 131
    NoteHypothesis::Estimate e3(500, RealTime::fromMilliseconds(20), 1);
......
130 147
    // offered an estimate that follows too long a gap, should enter
131 148
    // expired state rather than rejected state (showing that it has a
132 149
    // valid note but that the note has apparently finished)
133
    NoteHypothesis h;
150
    NoteHypothesis h(DEFAULT_SLACK_MS);
134 151
    NoteHypothesis::Estimate e1(500, RealTime::fromMilliseconds(0), 1);
135 152
    NoteHypothesis::Estimate e2(500, RealTime::fromMilliseconds(10), 1);
136 153
    NoteHypothesis::Estimate e3(500, RealTime::fromMilliseconds(20), 1);
......
156 173
{
157 174
    // A wildly different frequency occurring in the middle of a
158 175
    // provisionally accepted note should be ignored
159
    NoteHypothesis h;
176
    NoteHypothesis h(DEFAULT_SLACK_MS);
160 177
    NoteHypothesis::Estimate e1(500, RealTime::fromMilliseconds(0), 1);
161 178
    NoteHypothesis::Estimate e2(1000, RealTime::fromMilliseconds(10), 1);
162 179
    NoteHypothesis::Estimate e3(500, RealTime::fromMilliseconds(20), 1);
......
176 193
{
177 194
    // A wildly different frequency occurring in the middle of a
178 195
    // satisfied note should be ignored
179
    NoteHypothesis h;
196
    NoteHypothesis h(DEFAULT_SLACK_MS);
180 197
    NoteHypothesis::Estimate e1(500, RealTime::fromMilliseconds(0), 1);
181 198
    NoteHypothesis::Estimate e2(500, RealTime::fromMilliseconds(10), 1);
182 199
    NoteHypothesis::Estimate e3(500, RealTime::fromMilliseconds(20), 1);
......
199 216
{
200 217
    // Behaviour with slightly varying frequencies should be as for
201 218
    // that with fixed frequency
202
    NoteHypothesis h;
219
    NoteHypothesis h(DEFAULT_SLACK_MS);
203 220
    NoteHypothesis::Estimate e1(500, RealTime::fromMilliseconds(0), 0.5);
204 221
    NoteHypothesis::Estimate e2(502, RealTime::fromMilliseconds(10), 0.5);
205 222
    NoteHypothesis::Estimate e3(504, RealTime::fromMilliseconds(20), 0.5);
......
225 242
{
226 243
    // But there's a limit: outside a certain range we should reject
227 244
    //!!! (but what is this range? is it part of the spec?)
228
    NoteHypothesis h;
245
    NoteHypothesis h(DEFAULT_SLACK_MS);
229 246
    NoteHypothesis::Estimate e1(440, RealTime::fromMilliseconds(0), 1);
230 247
    NoteHypothesis::Estimate e2(448, RealTime::fromMilliseconds(10), 1);
231 248
    NoteHypothesis::Estimate e3(444, RealTime::fromMilliseconds(20), 1);
......
244 261
BOOST_AUTO_TEST_CASE(acceptedEstimates)
245 262
{
246 263
    // Check that getAcceptedEstimates() returns the right result
247
    NoteHypothesis h;
264
    NoteHypothesis h(DEFAULT_SLACK_MS);
248 265
    NoteHypothesis::Estimate e1(440, RealTime::fromMilliseconds(0), 1);
249 266
    NoteHypothesis::Estimate e2(448, RealTime::fromMilliseconds(10), 1);
250 267
    NoteHypothesis::Estimate e3(444, RealTime::fromMilliseconds(20), 1);
......
276 293
BOOST_AUTO_TEST_CASE(meanFrequency)
277 294
{
278 295
    // Check that the mean frequency is the mean of the frequencies
279
    NoteHypothesis h;
296
    NoteHypothesis h(DEFAULT_SLACK_MS);
280 297
    NoteHypothesis::Estimate e1(440, RealTime::fromMilliseconds(0), 1);
281 298
    NoteHypothesis::Estimate e2(448, RealTime::fromMilliseconds(10), 1);
282 299
    NoteHypothesis::Estimate e3(444, RealTime::fromMilliseconds(20), 1);
......
289 306
BOOST_AUTO_TEST_CASE(averagedNote)
290 307
{
291 308
    // Check that getAveragedNote returns something sane
292
    NoteHypothesis h;
309
    NoteHypothesis h(DEFAULT_SLACK_MS);
293 310
    NoteHypothesis::Estimate e1(440, RealTime::fromMilliseconds(10), 1);
294 311
    NoteHypothesis::Estimate e2(448, RealTime::fromMilliseconds(20), 1);
295 312
    NoteHypothesis::Estimate e3(444, RealTime::fromMilliseconds(30), 1);

Also available in: Unified diff