| 53 |
53 |
|
| 54 |
54 |
BOOST_AUTO_TEST_CASE(emptyAccept)
|
| 55 |
55 |
{
|
|
56 |
// An empty hypothesis should accept any estimate and enter
|
|
57 |
// provisional state
|
| 56 |
58 |
NoteHypothesis h;
|
| 57 |
59 |
NoteHypothesis::Estimate e;
|
| 58 |
60 |
BOOST_CHECK_EQUAL(h.getState(), NoteHypothesis::New);
|
| 59 |
61 |
BOOST_CHECK(h.accept(e));
|
| 60 |
62 |
BOOST_CHECK_EQUAL(h.getState(), NoteHypothesis::Provisional);
|
| 61 |
63 |
}
|
|
64 |
|
|
65 |
BOOST_AUTO_TEST_CASE(tooSlow)
|
|
66 |
{
|
|
67 |
// Having accepted a first estimate, a hypothesis should reject a
|
|
68 |
// second (and enter rejected state) if there is too long a gap
|
|
69 |
// between them for them to belong to a single note
|
|
70 |
NoteHypothesis h;
|
|
71 |
NoteHypothesis::Estimate e1(500, RealTime::fromMilliseconds(0), 1);
|
|
72 |
NoteHypothesis::Estimate e2(500, RealTime::fromMilliseconds(50), 1);
|
|
73 |
BOOST_CHECK_EQUAL(h.getState(), NoteHypothesis::New);
|
|
74 |
BOOST_CHECK(h.accept(e1));
|
|
75 |
BOOST_CHECK_EQUAL(h.getState(), NoteHypothesis::Provisional);
|
|
76 |
BOOST_CHECK(!h.accept(e2));
|
|
77 |
BOOST_CHECK_EQUAL(h.getState(), NoteHypothesis::Rejected);
|
|
78 |
}
|
| 62 |
79 |
|
| 63 |
80 |
BOOST_AUTO_TEST_CASE(simpleSatisfy)
|
| 64 |
81 |
{
|
|
82 |
// A hypothesis should enter satisfied state after accepting three
|
|
83 |
// consistent estimates, and then remain satisfied while accepting
|
|
84 |
// further consistent estimates
|
|
85 |
NoteHypothesis h;
|
|
86 |
NoteHypothesis::Estimate e1(500, RealTime::fromMilliseconds(0), 1);
|
|
87 |
NoteHypothesis::Estimate e2(500, RealTime::fromMilliseconds(10), 1);
|
|
88 |
NoteHypothesis::Estimate e3(500, RealTime::fromMilliseconds(20), 1);
|
|
89 |
NoteHypothesis::Estimate e4(500, RealTime::fromMilliseconds(30), 1);
|
|
90 |
BOOST_CHECK_EQUAL(h.getState(), NoteHypothesis::New);
|
|
91 |
BOOST_CHECK(h.accept(e1));
|
|
92 |
BOOST_CHECK_EQUAL(h.getState(), NoteHypothesis::Provisional);
|
|
93 |
BOOST_CHECK(h.accept(e2));
|
|
94 |
BOOST_CHECK_EQUAL(h.getState(), NoteHypothesis::Provisional);
|
|
95 |
BOOST_CHECK(h.accept(e3));
|
|
96 |
BOOST_CHECK_EQUAL(h.getState(), NoteHypothesis::Satisfied);
|
|
97 |
BOOST_CHECK(h.accept(e4));
|
|
98 |
BOOST_CHECK_EQUAL(h.getState(), NoteHypothesis::Satisfied);
|
|
99 |
}
|
|
100 |
|
|
101 |
BOOST_AUTO_TEST_CASE(expiry)
|
|
102 |
{
|
|
103 |
// A hypothesis that has been satisfied, but that is subsequently
|
|
104 |
// offered an estimate that follows too long a gap, should enter
|
|
105 |
// expired state rather than rejected state (showing that it has a
|
|
106 |
// valid note but that the note has apparently finished)
|
| 65 |
107 |
NoteHypothesis h;
|
| 66 |
108 |
NoteHypothesis::Estimate e1(500, RealTime::fromMilliseconds(0), 1);
|
| 67 |
109 |
NoteHypothesis::Estimate e2(500, RealTime::fromMilliseconds(10), 1);
|
| ... | ... | |
| 84 |
126 |
BOOST_CHECK_EQUAL(h.getState(), NoteHypothesis::Expired);
|
| 85 |
127 |
}
|
| 86 |
128 |
|
| 87 |
|
BOOST_AUTO_TEST_CASE(strayReject)
|
|
129 |
BOOST_AUTO_TEST_CASE(strayReject1)
|
| 88 |
130 |
{
|
|
131 |
// A wildly different frequency occurring in the middle of a
|
|
132 |
// provisionally accepted note should be ignored
|
| 89 |
133 |
NoteHypothesis h;
|
| 90 |
134 |
NoteHypothesis::Estimate e1(500, RealTime::fromMilliseconds(0), 1);
|
| 91 |
135 |
NoteHypothesis::Estimate e2(1000, RealTime::fromMilliseconds(10), 1);
|
| ... | ... | |
| 101 |
145 |
BOOST_CHECK(h.accept(e4));
|
| 102 |
146 |
BOOST_CHECK_EQUAL(h.getState(), NoteHypothesis::Satisfied);
|
| 103 |
147 |
}
|
| 104 |
|
|
| 105 |
|
BOOST_AUTO_TEST_CASE(tooSlow)
|
|
148 |
|
|
149 |
BOOST_AUTO_TEST_CASE(strayReject2)
|
| 106 |
150 |
{
|
|
151 |
// A wildly different frequency occurring in the middle of a
|
|
152 |
// satisfied note should be ignored
|
| 107 |
153 |
NoteHypothesis h;
|
| 108 |
154 |
NoteHypothesis::Estimate e1(500, RealTime::fromMilliseconds(0), 1);
|
| 109 |
|
NoteHypothesis::Estimate e2(500, RealTime::fromMilliseconds(50), 1);
|
|
155 |
NoteHypothesis::Estimate e2(500, RealTime::fromMilliseconds(10), 1);
|
|
156 |
NoteHypothesis::Estimate e3(500, RealTime::fromMilliseconds(20), 1);
|
|
157 |
NoteHypothesis::Estimate e4(1000, RealTime::fromMilliseconds(30), 1);
|
|
158 |
NoteHypothesis::Estimate e5(500, RealTime::fromMilliseconds(40), 1);
|
| 110 |
159 |
BOOST_CHECK_EQUAL(h.getState(), NoteHypothesis::New);
|
| 111 |
160 |
BOOST_CHECK(h.accept(e1));
|
| 112 |
161 |
BOOST_CHECK_EQUAL(h.getState(), NoteHypothesis::Provisional);
|
| 113 |
|
BOOST_CHECK(!h.accept(e2));
|
| 114 |
|
BOOST_CHECK_EQUAL(h.getState(), NoteHypothesis::Rejected);
|
|
162 |
BOOST_CHECK(h.accept(e2));
|
|
163 |
BOOST_CHECK_EQUAL(h.getState(), NoteHypothesis::Provisional);
|
|
164 |
BOOST_CHECK(h.accept(e3));
|
|
165 |
BOOST_CHECK_EQUAL(h.getState(), NoteHypothesis::Satisfied);
|
|
166 |
BOOST_CHECK(!h.accept(e4));
|
|
167 |
BOOST_CHECK_EQUAL(h.getState(), NoteHypothesis::Satisfied);
|
|
168 |
BOOST_CHECK(h.accept(e5));
|
|
169 |
BOOST_CHECK_EQUAL(h.getState(), NoteHypothesis::Satisfied);
|
| 115 |
170 |
}
|
| 116 |
171 |
|
| 117 |
172 |
BOOST_AUTO_TEST_CASE(weakSatisfy)
|
| 118 |
173 |
{
|
|
174 |
// Behaviour with slightly varying frequencies should be as for
|
|
175 |
// that with fixed frequency
|
| 119 |
176 |
NoteHypothesis h;
|
| 120 |
177 |
NoteHypothesis::Estimate e1(500, RealTime::fromMilliseconds(0), 0.5);
|
| 121 |
178 |
NoteHypothesis::Estimate e2(502, RealTime::fromMilliseconds(10), 0.5);
|
| ... | ... | |
| 140 |
197 |
|
| 141 |
198 |
BOOST_AUTO_TEST_CASE(frequencyRange)
|
| 142 |
199 |
{
|
|
200 |
// But there's a limit: outside a certain range we should reject
|
|
201 |
//!!! (but what is this range? is it part of the spec?)
|
| 143 |
202 |
NoteHypothesis h;
|
| 144 |
203 |
NoteHypothesis::Estimate e1(440, RealTime::fromMilliseconds(0), 1);
|
| 145 |
204 |
NoteHypothesis::Estimate e2(448, RealTime::fromMilliseconds(10), 1);
|
| ... | ... | |
| 158 |
217 |
|
| 159 |
218 |
BOOST_AUTO_TEST_CASE(acceptedEstimates)
|
| 160 |
219 |
{
|
|
220 |
// Check that getAcceptedEstimates() returns the right result
|
| 161 |
221 |
NoteHypothesis h;
|
| 162 |
222 |
NoteHypothesis::Estimate e1(440, RealTime::fromMilliseconds(0), 1);
|
| 163 |
223 |
NoteHypothesis::Estimate e2(448, RealTime::fromMilliseconds(10), 1);
|
| ... | ... | |
| 189 |
249 |
|
| 190 |
250 |
BOOST_AUTO_TEST_CASE(meanFrequency)
|
| 191 |
251 |
{
|
|
252 |
// Check that the mean frequency is the mean of the frequencies
|
| 192 |
253 |
NoteHypothesis h;
|
| 193 |
254 |
NoteHypothesis::Estimate e1(440, RealTime::fromMilliseconds(0), 1);
|
| 194 |
255 |
NoteHypothesis::Estimate e2(448, RealTime::fromMilliseconds(10), 1);
|
| ... | ... | |
| 201 |
262 |
|
| 202 |
263 |
BOOST_AUTO_TEST_CASE(averagedNote)
|
| 203 |
264 |
{
|
|
265 |
// Check that getAveragedNote returns something sane
|
| 204 |
266 |
NoteHypothesis h;
|
| 205 |
267 |
NoteHypothesis::Estimate e1(440, RealTime::fromMilliseconds(10), 1);
|
| 206 |
268 |
NoteHypothesis::Estimate e2(448, RealTime::fromMilliseconds(20), 1);
|
| ... | ... | |
| 214 |
276 |
RealTime::fromMilliseconds(20)));
|
| 215 |
277 |
}
|
| 216 |
278 |
|
|
279 |
//!!! Not yet tested: Confidence scores
|
|
280 |
|
| 217 |
281 |
BOOST_AUTO_TEST_SUITE_END()
|
| 218 |
282 |
|