ProteoWizard
Classes | Typedefs | Functions | Variables
MZRTFieldTest.cpp File Reference
#include "MZRTField.hpp"
#include "pwiz/utility/misc/unit.hpp"
#include "pwiz/utility/misc/Std.hpp"
#include <cstring>

Go to the source code of this file.

Classes

struct  Goober
 
struct  Simple
 
struct  MyPred
 

Typedefs

typedef shared_ptr< SimpleSimplePtr
 

Functions

void testPredicate ()
 
void testPredicate_Feature ()
 
void testConceptChecking ()
 
void testFind ()
 
void testPeakelField ()
 
void testFeatureField ()
 
void test ()
 
int main (int argc, char *argv[])
 

Variables

ostream * os_ = 0
 

Typedef Documentation

§ SimplePtr

typedef shared_ptr<Simple> SimplePtr

Definition at line 112 of file MZRTFieldTest.cpp.

Function Documentation

§ testPredicate()

void testPredicate ( )

Definition at line 39 of file MZRTFieldTest.cpp.

References os_, and unit_assert.

Referenced by test().

40 {
41  if (os_) *os_ << "testPredicate()\n";
42 
43  PeakelPtr a(new Peakel(Peak(1.0, 1.0)));
44  PeakelPtr b(new Peakel(Peak(2.0, 1.0)));
45  PeakelPtr c(new Peakel(Peak(1.0, 2.0)));
46 
47  LessThan_MZRT<Peakel> lt;
48 
49  // a < c < b
50 
51  unit_assert(lt(*a,*b));
52  unit_assert(lt(a,b));
53  unit_assert(!lt(b,a));
54  unit_assert(lt(a,c));
55  unit_assert(!lt(c,a));
56  unit_assert(lt(c,b));
57  unit_assert(!lt(b,c));
58 
59  unit_assert(!lt(a,a));
60 }
boost::shared_ptr< Peakel > PeakelPtr
Definition: PeakData.hpp:242
ostream * os_
represents some generic metadata about a peak detected in a signal
struct for an eluted peak (PEAK ELution)
Definition: PeakData.hpp:211
#define unit_assert(x)
Definition: unit.hpp:85

§ testPredicate_Feature()

void testPredicate_Feature ( )

Definition at line 63 of file MZRTFieldTest.cpp.

References pwiz::data::peakdata::Feature::mz, and unit_assert.

Referenced by test().

64 {
65  Feature a,b;
66  a.mz = 1;
67  b.mz = 2;
68 
69  LessThan_MZRT<Feature> lt;
70  unit_assert(lt(a,b));
71  unit_assert(!lt(b,a));
72  unit_assert(!lt(a,a));
73 }
#define unit_assert(x)
Definition: unit.hpp:85

§ testConceptChecking()

void testConceptChecking ( )

Definition at line 89 of file MZRTFieldTest.cpp.

Referenced by test().

90 {
91  MZRTField<Goober> gooberField;
92 }
MZRTField is a std::set of boost::shared_ptrs, stored as a binary tree ordered by LessThan_MZRT...
Definition: MZRTField.hpp:94

§ testFind()

void testFind ( )

Definition at line 115 of file MZRTFieldTest.cpp.

References pwiz::analysis::MZRTField< T >::find(), and unit_assert.

Referenced by test().

