Mercurial > hg > cepstral-pitchtracker
changeset 46:c666067fb8da
Comments
author | Chris Cannam |
---|---|
date | Wed, 15 Aug 2012 14:53:28 +0100 |
parents | 8db4a1f096f0 |
children | f72a470fe4b5 |
files | test/TestPeakInterpolator.cpp |
diffstat | 1 files changed, 30 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/test/TestPeakInterpolator.cpp Tue Aug 14 16:48:19 2012 +0100 +++ b/test/TestPeakInterpolator.cpp Wed Aug 15 14:53:28 2012 +0100 @@ -33,40 +33,52 @@ BOOST_AUTO_TEST_CASE(peakAtSample_N3) { - double data[] = { 0.0, 1.0, 0.0 }; + // Peak exactly at sample index + double data[] = { 0.0, 10.0, 0.0 }; PeakInterpolator p; + // Asked to find peak at index 1, should return index 1 double result = p.findPeakLocation(data, 3, 1); BOOST_CHECK_EQUAL(result, 1.0); + // Asked to find any peak, should return index 1 result = p.findPeakLocation(data, 3); BOOST_CHECK_EQUAL(result, 1.0); } BOOST_AUTO_TEST_CASE(peakAtSample_N5) { - double data[] = { 0.0, 1.0, 2.0, 1.0, 0.0 }; + // Peak exactly at sample index + double data[] = { 0.0, 10.0, 20.0, 10.0, 0.0 }; PeakInterpolator p; + // Asked to find peak at index 2, should return index 2 double result = p.findPeakLocation(data, 5, 2); BOOST_CHECK_EQUAL(result, 2.0); + // Asked to find any peak, should return index 2 result = p.findPeakLocation(data, 5); BOOST_CHECK_EQUAL(result, 2.0); } BOOST_AUTO_TEST_CASE(flat) { + // No peak double data[] = { 1.0, 1.0, 1.0, 1.0, 1.0 }; PeakInterpolator p; + // Asked to find peak at index N, should return N (no superior neighbours) double result = p.findPeakLocation(data, 5, 2); BOOST_CHECK_EQUAL(result, 2.0); + // Asked to find any peak, should return 0 (first value as good as any) result = p.findPeakLocation(data, 5); BOOST_CHECK_EQUAL(result, 0.0); } BOOST_AUTO_TEST_CASE(multiPeak) { + // More than one peak double data[] = { 1.0, 2.0, 1.0, 2.0, 1.0 }; PeakInterpolator p; + // Asked to find peak at index 3, should return index 3 double result = p.findPeakLocation(data, 5, 3); BOOST_CHECK_EQUAL(result, 3.0); + // But asked to find any peak, should return 1 (first peak) result = p.findPeakLocation(data, 5); BOOST_CHECK_EQUAL(result, 1.0); } @@ -74,7 +86,7 @@ BOOST_AUTO_TEST_CASE(start) { // Can't meaningfully interpolate if we're identifying element 0 - // as the peak + // as the peak (nothing to its left) double data[] = { 1.0, 1.0, 0.0, 0.0 }; PeakInterpolator p; double result = p.findPeakLocation(data, 4, 0); @@ -88,24 +100,30 @@ PeakInterpolator p; double result = p.findPeakLocation(data, 4, 3); BOOST_CHECK_EQUAL(result, 3.0); - // But when running without a peak location, we expect idx 2 to be - // picked as peak, not idx 3, so that will result in interpolation + // But when asked to find any peak, we expect idx 2 to be picked, + // not idx 3, so that will result in interpolation result = p.findPeakLocation(data, 4); BOOST_CHECK(result > 2.0 && result < 3.0); } BOOST_AUTO_TEST_CASE(longHalfway) { + // Peak is exactly half-way between indices double data[] = { 1.0, 1.0, 1.0, 2.0, 2.0, 1.0, 1.0, 1.0 }; PeakInterpolator p; - double result = p.findPeakLocation(data, 8, 4); + // Asked to find peak for either index 3 or 4, should return 3.5 + double result = p.findPeakLocation(data, 8, 3); BOOST_CHECK_EQUAL(result, 3.5); + result = p.findPeakLocation(data, 8, 4); + BOOST_CHECK_EQUAL(result, 3.5); + // Likewise if asked to find any peak result = p.findPeakLocation(data, 8); BOOST_CHECK_EQUAL(result, 3.5); } BOOST_AUTO_TEST_CASE(shortHalfway) { + // As longHalfway, but with fewer points double data[] = { 1.0, 2.0, 2.0, 1.0 }; PeakInterpolator p; double result = p.findPeakLocation(data, 4, 1); @@ -116,6 +134,9 @@ BOOST_AUTO_TEST_CASE(aboveHalfway) { + // Peak is nearer to one index than its neighbour. (Exact position + // depends on the peak interpolation method in use; we only know + // that it must be beyond the half way point) double data[] = { 1.0, 1.5, 2.0, 1.0 }; PeakInterpolator p; double result = p.findPeakLocation(data, 4, 2); @@ -126,6 +147,9 @@ BOOST_AUTO_TEST_CASE(belowHalfway) { + // Peak is nearer to one index than its neighbour. (Exact position + // depends on the peak interpolation method in use; we only know + // that it must be before the half way point) double data[] = { 1.0, 2.0, 1.5, 1.0 }; PeakInterpolator p; double result = p.findPeakLocation(data, 4, 1);