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.

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}
ostream * os_
boost::shared_ptr< Peakel > PeakelPtr
Definition PeakData.hpp:242
represents some generic metadata about a peak detected in a signal
struct for an eluted peak (PEAK ELution)
Definition PeakData.hpp:212
#define unit_assert(x)
Definition unit.hpp:85

References os_, and unit_assert.

Referenced by test().

◆ testPredicate_Feature()

void testPredicate_Feature ( )

Definition at line 63 of file MZRTFieldTest.cpp.

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}

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

Referenced by test().

◆ testConceptChecking()

void testConceptChecking ( )

Definition at line 89 of file MZRTFieldTest.cpp.

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:95

Referenced by test().

◆ testFind()

void testFind ( )

Definition at line 115 of file MZRTFieldTest.cpp.

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}
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 'matches' predicate
predicate always returns true
predicate returns true iff the object's retention time range contains the specified retention time
predicate returns true iff the object's retention time range is completely contained within the range...

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

Referenced by test().

◆ testPeakelField()

void testPeakelField ( )

Definition at line 154 of file MZRTFieldTest.cpp.

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}
void remove(const TPtr &p)
remove an object via a shared reference, rather than an iterator into the set
struct for expressing m/z tolerance in either amu or ppm

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

Referenced by test().

◆ testFeatureField()

void testFeatureField ( )

Definition at line 253 of file MZRTFieldTest.cpp.

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}
boost::shared_ptr< Feature > FeaturePtr
Definition PeakData.hpp:292

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

Referenced by test().

◆ test()

void test ( )

Definition at line 282 of file MZRTFieldTest.cpp.

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

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

Referenced by main().

◆ main()

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

Definition at line 293 of file MZRTFieldTest.cpp.

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:183
#define TEST_FAILED(x)
Definition unit.hpp:177
#define TEST_PROLOG(argc, argv)
Definition unit.hpp:175

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

Variable Documentation

◆ os_

ostream* os_ = 0

Definition at line 36 of file MZRTFieldTest.cpp.

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