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

typedef shared_ptr<Simple> SimplePtr

Definition at line 112 of file MZRTFieldTest.cpp.


Function Documentation

void testPredicate ( )

Definition at line 39 of file MZRTFieldTest.cpp.

References os_, and unit_assert.

Referenced by test().

{
if (os_) *os_ << "testPredicate()\n";
PeakelPtr a(new Peakel(Peak(1.0, 1.0)));
PeakelPtr b(new Peakel(Peak(2.0, 1.0)));
PeakelPtr c(new Peakel(Peak(1.0, 2.0)));
LessThan_MZRT<Peakel> lt;
// a < c < b
unit_assert(lt(*a,*b));
unit_assert(lt(a,b));
unit_assert(!lt(b,a));
unit_assert(lt(a,c));
unit_assert(!lt(c,a));
unit_assert(lt(c,b));
unit_assert(!lt(b,c));
unit_assert(!lt(a,a));
}
void testPredicate_Feature ( )

Definition at line 63 of file MZRTFieldTest.cpp.

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

Referenced by test().

{
Feature a,b;
a.mz = 1;
b.mz = 2;
LessThan_MZRT<Feature> lt;
unit_assert(lt(a,b));
unit_assert(!lt(b,a));
unit_assert(!lt(a,a));
}
void testConceptChecking ( )

Definition at line 89 of file MZRTFieldTest.cpp.

Referenced by test().

{
MZRTField<Goober> gooberField;
}
void testFind ( )

Definition at line 115 of file MZRTFieldTest.cpp.

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

{
// rt\mz 400 410 420 430 440
// 660 a c
// 661 a c
// 662 c
// 663
// 664 b
// 665 b d
// 666 b d
// 667 b d
// 668 b
// 669
SimplePtr a(new Simple(400, 660, 661));
SimplePtr b(new Simple(400, 664, 668));
SimplePtr c(new Simple(420, 660, 662));
SimplePtr d(new Simple(420, 665, 667));
MZRTField<Simple> simpleField;
simpleField.insert(a);
simpleField.insert(b);
simpleField.insert(c);
simpleField.insert(d);
vector<SimplePtr> result = simpleField.find(420, 1, RTMatches_Any<Simple>());
unit_assert(result.size()==2 && result[0]==c && result[1]==d);
result = simpleField.find(410, 11, RTMatches_Contains<Simple>(666,0));
unit_assert(result.size()==2 && result[0]==b && result[1]==d);
result = simpleField.find(420, 1, RTMatches_IsContainedIn<Simple>(*b));
unit_assert(result.size()==1 && result[0]==d);
result = simpleField.find(400, 1, RTMatches_IsContainedIn<Simple>(*d, 1.5));
unit_assert(result.size()==1 && result[0]==b);
}
void testPeakelField ( )

Definition at line 154 of file MZRTFieldTest.cpp.

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

Referenced by test().

{
if (os_) *os_ << "testPeakelField()\n";
PeakelPtr a(new Peakel(Peak(1.0, 1.0)));
PeakelPtr b(new Peakel(Peak(2.0, 1.0)));
PeakelPtr c(new Peakel(Peak(1.0, 2.0)));
pf.insert(a);
pf.insert(b);
pf.insert(c);
if (os_) *os_ << pf << endl;
unit_assert(pf.size() == 3);
PeakelField::const_iterator it = pf.begin();
unit_assert(*it == a);
// note that std::set allows only const access
// however, we can modify **it
(*it)->peaks.push_back(Peak());
(*it)->peaks.clear();
++it;
unit_assert(*it == c);
++it;
unit_assert(*it == b);
// find()
if (os_) *os_ << "testPeakelField(): find()\n";
vector<PeakelPtr> v = pf.find(1.5, .6, RTMatches_Contains<Peakel>(1, .5));
if (os_)
{
*os_ << "find(): " << v.size() << endl;
for (vector<PeakelPtr>::const_iterator it=v.begin(); it!=v.end(); ++it)
*os_ << **it << endl;
}
unit_assert(v.size()==2 && v[0]==a && v[1]==b);
v = pf.find(1.5, .4, RTMatches_Contains<Peakel>(1, .5));
unit_assert(v.empty());
v = pf.find(2, .1, RTMatches_Contains<Peakel>(1, .1));
unit_assert(v.size()==1 && v[0]==b);
MZTolerance fiveppm(5, MZTolerance::PPM);
v = pf.find(1.000001, fiveppm, RTMatches_Contains<Peakel>(1, 10));
unit_assert(v.size()==2 && v[0]==a && v[1]==c);
v = pf.find(1.000006, fiveppm, RTMatches_Contains<Peakel>(1, 10));
unit_assert(v.empty());
// remove()
if (os_) *os_ << "testPeakelField(): remove()\n";
pf.remove(a);
unit_assert(pf.size() == 2);
it = pf.begin();
unit_assert(*it == c);
++it;
unit_assert(*it == b);
bool caught = false;
try {
pf.remove(a);
}
catch (exception& e) {
if (os_) *os_ << "Caught exception correctly: " << e.what() << endl;
caught = true;
}
unit_assert(caught);
pf.remove(b);
unit_assert(pf.size() == 1);
it = pf.begin();
unit_assert(*it == c);
pf.remove(c);
unit_assert(pf.empty());
if (os_) *os_ << endl;
}
void testFeatureField ( )

Definition at line 253 of file MZRTFieldTest.cpp.

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

Referenced by test().

{
if (os_) *os_ << "testFeatureField()\n";
a->mz=1; a->retentionTime=1;
b->mz=2; b->retentionTime=1;
c->mz=1; c->retentionTime=2;
ff.insert(a);
ff.insert(b);
ff.insert(c);
if (os_) *os_ << ff << endl;
MZTolerance fiveppm(5, MZTolerance::PPM);
vector<FeaturePtr> v = ff.find(1.000001, fiveppm, RTMatches_Contains<Feature>(1, 10));
unit_assert(v.size()==2 && v[0]==a && v[1]==c);
v = ff.find(1.000006, fiveppm, RTMatches_Contains<Feature>(1, 10));
unit_assert(v.empty());
}
void test ( )
int main ( int  argc,
char *  argv[] 
)

Definition at line 293 of file MZRTFieldTest.cpp.

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

{
TEST_PROLOG(argc, argv)
try
{
if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
test();
}
catch (exception& e)
{
TEST_FAILED(e.what())
}
catch (...)
{
TEST_FAILED("Caught unknown exception.")
}
}

Variable Documentation

ostream* os_ = 0

Definition at line 36 of file MZRTFieldTest.cpp.