return not (a == b);
}
+bool operator<(const ConservedPath& a, const ConservedPath &b)
+{
+ ConservedPath::const_iterator a_i = a.begin();
+ ConservedPath::const_iterator b_i = b.begin();
+ for(; a_i != a.end() and b_i != b.end(); ++a_i, ++b_i)
+ {
+ if (*a_i < *b_i) {
+ return true;
+ } else if (*a_i > *b_i) {
+ return false;
+ }
+ // else they're equal and we continue to loop
+ }
+ // now handle mismatched lengths
+ if (a_i == a.end() and b_i == b.end()) {
+ return false; // since the two paths are equal
+ } else if (a_i == a.end()) {
+ return true; // a is shorter than b
+ } else if (b_i == b.end()) {
+ return false; // b is shorter than a
+ } else {
+ // something went horribly wrong
+ throw std::runtime_error("ConservedPath operator< had a fatal logic error");
+ }
+}
+
std::ostream& operator<<(std::ostream& out, const ConservedPath& path)
{
out << "<path win_size" << path.window_size
friend bool operator==(const ConservedPath& a, const ConservedPath &b);
friend bool operator!=(const ConservedPath& a, const ConservedPath &b);
+ friend bool operator<(const ConservedPath& a, const ConservedPath &b);
friend std::ostream& operator<<(std::ostream&, const ConservedPath&);
//! return true if all elements of the path are "next to" our current path.
}
}
+BOOST_AUTO_TEST_CASE( conserved_path_less_than )
+{
+ vector<int> p111;
+ p111 += 1,1,1;
+ vector<int> p112;
+ p112 += 1,1,2;
+ vector<int> p115;
+ p115 += 1,1,5;
+ vector<int> p112a;
+ p112a += 1,1,1;
+ vector<int> p1111;
+ p1111 += 1,1,1,1;
+
+ ConservedPath cp111(10, 1.0, p111);
+ ConservedPath cp112(10, 1.0, p112);
+ ConservedPath cp112a(10, 1.0, p112a);
+ ConservedPath cp115(10, 1.0, p115);
+ ConservedPath cp1111(10, 1.0, p1111);
+
+ BOOST_CHECK_EQUAL( cp111 < cp112, true );
+ BOOST_CHECK_EQUAL( cp111 < cp1111, true );
+ BOOST_CHECK_EQUAL( cp1111 < cp111, false );
+ BOOST_CHECK_EQUAL( cp112 < cp112, false );
+ BOOST_CHECK_EQUAL( cp112 == cp112, true );
+ BOOST_CHECK_EQUAL( cp112 < cp115, true );
+}
+
+BOOST_AUTO_TEST_CASE( conserved_path_sort )
+{
+ vector<int> p111;
+ p111 += 1,1,1;
+ vector<int> p112;
+ p112 += 1,1,2;
+ vector<int> p115;
+ p115 += 1,1,5;
+ vector<int> p121;
+ p121 += 1,2,1;
+
+ ConservedPath cp111(10, 1.0, p111);
+ ConservedPath cp112(10, 1.0, p112);
+ ConservedPath cp115(10, 1.0, p115);
+ ConservedPath cp121(10, 1.0, p121);
+
+ list<ConservedPath> paths;
+ paths.push_back(cp115);
+ paths.push_back(cp121);
+ paths.push_back(cp112);
+ paths.push_back(cp111);
+
+ paths.sort();
+ BOOST_REQUIRE_EQUAL( paths.size(), 4 );
+ list<ConservedPath>::const_iterator path_i = paths.begin();
+
+ BOOST_CHECK_EQUAL( *path_i, cp111 ); ++path_i;
+ BOOST_CHECK_EQUAL( *path_i, cp112 ); ++path_i;
+ BOOST_CHECK_EQUAL( *path_i, cp115 ); ++path_i;
+ BOOST_CHECK_EQUAL( *path_i, cp121 );
+}
\ No newline at end of file
result_i != result.end();
++result_i)
{
- std::cout << "path ";
ConservedPath::path_element first_element = *(result_i->begin());
for (ConservedPath::path_type::iterator element_i = result_i->begin();
element_i != result_i->end();
BOOST_CHECK_EQUAL( s0[*element_i], s1[*element_i] );
BOOST_CHECK_EQUAL( s1[*element_i], s2[*element_i] );
BOOST_CHECK_EQUAL( s0[*element_i], s2[*element_i] );
- std::cout << *element_i << " " << s0[*element_i];
}
- std::cout << std::endl;
}
}