ProteoWizard
Classes | Functions | Variables
CwtPeakDetectorTest.cpp File Reference
#include "CwtPeakDetector.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 102 of file CwtPeakDetectorTest.cpp.

Referenced by test().

103 {
104  vector<double> doubleVector;
105  vector<string> tokens;
106  bal::split(tokens, doubleArray, bal::is_space(), bal::token_compress_on);
107  if (!tokens.empty() && !tokens[0].empty())
108  for (size_t i=0; i < tokens.size(); ++i)
109  doubleVector.push_back(lexical_cast<double>(tokens[i]));
110  return doubleVector;
111 }

§ test()

void test ( )

Definition at line 114 of file CwtPeakDetectorTest.cpp.

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

Referenced by main().

115 {
116  for (size_t i=0; i < testDataSize; ++i)
117  {
118  const TestData& data = testData[i];
119 
120  vector<double> xRaw = parseDoubleArray(data.xRaw);
121  vector<double> yRaw = parseDoubleArray(data.yRaw);
122  vector<double> target_xPeakValues = parseDoubleArray(data.xPeakValues);
123  vector<double> target_yPeakValues = parseDoubleArray(data.yPeakValues);
124 
125  // sanity checks
126  unit_assert(xRaw.size() == yRaw.size());
127  unit_assert(target_xPeakValues.size() == target_yPeakValues.size());
128 
129  CwtPeakDetector peakDetector(1.0,0,0.01);
130  vector<double> xPeakValues, yPeakValues;
131  peakDetector.detect(xRaw, yRaw, xPeakValues, yPeakValues);
132 
133  unit_assert(xPeakValues.size() == target_xPeakValues.size());
134 
135  for (size_t j=0; j < xPeakValues.size(); ++j)
136  {
137  unit_assert_equal(xPeakValues[j], target_xPeakValues[j], 1e-5);
138  unit_assert_equal(yPeakValues[j], target_yPeakValues[j], 1e-5);
139  }
140  }
141 }
const size_t testDataSize
const char * yRaw
#define unit_assert_equal(x, y, epsilon)
Definition: unit.hpp:99
vector< double > parseDoubleArray(const string &doubleArray)
const char * xRaw
const TestData testData[]
const char * xPeakValues
const char * yPeakValues
#define unit_assert(x)
Definition: unit.hpp:85

§ main()

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

Definition at line 144 of file CwtPeakDetectorTest.cpp.

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

145 {
146  TEST_PROLOG(argc, argv)
147 
148  try
149  {
150  if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
151  test();
152  }
153  catch (exception& e)
154  {
155  TEST_FAILED(e.what())
156  }
157  catch (...)
158  {
159  TEST_FAILED("Caught unknown exception.")
160  }
161 
163 }
ostream * os_
#define TEST_EPILOG
Definition: unit.hpp:182
void test()
#define TEST_FAILED(x)
Definition: unit.hpp:176
#define TEST_PROLOG(argc, argv)
Definition: unit.hpp:174

Variable Documentation

§ os_

ostream* os_ = 0

§ testData

const TestData testData[]

Definition at line 43 of file CwtPeakDetectorTest.cpp.

§ testDataSize

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

Definition at line 99 of file CwtPeakDetectorTest.cpp.

Referenced by test().