116 {
117  // rt\mz 400 410 420 430 440
118  // 660 a c
119  // 661 a c
120  // 662 c
121  // 663
122  // 664 b
123  // 665 b d
124  // 666 b d
125  // 667 b d
126  // 668 b
127  // 669
128 
129  SimplePtr a(new Simple(400, 660, 661));
130  SimplePtr b(new Simple(400, 664, 668));
131  SimplePtr c(new Simple(420, 660, 662));
132  SimplePtr d(new Simple(420, 665, 667));
133 
134  MZRTField<Simple> simpleField;
135  simpleField.insert(a);
136  simpleField.insert(b);
137  simpleField.insert(c);
138  simpleField.insert(d);
139 
140  vector<SimplePtr> result = simpleField.find(420, 1, RTMatches_Any<Simple>());
141  unit_assert(result.size()==2 && result[0]==c && result[1]==d);
142 
143  result = simpleField.find(410, 11, RTMatches_Contains<Simple>(666,0));
144  unit_assert(result.size()==2 && result[0]==b && result[1]==d);
145 
146  result = simpleField.find(420, 1, RTMatches_IsContainedIn<Simple>(*b));
147  unit_assert(result.size()==1 && result[0]==d);
148 
149  result = simpleField.find(400, 1, RTMatches_IsContainedIn<Simple>(*d, 1.5));
150  unit_assert(result.size()==1 && result[0]==b);
151 }
predicate always returns true
Definition: MZRTField.hpp:121
MZRTField is a std::set of boost::shared_ptrs, stored as a binary tree ordered by LessThan_MZRT...
Definition: MZRTField.hpp:94
predicate returns true iff the object&#39;s retention time range contains the specified retention time ...
Definition: MZRTField.hpp:130
shared_ptr< Simple > SimplePtr
std::vector< TPtr > find(double mz, MZTolerance mzTolerance, RTMatches matches) const
find all objects with a given m/z, within a given m/z tolerance, satisfying the &#39;matches&#39; predicate ...
#define unit_assert(x)
Definition: unit.hpp:85
predicate returns true iff the object&#39;s retention time range is completely contained within the range...
Definition: MZRTField.hpp:148

§ testPeakelField()

void testPeakelField ( )

Definition at line 154 of file MZRTFieldTest.cpp.

References pwiz::analysis::MZRTField< T >::find(), os_, pwiz::analysis::MZRTField< T >::remove(), and unit_assert.

Referenced by test().

155 {
156  if (os_) *os_ << "testPeakelField()\n";
157 
158  PeakelPtr a(new Peakel(Peak(1.0, 1.0)));
159  PeakelPtr b(new Peakel(Peak(2.0, 1.0)));
160  PeakelPtr c(new Peakel(Peak(1.0, 2.0)));
161 
162  PeakelField pf;
163 
164  pf.insert(a);
165  pf.insert(b);
166  pf.insert(c);
167 
168  if (os_) *os_ << pf << endl;
169 
170  unit_assert(pf.size() == 3);
171 
172  PeakelField::const_iterator it = pf.begin();
173  unit_assert(*it == a);
174 
175  // note that std::set allows only const access
176  // however, we can modify **it
177  (*it)->peaks.push_back(Peak());
178  (*it)->peaks.clear();
179 
180  ++it;
181  unit_assert(*it == c);
182 
183  ++it;
184  unit_assert(*it == b);
185 
186  // find()
187 
188  if (os_) *os_ << "testPeakelField(): find()\n";
189 
190  vector<PeakelPtr> v = pf.find(1.5, .6, RTMatches_Contains<Peakel>(1, .5));
191 
192  if (os_)
193  {
194  *os_ << "find(): " << v.size() << endl;
195  for (vector<PeakelPtr>::const_iterator it=v.begin(); it!=v.end(); ++it)
196  *os_ << **it << endl;
197  }
198 
199  unit_assert(v.size()==2 && v[0]==a && v[1]==b);
200  v = pf.find(1.5, .4, RTMatches_Contains<Peakel>(1, .5));
201  unit_assert(v.empty());
202  v = pf.find(2, .1, RTMatches_Contains<Peakel>(1, .1));
203  unit_assert(v.size()==1 && v[0]==b);
204 
205  MZTolerance fiveppm(5, MZTolerance::PPM);
206  v = pf.find(1.000001, fiveppm, RTMatches_Contains<Peakel>(1, 10));
207  unit_assert(v.size()==2 && v[0]==a && v[1]==c);
208  v = pf.find(1.000006, fiveppm, RTMatches_Contains<Peakel>(1, 10));
209  unit_assert(v.empty());
210 
211  // remove()
212 
213  if (os_) *os_ << "testPeakelField(): remove()\n";
214 
215  pf.remove(a);
216  unit_assert(pf.size() == 2);
217  it = pf.begin();
218  unit_assert(*it == c);
219  ++it;
220  unit_assert(*it == b);
221 
222  bool caught = false;
223  try {
224  pf.remove(a);
225  }
226  catch (exception& e) {
227  if (os_) *os_ << "Caught exception correctly: " << e.what() << endl;
228  caught = true;
229  }
230  unit_assert(caught);
231 
232  pf.remove(b);
233  unit_assert(pf.size() == 1);
234  it = pf.begin();
235  unit_assert(*it == c);
236 
237  pf.remove(c);
238  unit_assert(pf.empty());
239 
240  if (os_) *os_ << endl;
241 }
MZRTField is a std::set of boost::shared_ptrs, stored as a binary tree ordered by LessThan_MZRT...
Definition: MZRTField.hpp:94
predicate returns true iff the object&#39;s retention time range contains the specified retention time ...
Definition: MZRTField.hpp:130
std::vector< TPtr > find(double mz, MZTolerance mzTolerance, RTMatches matches) const
find all objects with a given m/z, within a given m/z tolerance, satisfying the &#39;matches&#39; predicate ...
boost::shared_ptr< Peakel > PeakelPtr
Definition: PeakData.hpp:242
void remove(const TPtr &p)
remove an object via a shared reference, rather than an iterator into the set
Definition: MZRTField.hpp:193
ostream * os_
represents some generic metadata about a peak detected in a signal
struct for an eluted peak (PEAK ELution)
Definition: PeakData.hpp:211
struct for expressing m/z tolerance in either amu or ppm
Definition: MZTolerance.hpp:38
#define unit_assert(x)
Definition: unit.hpp:85

