ProteoWizard
Classes | Functions | Variables
LocalMaximumPeakDetectorTest.cpp File Reference
#include "LocalMaximumPeakDetector.hpp"
#include "pwiz/utility/misc/unit.hpp"
#include "pwiz/utility/misc/Std.hpp"

Go to the source code of this file.

Classes

struct  TestData
 

Functions

vector< double > parseDoubleArray (const string &doubleArray)
 
void test ()
 
int main (int argc, char *argv[])
 

Variables

ostream * os_ = 0
 
const TestData testData []
 
const size_t testDataSize = sizeof(testData) / sizeof(TestData)
 

Function Documentation

§ parseDoubleArray()

vector<double> parseDoubleArray ( const string &  doubleArray)

Definition at line 74 of file LocalMaximumPeakDetectorTest.cpp.

Referenced by test().

75 {
76  vector<double> doubleVector;
77  vector<string> tokens;
78  bal::split(tokens, doubleArray, bal::is_space(), bal::token_compress_on);
79  if (!tokens.empty() && !tokens[0].empty())
80  for (size_t i=0; i < tokens.size(); ++i)
81  doubleVector.push_back(lexical_cast<double>(tokens[i]));
82  return doubleVector;
83 }

§ test()

void test ( )

Definition at line 86 of file LocalMaximumPeakDetectorTest.cpp.

References parseDoubleArray(), testDataSize, unit_assert, unit_assert_equal, TestData::windowSize, TestData::xPeakValues, TestData::xRaw, TestData::yPeakValues, and TestData::yRaw.

Referenced by main().

87 {
88  for (size_t i=0; i < testDataSize; ++i)
89  {
90  const TestData& data = testData[i];
91 
92  vector<double> xRaw = parseDoubleArray(data.xRaw);
93  vector<double> yRaw = parseDoubleArray(data.yRaw);
94  vector<double> target_xPeakValues = parseDoubleArray(data.xPeakValues);
95  vector<double> target_yPeakValues = parseDoubleArray(data.yPeakValues);
96 
97  // sanity checks
98  unit_assert(xRaw.size() == yRaw.size());
99  unit_assert(target_xPeakValues.size() == target_yPeakValues.size());
100 
101  LocalMaximumPeakDetector peakDetector(data.windowSize);
102  vector<double> xPeakValues, yPeakValues;
103  peakDetector.detect(xRaw, yRaw, xPeakValues, yPeakValues);
104 
105  unit_assert(xPeakValues.size() == target_xPeakValues.size());
106 
107  for (size_t j=0; j < xPeakValues.size(); ++j)
108  {
109  unit_assert_equal(xPeakValues[j], target_xPeakValues[j], 1e-5);
110  unit_assert_equal(yPeakValues[j], target_yPeakValues[j], 1e-5);
111  }
112  }
113 }
const char * yRaw
#define unit_assert_equal(x, y, epsilon)
Definition: unit.hpp:99
vector< double > parseDoubleArray(const string &doubleArray)
const TestData testData[]
const size_t testDataSize
const char * xRaw
const char * xPeakValues
const char * yPeakValues
#define unit_assert(x)
Definition: unit.hpp:85

§ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 116 of file LocalMaximumPeakDetectorTest.cpp.

References os_, test(), TEST_EPILOG, TEST_FAILED, and TEST_PROLOG.

117 {
118  TEST_PROLOG(argc, argv)
119 
120  try
121  {
122  if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
123  test();
124  }
125  catch (exception& e)
126  {
127  TEST_FAILED(e.what())
128  }
129  catch (...)
130  {
131  TEST_FAILED("Caught unknown exception.")
132  }
133 
135 }
#define TEST_EPILOG
Definition: unit.hpp:182
#define TEST_FAILED(x)
Definition: unit.hpp:176
#define TEST_PROLOG(argc, argv)
Definition: unit.hpp:174

Variable Documentation

§ os_

ostream* os_ = 0

Definition at line 32 of file LocalMaximumPeakDetectorTest.cpp.

Referenced by main().

§ testData

const TestData testData[]
Initial value:
=
{
{
3,
"1 2 3 4 5 6 7 8 9",
"0 1 0 1 2 3 0 0 4",
"2 6 9",
"1 3 4"
},
{
5,
"1 2 3 4 5 6 7 8 9",
"0 1 0 1 2 3 0 0 4",
"2 6 9",
"1 3 4"
},
{
7,
"1 2 3 4 5 6 7 8 9",
"0 1 0 1 2 3 0 0 4",
"9",
"4"
}
}

Definition at line 44 of file LocalMaximumPeakDetectorTest.cpp.

§ testDataSize

const size_t testDataSize = sizeof(testData) / sizeof(TestData)

Definition at line 71 of file LocalMaximumPeakDetectorTest.cpp.

Referenced by test().