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 BOOST_AUTO_TEST_CASE ( extended_conserved_path_simple )
69 path += 3,4,5,1; // magic from boost assign
71 ExtendedConservedPath ecp1;
72 ecp1.window_size = 30;
74 ecp1.track_indexes = path;
75 BOOST_CHECK_EQUAL ( ecp1.size(), path.size() );
77 ExtendedConservedPath ecp2(30, 18.0, path);
78 BOOST_CHECK_EQUAL ( ecp1, ecp2 );
79 BOOST_CHECK_EQUAL ( ecp2.size(), path.size() );
81 ExtendedConservedPath ecp_ne(35, 20.0, path);
82 BOOST_CHECK(ecp2 != ecp_ne);
86 cp1.track_indexes = path;
88 ExtendedConservedPath ecp3(30, cp1);
89 BOOST_CHECK_EQUAL( ecp2, ecp3 );
90 BOOST_CHECK_EQUAL( ecp3.size(), path.size() );
93 //! Can we grow succesfully?
94 BOOST_AUTO_TEST_CASE ( extended_conserved_path_growth )
96 vector<int> path_base;
97 path_base += 3,4,5,1; // magic from boost assign
98 vector<int> path_next;
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;
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);
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));
116 const int growth = 2;
117 ecp_base.extend(growth);
118 BOOST_CHECK_EQUAL( ecp_base.window_size, window_size + growth );