NCBI C++ ToolKit
seqalign_unit_test.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: seqalign_unit_test.cpp 51064 2011-08-30 17:34:10Z mozese2 $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Author: Christiam Camacho, NCBI
27  *
28  * File Description:
29  * Unit tests for the CSeq_align class.
30  *
31  * NOTE:
32  * Boost.Test reports some memory leaks when compiled in MSVC even for this
33  * simple code. Maybe it's related to some toolkit static variables.
34  * To avoid annoying messages about memory leaks run this program with
35  * parameter --detect_memory_leak=0
36  *
37  * ===========================================================================
38  */
39 
40 #include <ncbi_pch.hpp>
41 
42 // This macro should be defined before inclusion of test_boost.hpp in all
43 // "*.cpp" files inside executable except one. It is like function main() for
44 // non-Boost.Test executables is defined only in one *.cpp file - other files
45 // should not include it. If NCBI_BOOST_NO_AUTO_TEST_MAIN will not be defined
46 // then test_boost.hpp will define such "main()" function for tests.
47 //
48 // Usually if your unit tests contain only one *.cpp file you should not
49 // care about this macro at all.
50 //
51 //#undef NCBI_BOOST_NO_AUTO_TEST_MAIN
52 
53 // This header must be included before all Boost.Test headers if there are any
54 #include <corelib/test_boost.hpp>
58 
59 #include <common/test_assert.h> /* This header must go last */
60 
61 
64 
65 
66 BOOST_AUTO_TEST_CASE(TestDenseSegGaps)
67 {
68  const string kFileName("data/blastp_db.asn");
69  ifstream in(kFileName.c_str());
70  CSeq_align_set alignments;
71  in >> MSerial_AsnText >> alignments;
72 
73  // Each element of this vector stores the number of gap openings in the
74  // pair's first field and the total number of gaps in its second field
75  vector< pair<TSeqPos, TSeqPos> > gap_data;
76  gap_data.push_back(make_pair(0U,0U));
77  gap_data.push_back(make_pair(0U,0U));
78  gap_data.push_back(make_pair(1U,2U));
79  gap_data.push_back(make_pair(1U,2U));
80  gap_data.push_back(make_pair(1U,5U));
81  gap_data.push_back(make_pair(1U,5U));
82  gap_data.push_back(make_pair(2U,2U));
83  gap_data.push_back(make_pair(1U,1U));
84  gap_data.push_back(make_pair(1U,1U));
85  gap_data.push_back(make_pair(0U,0U));
86 
87  int index = 0;
88  ITERATE(CSeq_align_set::Tdata, alignment, alignments.Get()) {
89  TSeqPos test_value = (*alignment)->GetNumGapOpenings();
90  BOOST_REQUIRE_EQUAL(gap_data[index].first, test_value);
91  test_value = (*alignment)->GetTotalGapCount();
92  BOOST_REQUIRE_EQUAL(gap_data[index].second, test_value);
93  index++;
94  }
95 }
96 
97 static void s_TestStdSegGaps(void)
98 {
99  const string kFileName("data/tblastn_db.asn");
100  ifstream in(kFileName.c_str());
101  CSeq_align_set alignments;
102  in >> MSerial_AsnText >> alignments;
103 
104  // Each element of this vector stores the number of gap openings in the
105  // pair's first field and the total number of gaps in its second field
106  vector< pair<TSeqPos, TSeqPos> > gap_data;
107  gap_data.push_back(make_pair(0U,0U));
108  gap_data.push_back(make_pair(0U,0U));
109 
110  int index = 0;
111  ITERATE(CSeq_align_set::Tdata, alignment, alignments.Get()) {
112  TSeqPos test_value = (*alignment)->GetNumGapOpenings();
113  BOOST_REQUIRE_EQUAL(gap_data[index].first, test_value);
114  index++;
115  }
116 }
117 
118 BOOST_AUTO_TEST_CASE(TestStdSegGaps)
119 {
121 }
static const char * kFileName
static DLIST_TYPE *DLIST_NAME() first(DLIST_LIST_TYPE *list)
Definition: dlist.tmpl.h:46
unsigned int TSeqPos
Type for sequence locations and lengths.
Definition: ncbimisc.hpp:875
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
#define MSerial_AsnText
I/O stream manipulators –.
Definition: serialbase.hpp:696
list< CRef< CSeq_align > > Tdata
const Tdata & Get(void) const
Get the member data.
std::istream & in(std::istream &in_, double &x_)
USING_SCOPE(objects)
static void s_TestStdSegGaps(void)
BOOST_AUTO_TEST_CASE(TestDenseSegGaps)
USING_NCBI_SCOPE
Utility stuff for more convenient using of Boost.Test library.
Modified on Sat Apr 20 12:14:46 2024 by modify_doxy.py rev. 669887