define window for showing a mussa alignment
[mussa.git] / alg / test / test_conserved_path.cpp
1 #include <boost/test/auto_unit_test.hpp>
2 #include <boost/assign/std/vector.hpp>
3 using namespace boost::assign;
4
5 #include <vector>
6 using namespace std;
7
8 #include "alg/conserved_path.hpp"
9
10 //! write tests for our conserved path types (just to make sure they
11 //! don't change on us.
12 BOOST_AUTO_TEST_CASE ( conserved_path_simple ) 
13 {
14   vector<int> path;
15   path += 3,4,5,1; // magic from boost assign
16
17   ConservedPath cp1;
18   BOOST_CHECK_EQUAL( cp1.size(), 0 ); //empty
19   BOOST_CHECK( cp1.begin() == cp1.end() );
20   
21   cp1.score = 18;
22   cp1.track_indexes = path;
23   BOOST_CHECK_EQUAL( cp1.size(), path.size() );
24
25   ConservedPath cp2(18, path);
26   BOOST_CHECK_EQUAL (cp1, cp2);
27   BOOST_CHECK_EQUAL( cp2.size(), path.size() );
28
29   ConservedPath::iterator cp2_itor;
30   vector<int>::iterator path_itor;
31   for (cp2_itor = cp2.begin(), path_itor = path.begin();
32        cp2_itor != cp2.end() && path_itor != path.end();
33        ++cp2_itor, ++path_itor)
34   {
35     BOOST_CHECK_EQUAL( *cp2_itor, *path_itor );
36   }
37
38   ConservedPath cp3( cp2 );
39   BOOST_CHECK_EQUAL( cp3.size(), cp2.size() );
40   ConservedPath::iterator cp3_itor;
41   for (cp2_itor = cp2.begin(), cp3_itor = cp3.begin();
42        cp2_itor != cp2.end() && cp3_itor != cp3.end();
43        ++cp2_itor, ++cp3_itor)
44   {
45     BOOST_CHECK_EQUAL( *cp2_itor, *cp3_itor );
46   }
47 }
48
49 //! do vector like operations work?
50 BOOST_AUTO_TEST_CASE ( conserved_path_vector )
51 {
52   ConservedPath cp;
53   cp.score = 21.0;
54   
55   BOOST_CHECK_EQUAL( cp.size(), 0 );
56   cp.push_back( 3 );
57   BOOST_CHECK_EQUAL( cp.size(), 1);
58   BOOST_CHECK_EQUAL( cp[0], 3 );
59   cp.push_back( 4 );
60   BOOST_CHECK_EQUAL( cp.size(), 2);
61   BOOST_CHECK_EQUAL( cp[1], 4 );
62   cp.pop_back();
63   BOOST_CHECK_EQUAL( cp.size(), 1 );
64 }
65
66 // does the reverse compliment test work?
67 BOOST_AUTO_TEST_CASE ( conserved_path_reverse_compliment ) 
68 {
69   vector<int> path;
70   path += 3,4,-5,1; // magic from boost assign
71
72   ConservedPath cp1(10, path);
73   vector<bool> reversed = cp1.reverseComplimented();
74
75   BOOST_CHECK_EQUAL( path.size(), reversed.size());
76   vector<int>::iterator path_i = path.begin();
77   vector<bool>::iterator reversed_i = reversed.begin();
78   for(; path_i != path.end() and reversed_i != reversed.end(); 
79       ++path_i, ++reversed_i)
80   {
81     // if we're less than zero our reversed flag should be true
82     BOOST_CHECK_EQUAL( *path_i < 0, *reversed_i);
83   }
84 }
85
86 BOOST_AUTO_TEST_CASE ( extended_conserved_path_simple ) 
87 {
88   vector<int> path;
89   path += 3,4,5,1; // magic from boost assign
90
91   ExtendedConservedPath ecp1;
92   ecp1.window_size = 30;
93   ecp1.score = 18;
94   ecp1.track_indexes = path;
95   BOOST_CHECK_EQUAL ( ecp1.size(), path.size() );
96
97   ExtendedConservedPath ecp2(30, 18.0, path);
98   BOOST_CHECK_EQUAL ( ecp1, ecp2 );
99   BOOST_CHECK_EQUAL ( ecp2.size(), path.size() );
100
101   ExtendedConservedPath ecp_ne(35, 20.0, path);
102   BOOST_CHECK(ecp2 != ecp_ne);
103
104   ConservedPath cp1;
105   cp1.score = 18;
106   cp1.track_indexes = path;
107
108   ExtendedConservedPath ecp3(30, cp1);
109   BOOST_CHECK_EQUAL( ecp2, ecp3 );
110   BOOST_CHECK_EQUAL( ecp3.size(), path.size() );
111 }
112
113 //! Can we grow succesfully?
114 BOOST_AUTO_TEST_CASE ( extended_conserved_path_growth )
115 {
116   vector<int> path_base;
117   path_base += 3,4,5,1; // magic from boost assign
118   vector<int> path_next;
119   path_next += 4,5,6,2; 
120   vector<int> path_next_reversed;
121   path_next_reversed += 4,5,6,-2; 
122   vector<int> path_not_next;
123   path_not_next += 4,5,6,5; 
124   const int window_size = 4;
125
126   ExtendedConservedPath ecp_base(window_size, 20, path_base);
127   ConservedPath cp_next(25, path_next);
128   ConservedPath cp_next_reversed(25, path_next_reversed);
129   ConservedPath cp_not_next(22, path_not_next);
130
131   BOOST_CHECK(ecp_base.nextTo(cp_next));
132   BOOST_CHECK(!ecp_base.nextTo(cp_not_next));
133   // FIXME: should something like this actually extend?
134   BOOST_CHECK(!ecp_base.nextTo(cp_next_reversed));
135
136   const int growth = 2;
137   ecp_base.extend(growth);
138   BOOST_CHECK_EQUAL( ecp_base.window_size, window_size + growth );
139 }