test_seqvector_ci.cpp

来自「ncbi源码」· C++ 代码 · 共 528 行 · 第 1/2 页

CPP
528
字号
    CScope scope(*m_OM);    scope.AddDefaults();    CSeq_id id;    id.SetGi(gi);    CBioseq_Handle handle = scope.GetBioseqHandle(id);    // Check if the handle is valid    if ( !handle ) {        cout << "Can not find gi " << gi << endl;        return 0;    }    // Create seq-vector    m_Vect = handle.GetSeqVector(CBioseq_Handle::eCoding_Iupac);    // Prepare reference data    m_Vect.GetSeqData(0, m_Vect.size(), m_RefBuf);    CSeqVector_CI vit = CSeqVector_CI(m_Vect);    string buf;    // start > stop test    cout << "Testing empty range (start > stop)... ";    vit.GetSeqData(m_Vect.size(), 0, buf);    if (buf.size() != 0) {        cout << endl << "ERROR: Test failed -- got non-empty data" << endl;        throw runtime_error("Empty range test failed");    }    cout << "OK" << endl;    // stop > length test    cout << "Testing past-end read (stop > size)... ";    vit.GetSeqData(        max<TSeqPos>(m_Vect.size(), 100) - 100, m_Vect.size() + 1, buf);    if ( !x_CheckBuf(buf, max<TSeqPos>(m_Vect.size(), 100) - 100, 100) ) {        cout << "ERROR: GetSeqData() failed -- invalid data" << endl;        throw runtime_error("Past-end read test failed");    }    cout << "OK" << endl;    buf = ""; // .erase();    // Compare iterator with GetSeqData()    // Not using x_TestIterate() to also check operator bool()    cout << "Testing basic iterator... ";    const char* data = m_RefBuf.data();    const char* c = data;    const char* data_end = data + m_RefBuf.size();    for (vit.SetPos(0); vit; ++vit, ++c) {        if (c == data_end ||  *vit != *c) {            cout << "ERROR: Invalid data at " << vit.GetPos() << endl;            throw runtime_error("Basic iterator test failed");        }    }    if (c != data_end) {        cout << "ERROR: Invalid data length" << endl;        throw runtime_error("Basic iterator test failed");    }    cout << "OK" << endl;    // Partial retrieval with GetSeqData() test, limit to 2000 bases    cout << "Testing partial retrieval... ";    for (unsigned i = max<int>(1, m_Vect.size() / 2 - 2000);         i <= m_Vect.size() / 2; ++i) {        x_TestGetData(vit, i, m_Vect.size() - i);    }    cout << "OK" << endl;    // Butterfly test    cout << "Testing butterfly reading... ";    for (unsigned i = 1; i < m_Vect.size() / 2; ++i) {        if (m_Vect[i] != data[i]) {            cout << "ERROR: Butterfly test failed at position " << i << endl;            throw runtime_error("Butterfly read test failed");        }    }    cout << "OK" << endl;    TSeqPos pos1 = 0;    TSeqPos pos2 = 0;    TSeqPos pos3 = 0;    TSeqPos pos4 = 0;    {{        const CSeqMap& smap = handle.GetSeqMap();        CSeqMap_CI map_it = smap.begin_resolved(&scope);        if ( map_it ) {            // Should happen for any non-empty sequence            pos2 = map_it.GetEndPosition();            ++map_it;            if ( map_it ) {                // Should happen for most segmented sequences                pos3 = map_it.GetEndPosition();                ++map_it;                if ( map_it ) {                    // May happen for some segmented sequences                    pos4 = map_it.GetEndPosition();                }            }        }    }}    // ========= Iterator tests ==========    cout << "Testing iterator - single segment... ";    // Single segment test, start from the middle of the first segment    vit = CSeqVector_CI(m_Vect, (pos1 + pos2) / 2);    // Back to the first segment start    x_TestIterate(vit, kInvalidSeqPos, pos1);    // Forward to the first segment end    x_TestIterate(vit, kInvalidSeqPos, pos2);    // Back to the first segment start again    x_TestIterate(vit, kInvalidSeqPos, pos1);    cout << "OK" << endl;    // Try to run multi-segment tests    if ( pos3 ) {        cout << "Testing iterator - multiple segments... ";        // Start from the middle of the second segment        vit = CSeqVector_CI(m_Vect, (pos2 + pos3) / 2);        // Back to the first segment start        x_TestIterate(vit, kInvalidSeqPos, pos1);        // Forward to the second or third segment end        x_TestIterate(vit, kInvalidSeqPos, pos4 ? pos4 : pos3);        // Back to the first segment start again        x_TestIterate(vit, kInvalidSeqPos, pos1);        cout << "OK" << endl;    }    // ========= GetSeqData() tests ==========    cout << "Testing GetSeqData() - single segment... ";    // Single segment test, start from the middle of the first segment    vit = CSeqVector_CI(m_Vect, (pos1 + pos2) / 2);    // Back to the first segment start    x_TestGetData(vit, kInvalidSeqPos, pos1);    // Forward to the first segment end    x_TestGetData(vit, kInvalidSeqPos, pos2);    // Back to the first segment start again    x_TestGetData(vit, kInvalidSeqPos, pos1);    cout << "OK" << endl;    // Try to run multi-segment tests    if ( pos3 ) {        cout << "Testing GetSeqData() - multiple segments... ";        // Start from the middle of the second segment        vit = CSeqVector_CI(m_Vect, (pos2 + pos3) / 2);        // Back to the first segment start        x_TestGetData(vit, kInvalidSeqPos, pos1);        // Forward to the second or third segment end        x_TestGetData(vit, kInvalidSeqPos, pos4 ? pos4 : pos3);        // Back to the first segment start again        x_TestGetData(vit, kInvalidSeqPos, pos1);        cout << "OK" << endl;    }    // ========= CSeqVector[] tests ==========    cout << "Testing operator[] - single segment... ";    // Single segment test, start from the middle of the first segment    // Back to the first segment start    x_TestVector((pos1 + pos2) / 2, pos1);    // Forward to the first segment end    x_TestVector(pos1, pos2);    // Back to the first segment start again    x_TestVector(pos2, pos1);    cout << "OK" << endl;    // Try to run multi-segment tests    if ( pos3 ) {        cout << "Testing operator[] - multiple segments... ";        // Start from the middle of the second segment        // Back to the first segment start        x_TestVector((pos2 + pos3) / 2, pos1);        // Forward to the second or third segment end        x_TestVector(pos1, pos4 ? pos4 : pos3);        // Back to the first segment start again        x_TestVector(pos4 ? pos4 : pos3, pos1);        cout << "OK" << endl;    }    // Random access tests    cout << "Testing random access" << endl;    unsigned int rseed = args["seed"].AsInteger();    int cycles = args["cycles"].AsInteger();    if (rseed == 0) {        rseed = (unsigned)time( NULL );    }    cout << "Testing random reading (seed: " << rseed         << ", cycles: " << cycles << ")... " << endl;    CRandom random(rseed);    vit = CSeqVector_CI(m_Vect);    for (int i = 0; i < cycles; ++i) {        TSeqPos start = random.GetRand(0, m_Vect.size());        TSeqPos stop = random.GetRand(0, m_Vect.size());        switch (i % 3) {        case 0:            x_TestIterate(vit, start, stop);            break;        case 1:            x_TestGetData(vit, start, stop);            break;        case 2:            x_TestVector(start, stop);            break;        }    }    cout << "OK" << endl;    NcbiCout << "All tests passed" << NcbiEndl;    return 0;}END_NCBI_SCOPE///////////////////////////////////////////////////////////////////////////////  MAINUSING_NCBI_SCOPE;int main(int argc, const char* argv[]){    return CTestApp().AppMain(argc, argv);}/** ---------------------------------------------------------------------------* $Log: test_seqvector_ci.cpp,v $* Revision 1000.1  2004/06/01 19:42:39  gouriano* PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.2** Revision 1.2  2004/05/21 21:42:52  gorelenk* Added PCH ncbi_pch.hpp** Revision 1.1  2003/12/16 17:51:23  kuznets* Code reorganization** Revision 1.6  2003/11/12 20:16:15  vasilche* Fixed error: Attempt to delete Object Manager with open scopes.** Revision 1.5  2003/08/29 13:34:48  vasilche* Rewrote CSeqVector/CSeqVector_CI code to allow better inlining.* CSeqVector::operator[] made significantly faster.* Added possibility to have platform dependent byte unpacking functions.** Revision 1.4  2003/08/06 20:51:54  grichenk* Use CRandom class** Revision 1.3  2003/07/09 18:49:33  grichenk* Added arguments (seed and cycles), default random cycles set to 20.** Revision 1.2  2003/06/26 17:02:52  grichenk* Simplified output, decreased number of cycles.** Revision 1.1  2003/06/24 19:50:02  grichenk* Added test for CSeqVector_CI*** ===========================================================================*/

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?