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

Go to the SVN repository for this file.

1 /* $Id: links_unit_test.cpp 46598 2010-07-23 13:56:44Z boratyng $
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: Greg Boratyn
27 *
28 * File Description:
29 * Unit tests for CLinks class
30 *
31 *
32 * ===========================================================================
33 */
34 
35 #include <ncbi_pch.hpp>
36 
37 #include <algo/cobalt/links.hpp>
38 
39 // This macro should be defined before inclusion of test_boost.hpp in all
40 // "*.cpp" files inside executable except one. It is like function main() for
41 // non-Boost.Test executables is defined only in one *.cpp file - other files
42 // should not include it. If NCBI_BOOST_NO_AUTO_TEST_MAIN will not be defined
43 // then test_boost.hpp will define such "main()" function for tests.
44 //
45 // Usually if your unit tests contain only one *.cpp file you should not
46 // care about this macro at all.
47 //
48 #undef NCBI_BOOST_NO_AUTO_TEST_MAIN
49 
50 
51 // This header must be included before all Boost.Test headers if there are any
52 #include <corelib/test_boost.hpp>
53 
54 #ifndef SKIP_DOXYGEN_PROCESSING
55 
57 USING_SCOPE(cobalt);
58 
60 
62 {
63  const int kNumElements = 10;
64 
65  CLinks links(kNumElements);
66 
67  // adding link with node that has index larger than number of elements
68  // causes expection
69  BOOST_REQUIRE_THROW(links.AddLink(0, kNumElements + 1, 0.0),
71 }
72 
74 {
75  const int kNumElements = 10;
76  const double kSmallerWeight = 0.0;
77  const double kLargerWeight = 0.3;
78 
79  CLinks links(kNumElements);
80 
81  BOOST_REQUIRE(kSmallerWeight < kLargerWeight);
82 
83  links.AddLink(0, 1, kSmallerWeight);
84  links.AddLink(1, 2, kLargerWeight);
85  links.AddLink(1, 3, kLargerWeight + 0.1);
86 
87  links.Sort();
88  CLinks::SLink_CI first_it = links.begin();
89  CLinks::SLink_CI second_it = first_it;
90  ++second_it;
91 
92  // links must be sorted in ascending order accoring to weights
93  BOOST_REQUIRE(first_it->weight < second_it->weight);
94 }
95 
96 BOOST_AUTO_TEST_CASE(TestIsSorted)
97 {
98  const int kNumElements = 10;
99 
100  CLinks links(kNumElements);
101 
102  // initially links must be unsorted
103  BOOST_REQUIRE(!links.IsSorted());
104  links.AddLink(0, 1, 0.0);
105  BOOST_REQUIRE(!links.IsSorted());
106 
107  // afetr sorting links must be reported as sorted
108  links.Sort();
109  BOOST_REQUIRE(links.IsSorted());
110 
111  // after sorting and adding another link, links must be unsorted
112  links.AddLink(0, 2, 0.0);
113  BOOST_REQUIRE(!links.IsSorted());
114 }
115 
117 {
118  const int kNumElements = 10;
119 
120  CLinks links(kNumElements);
121  links.AddLink(1, 0, 0.0);
122 
123  // links must be sorted before check can be made
124  BOOST_CHECK_THROW(links.IsLink(0, 1), CLinksException);
125 
126  links.Sort();
127 
128  // existent link
129  BOOST_REQUIRE(links.IsLink(0, 1));
130  // links are undirected
131  BOOST_REQUIRE(links.IsLink(1, 0));
132 
133  // non existent link
134  BOOST_REQUIRE(!links.IsLink(1, 2));
135  BOOST_REQUIRE(!links.IsLink(2, 1));
136 }
137 
139 
140 #endif /* SKIP_DOXYGEN_PROCESSING */
BOOST_AUTO_TEST_SUITE_END() static int s_GetSegmentFlags(const CBioseq &bioseq)
Exceptions for CLinks class.
Definition: links.hpp:199
BOOST_AUTO_TEST_SUITE(psiblast_iteration)
Utility stuff for more convenient using of Boost.Test library.
Modified on Tue May 28 05:51:19 2024 by modify_doxy.py rev. 669887