void testToyExample()
{
    vector< vector<Peak> > peaks = createToyPeaks();

    PeakelGrower_Proximity::Config config;
    config.mzTolerance = .1;
    config.rtTolerance = 1.5;

    PeakelGrower_Proximity peakelGrower(config);

    PeakelField field;
    peakelGrower.sowPeaks(field, peaks);

    const double epsilon = .1;
    unit_assert(field.size() == 4);

    PeakelField::const_iterator it = field.begin();

    unit_assert_equal((*it)->mz, 1000, epsilon);
    unit_assert_equal((*it)->retentionTime, 0, epsilon);

    ++it;
    unit_assert_equal((*it)->mz, 1000, epsilon);
    unit_assert_equal((*it)->retentionTime, 3, epsilon);
    
    ++it;
    unit_assert_equal((*it)->mz, 1001, epsilon);
    unit_assert_equal((*it)->retentionTime, 1, epsilon);
    
    ++it;
    unit_assert_equal((*it)->mz, 1002, epsilon);
    unit_assert_equal((*it)->retentionTime, 0, epsilon);
}
Esempio n. 2
0
void testPeakelField()
{
    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)));

    PeakelField pf;

    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;
}