There can be only one (filename convention)
[mussa.git] / alg / test / test_conserved_path.cpp
diff --git a/alg/test/test_conserved_path.cpp b/alg/test/test_conserved_path.cpp
new file mode 100644 (file)
index 0000000..b28c635
--- /dev/null
@@ -0,0 +1,119 @@
+#include <boost/test/auto_unit_test.hpp>
+#include <boost/assign/std/vector.hpp>
+using namespace boost::assign;
+
+#include <vector>
+using namespace std;
+
+#include "alg/conserved_path.hpp"
+
+//! write tests for our conserved path types (just to make sure they
+//! don't change on us.
+BOOST_AUTO_TEST_CASE ( conserved_path_simple ) 
+{
+  vector<int> path;
+  path += 3,4,5,1; // magic from boost assign
+
+  ConservedPath cp1;
+  BOOST_CHECK_EQUAL( cp1.size(), 0 ); //empty
+  BOOST_CHECK( cp1.begin() == cp1.end() );
+  
+  cp1.score = 18;
+  cp1.track_indexes = path;
+  BOOST_CHECK_EQUAL( cp1.size(), path.size() );
+
+  ConservedPath cp2(18, path);
+  BOOST_CHECK_EQUAL (cp1, cp2);
+  BOOST_CHECK_EQUAL( cp2.size(), path.size() );
+
+  ConservedPath::iterator cp2_itor;
+  vector<int>::iterator path_itor;
+  for (cp2_itor = cp2.begin(), path_itor = path.begin();
+       cp2_itor != cp2.end() && path_itor != path.end();
+       ++cp2_itor, ++path_itor)
+  {
+    BOOST_CHECK_EQUAL( *cp2_itor, *path_itor );
+  }
+
+  ConservedPath cp3( cp2 );
+  BOOST_CHECK_EQUAL( cp3.size(), cp2.size() );
+  ConservedPath::iterator cp3_itor;
+  for (cp2_itor = cp2.begin(), cp3_itor = cp3.begin();
+       cp2_itor != cp2.end() && cp3_itor != cp3.end();
+       ++cp2_itor, ++cp3_itor)
+  {
+    BOOST_CHECK_EQUAL( *cp2_itor, *cp3_itor );
+  }
+}
+
+//! do vector like operations work?
+BOOST_AUTO_TEST_CASE ( conserved_path_vector )
+{
+  ConservedPath cp;
+  cp.score = 21.0;
+  
+  BOOST_CHECK_EQUAL( cp.size(), 0 );
+  cp.push_back( 3 );
+  BOOST_CHECK_EQUAL( cp.size(), 1);
+  BOOST_CHECK_EQUAL( cp[0], 3 );
+  cp.push_back( 4 );
+  BOOST_CHECK_EQUAL( cp.size(), 2);
+  BOOST_CHECK_EQUAL( cp[1], 4 );
+  cp.pop_back();
+  BOOST_CHECK_EQUAL( cp.size(), 1 );
+}
+
+BOOST_AUTO_TEST_CASE ( extended_conserved_path_simple ) 
+{
+  vector<int> path;
+  path += 3,4,5,1; // magic from boost assign
+
+  ExtendedConservedPath ecp1;
+  ecp1.window_size = 30;
+  ecp1.score = 18;
+  ecp1.track_indexes = path;
+  BOOST_CHECK_EQUAL ( ecp1.size(), path.size() );
+
+  ExtendedConservedPath ecp2(30, 18.0, path);
+  BOOST_CHECK_EQUAL ( ecp1, ecp2 );
+  BOOST_CHECK_EQUAL ( ecp2.size(), path.size() );
+
+  ExtendedConservedPath ecp_ne(35, 20.0, path);
+  BOOST_CHECK(ecp2 != ecp_ne);
+
+  ConservedPath cp1;
+  cp1.score = 18;
+  cp1.track_indexes = path;
+
+  ExtendedConservedPath ecp3(30, cp1);
+  BOOST_CHECK_EQUAL( ecp2, ecp3 );
+  BOOST_CHECK_EQUAL( ecp3.size(), path.size() );
+}
+
+//! Can we grow succesfully?
+BOOST_AUTO_TEST_CASE ( extended_conserved_path_growth )
+{
+  vector<int> path_base;
+  path_base += 3,4,5,1; // magic from boost assign
+  vector<int> path_next;
+  path_next += 4,5,6,2; 
+  vector<int> path_next_reversed;
+  path_next_reversed += 4,5,6,-2; 
+  vector<int> path_not_next;
+  path_not_next += 4,5,6,5; 
+  const int window_size = 4;
+
+  ExtendedConservedPath ecp_base(window_size, 20, path_base);
+  ConservedPath cp_next(25, path_next);
+  ConservedPath cp_next_reversed(25, path_next_reversed);
+  ConservedPath cp_not_next(22, path_not_next);
+
+  BOOST_CHECK(ecp_base.nextTo(cp_next));
+  BOOST_CHECK(!ecp_base.nextTo(cp_not_next));
+  // FIXME: should something like this actually extend?
+  BOOST_CHECK(!ecp_base.nextTo(cp_next_reversed));
+
+  const int growth = 2;
+  ecp_base.extend(growth);
+  BOOST_CHECK_EQUAL( ecp_base.window_size, window_size + growth );
+}