1 #include <boost/test/auto_unit_test.hpp>
2 #include <boost/assign/std/vector.hpp>
3 using namespace boost::assign;
8 #include "alg/conserved_path.hpp"
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 )
15 path += 3,4,5,1; // magic from boost assign
18 BOOST_CHECK_EQUAL( cp1.size(), 0 ); //empty
19 BOOST_CHECK( cp1.begin() == cp1.end() );
22 cp1.track_indexes = path;
23 BOOST_CHECK_EQUAL( cp1.size(), path.size() );
25 ConservedPath cp2(18, path);
26 BOOST_CHECK_EQUAL (cp1, cp2);
27 BOOST_CHECK_EQUAL( cp2.size(), path.size() );
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)
35 BOOST_CHECK_EQUAL( *cp2_itor, *path_itor );
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)
45 BOOST_CHECK_EQUAL( *cp2_itor, *cp3_itor );
49 //! do vector like operations work?
50 BOOST_AUTO_TEST_CASE ( conserved_path_vector )
55 BOOST_CHECK_EQUAL( cp.size(), 0 );
57 BOOST_CHECK_EQUAL( cp.size(), 1);
58 BOOST_CHECK_EQUAL( cp[0], 3 );
60 BOOST_CHECK_EQUAL( cp.size(), 2);
61 BOOST_CHECK_EQUAL( cp[1], 4 );
63 BOOST_CHECK_EQUAL( cp.size(), 1 );
66 // does the reverse compliment test work?
67 BOOST_AUTO_TEST_CASE ( conserved_path_reverse_compliment )
70 path += 3,4,-5,1; // magic from boost assign
72 ConservedPath cp1(10, path);
73 vector<bool> reversed = cp1.reverseComplimented();
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)
81 // if we're less than zero our reversed flag should be true
82 BOOST_CHECK_EQUAL( *path_i < 0, *reversed_i);
86 BOOST_AUTO_TEST_CASE ( extended_conserved_path_simple )
89 path += 3,4,5,1; // magic from boost assign
91 ExtendedConservedPath ecp1;
92 ecp1.window_size = 30;
94 ecp1.track_indexes = path;
95 BOOST_CHECK_EQUAL ( ecp1.size(), path.size() );
97 ExtendedConservedPath ecp2(30, 18.0, path);
98 BOOST_CHECK_EQUAL ( ecp1, ecp2 );
99 BOOST_CHECK_EQUAL ( ecp2.size(), path.size() );
101 ExtendedConservedPath ecp_ne(35, 20.0, path);
102 BOOST_CHECK(ecp2 != ecp_ne);
106 cp1.track_indexes = path;
108 ExtendedConservedPath ecp3(30, cp1);
109 BOOST_CHECK_EQUAL( ecp2, ecp3 );
110 BOOST_CHECK_EQUAL( ecp3.size(), path.size() );
113 //! Can we grow succesfully?
114 BOOST_AUTO_TEST_CASE ( extended_conserved_path_growth )
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;
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);
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));
136 const int growth = 2;
137 ecp_base.extend(growth);
138 BOOST_CHECK_EQUAL( ecp_base.window_size, window_size + growth );
141 BOOST_AUTO_TEST_CASE ( extended_conserved_normalized )
144 path += 3,-14,5,-19; // magic from boost assign
145 vector<int> normalized_path;
146 normalized_path += 3,4, 5,9;
148 ExtendedConservedPath ecp1;
149 ecp1.window_size = 10;
151 ecp1.track_indexes = path;
152 BOOST_CHECK_EQUAL ( ecp1.size(), path.size() );
154 vector<ConservedPath::path_element> normalized_index(ecp1.normalizedIndexes());
156 for(int i=0; i != ecp1.size(); ++i)
158 BOOST_CHECK_EQUAL(normalized_index[i], normalized_path[i]);