There can be only one (filename convention)
[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 BOOST_AUTO_TEST_CASE ( extended_conserved_path_simple ) 
67 {
68   vector<int> path;
69   path += 3,4,5,1; // magic from boost assign
70
71   ExtendedConservedPath ecp1;
72   ecp1.window_size = 30;
73   ecp1.score = 18;
74   ecp1.track_indexes = path;
75   BOOST_CHECK_EQUAL ( ecp1.size(), path.size() );
76
77   ExtendedConservedPath ecp2(30, 18.0, path);
78   BOOST_CHECK_EQUAL ( ecp1, ecp2 );
79   BOOST_CHECK_EQUAL ( ecp2.size(), path.size() );
80
81   ExtendedConservedPath ecp_ne(35, 20.0, path);
82   BOOST_CHECK(ecp2 != ecp_ne);
83
84   ConservedPath cp1;
85   cp1.score = 18;
86   cp1.track_indexes = path;
87
88   ExtendedConservedPath ecp3(30, cp1);
89   BOOST_CHECK_EQUAL( ecp2, ecp3 );
90   BOOST_CHECK_EQUAL( ecp3.size(), path.size() );
91 }
92
93 //! Can we grow succesfully?
94 BOOST_AUTO_TEST_CASE ( extended_conserved_path_growth )
95 {
96   vector<int> path_base;
97   path_base += 3,4,5,1; // magic from boost assign
98   vector<int> path_next;
99   path_next += 4,5,6,2; 
100   vector<int> path_next_reversed;
101   path_next_reversed += 4,5,6,-2; 
102   vector<int> path_not_next;
103   path_not_next += 4,5,6,5; 
104   const int window_size = 4;
105
106   ExtendedConservedPath ecp_base(window_size, 20, path_base);
107   ConservedPath cp_next(25, path_next);
108   ConservedPath cp_next_reversed(25, path_next_reversed);
109   ConservedPath cp_not_next(22, path_not_next);
110
111   BOOST_CHECK(ecp_base.nextTo(cp_next));
112   BOOST_CHECK(!ecp_base.nextTo(cp_not_next));
113   // FIXME: should something like this actually extend?
114   BOOST_CHECK(!ecp_base.nextTo(cp_next_reversed));
115
116   const int growth = 2;
117   ecp_base.extend(growth);
118   BOOST_CHECK_EQUAL( ecp_base.window_size, window_size + growth );
119 }