Revision 46:c666067fb8da
| test/TestPeakInterpolator.cpp | ||
|---|---|---|
| 33 | 33 |
|
| 34 | 34 |
BOOST_AUTO_TEST_CASE(peakAtSample_N3) |
| 35 | 35 |
{
|
| 36 |
double data[] = { 0.0, 1.0, 0.0 };
|
|
| 36 |
// Peak exactly at sample index |
|
| 37 |
double data[] = { 0.0, 10.0, 0.0 };
|
|
| 37 | 38 |
PeakInterpolator p; |
| 39 |
// Asked to find peak at index 1, should return index 1 |
|
| 38 | 40 |
double result = p.findPeakLocation(data, 3, 1); |
| 39 | 41 |
BOOST_CHECK_EQUAL(result, 1.0); |
| 42 |
// Asked to find any peak, should return index 1 |
|
| 40 | 43 |
result = p.findPeakLocation(data, 3); |
| 41 | 44 |
BOOST_CHECK_EQUAL(result, 1.0); |
| 42 | 45 |
} |
| 43 | 46 |
|
| 44 | 47 |
BOOST_AUTO_TEST_CASE(peakAtSample_N5) |
| 45 | 48 |
{
|
| 46 |
double data[] = { 0.0, 1.0, 2.0, 1.0, 0.0 };
|
|
| 49 |
// Peak exactly at sample index |
|
| 50 |
double data[] = { 0.0, 10.0, 20.0, 10.0, 0.0 };
|
|
| 47 | 51 |
PeakInterpolator p; |
| 52 |
// Asked to find peak at index 2, should return index 2 |
|
| 48 | 53 |
double result = p.findPeakLocation(data, 5, 2); |
| 49 | 54 |
BOOST_CHECK_EQUAL(result, 2.0); |
| 55 |
// Asked to find any peak, should return index 2 |
|
| 50 | 56 |
result = p.findPeakLocation(data, 5); |
| 51 | 57 |
BOOST_CHECK_EQUAL(result, 2.0); |
| 52 | 58 |
} |
| 53 | 59 |
|
| 54 | 60 |
BOOST_AUTO_TEST_CASE(flat) |
| 55 | 61 |
{
|
| 62 |
// No peak |
|
| 56 | 63 |
double data[] = { 1.0, 1.0, 1.0, 1.0, 1.0 };
|
| 57 | 64 |
PeakInterpolator p; |
| 65 |
// Asked to find peak at index N, should return N (no superior neighbours) |
|
| 58 | 66 |
double result = p.findPeakLocation(data, 5, 2); |
| 59 | 67 |
BOOST_CHECK_EQUAL(result, 2.0); |
| 68 |
// Asked to find any peak, should return 0 (first value as good as any) |
|
| 60 | 69 |
result = p.findPeakLocation(data, 5); |
| 61 | 70 |
BOOST_CHECK_EQUAL(result, 0.0); |
| 62 | 71 |
} |
| 63 | 72 |
|
| 64 | 73 |
BOOST_AUTO_TEST_CASE(multiPeak) |
| 65 | 74 |
{
|
| 75 |
// More than one peak |
|
| 66 | 76 |
double data[] = { 1.0, 2.0, 1.0, 2.0, 1.0 };
|
| 67 | 77 |
PeakInterpolator p; |
| 78 |
// Asked to find peak at index 3, should return index 3 |
|
| 68 | 79 |
double result = p.findPeakLocation(data, 5, 3); |
| 69 | 80 |
BOOST_CHECK_EQUAL(result, 3.0); |
| 81 |
// But asked to find any peak, should return 1 (first peak) |
|
| 70 | 82 |
result = p.findPeakLocation(data, 5); |
| 71 | 83 |
BOOST_CHECK_EQUAL(result, 1.0); |
| 72 | 84 |
} |
| ... | ... | |
| 74 | 86 |
BOOST_AUTO_TEST_CASE(start) |
| 75 | 87 |
{
|
| 76 | 88 |
// Can't meaningfully interpolate if we're identifying element 0 |
| 77 |
// as the peak |
|
| 89 |
// as the peak (nothing to its left)
|
|
| 78 | 90 |
double data[] = { 1.0, 1.0, 0.0, 0.0 };
|
| 79 | 91 |
PeakInterpolator p; |
| 80 | 92 |
double result = p.findPeakLocation(data, 4, 0); |
| ... | ... | |
| 88 | 100 |
PeakInterpolator p; |
| 89 | 101 |
double result = p.findPeakLocation(data, 4, 3); |
| 90 | 102 |
BOOST_CHECK_EQUAL(result, 3.0); |
| 91 |
// But when running without a peak location, we expect idx 2 to be
|
|
| 92 |
// picked as peak, not idx 3, so that will result in interpolation
|
|
| 103 |
// But when asked to find any peak, we expect idx 2 to be picked,
|
|
| 104 |
// not idx 3, so that will result in interpolation |
|
| 93 | 105 |
result = p.findPeakLocation(data, 4); |
| 94 | 106 |
BOOST_CHECK(result > 2.0 && result < 3.0); |
| 95 | 107 |
} |
| 96 | 108 |
|
| 97 | 109 |
BOOST_AUTO_TEST_CASE(longHalfway) |
| 98 | 110 |
{
|
| 111 |
// Peak is exactly half-way between indices |
|
| 99 | 112 |
double data[] = { 1.0, 1.0, 1.0, 2.0, 2.0, 1.0, 1.0, 1.0 };
|
| 100 | 113 |
PeakInterpolator p; |
| 101 |
double result = p.findPeakLocation(data, 8, 4); |
|
| 114 |
// Asked to find peak for either index 3 or 4, should return 3.5 |
|
| 115 |
double result = p.findPeakLocation(data, 8, 3); |
|
| 102 | 116 |
BOOST_CHECK_EQUAL(result, 3.5); |
| 117 |
result = p.findPeakLocation(data, 8, 4); |
|
| 118 |
BOOST_CHECK_EQUAL(result, 3.5); |
|
| 119 |
// Likewise if asked to find any peak |
|
| 103 | 120 |
result = p.findPeakLocation(data, 8); |
| 104 | 121 |
BOOST_CHECK_EQUAL(result, 3.5); |
| 105 | 122 |
} |
| 106 | 123 |
|
| 107 | 124 |
BOOST_AUTO_TEST_CASE(shortHalfway) |
| 108 | 125 |
{
|
| 126 |
// As longHalfway, but with fewer points |
|
| 109 | 127 |
double data[] = { 1.0, 2.0, 2.0, 1.0 };
|
| 110 | 128 |
PeakInterpolator p; |
| 111 | 129 |
double result = p.findPeakLocation(data, 4, 1); |
| ... | ... | |
| 116 | 134 |
|
| 117 | 135 |
BOOST_AUTO_TEST_CASE(aboveHalfway) |
| 118 | 136 |
{
|
| 137 |
// Peak is nearer to one index than its neighbour. (Exact position |
|
| 138 |
// depends on the peak interpolation method in use; we only know |
|
| 139 |
// that it must be beyond the half way point) |
|
| 119 | 140 |
double data[] = { 1.0, 1.5, 2.0, 1.0 };
|
| 120 | 141 |
PeakInterpolator p; |
| 121 | 142 |
double result = p.findPeakLocation(data, 4, 2); |
| ... | ... | |
| 126 | 147 |
|
| 127 | 148 |
BOOST_AUTO_TEST_CASE(belowHalfway) |
| 128 | 149 |
{
|
| 150 |
// Peak is nearer to one index than its neighbour. (Exact position |
|
| 151 |
// depends on the peak interpolation method in use; we only know |
|
| 152 |
// that it must be before the half way point) |
|
| 129 | 153 |
double data[] = { 1.0, 2.0, 1.5, 1.0 };
|
| 130 | 154 |
PeakInterpolator p; |
| 131 | 155 |
double result = p.findPeakLocation(data, 4, 1); |
Also available in: Unified diff