§ testFeatureField()

void testFeatureField ( )

Definition at line 253 of file MZRTFieldTest.cpp.

References pwiz::analysis::MZRTField< T >::find(), os_, and unit_assert.

Referenced by test().

254 {
255  if (os_) *os_ << "testFeatureField()\n";
256 
257  FeatureField ff;
258 
259  FeaturePtr a(new Feature);
260  a->mz=1; a->retentionTime=1;
261 
262  FeaturePtr b(new Feature);
263  b->mz=2; b->retentionTime=1;
264 
265  FeaturePtr c(new Feature);
266  c->mz=1; c->retentionTime=2;
267 
268  ff.insert(a);
269  ff.insert(b);
270  ff.insert(c);
271 
272  if (os_) *os_ << ff << endl;
273 
274  MZTolerance fiveppm(5, MZTolerance::PPM);
275  vector<FeaturePtr> v = ff.find(1.000001, fiveppm, RTMatches_Contains<Feature>(1, 10));
276  unit_assert(v.size()==2 && v[0]==a && v[1]==c);
277  v = ff.find(1.000006, fiveppm, RTMatches_Contains<Feature>(1, 10));
278  unit_assert(v.empty());
279 }
MZRTField is a std::set of boost::shared_ptrs, stored as a binary tree ordered by LessThan_MZRT...
Definition: MZRTField.hpp:94
predicate returns true iff the object&#39;s retention time range contains the specified retention time ...
Definition: MZRTField.hpp:130
std::vector< TPtr > find(double mz, MZTolerance mzTolerance, RTMatches matches) const
find all objects with a given m/z, within a given m/z tolerance, satisfying the &#39;matches&#39; predicate ...
boost::shared_ptr< Feature > FeaturePtr
Definition: PeakData.hpp:292
ostream * os_
struct for expressing m/z tolerance in either amu or ppm
Definition: MZTolerance.hpp:38
#define unit_assert(x)
Definition: unit.hpp:85

§ test()

void test ( )

Definition at line 282 of file MZRTFieldTest.cpp.

References testConceptChecking(), testFeatureField(), testFind(), testPeakelField(), testPredicate(), and testPredicate_Feature().

Referenced by main().

283 {
284  testPredicate();
287  testFind();
288  testPeakelField();
290 }
void testConceptChecking()
void testFind()
void testFeatureField()
void testPredicate_Feature()
void testPeakelField()
void testPredicate()

§ main()

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

Definition at line 293 of file MZRTFieldTest.cpp.

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

294 {
295  TEST_PROLOG(argc, argv)
296 
297  try
298  {
299  if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
300  test();
301  }
302  catch (exception& e)
303  {
304  TEST_FAILED(e.what())
305  }
306  catch (...)
307  {
308  TEST_FAILED("Caught unknown exception.")
309  }
310 
312 }
void test()
#define TEST_EPILOG
Definition: unit.hpp:182
ostream * os_
#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 36 of file MZRTFieldTest.cpp.

Referenced by main(), testFeatureField(), testPeakelField(), and testPredicate().