diff -r dff32ce3db71 -r d3dcc49e6403 test/tsp_test.cc --- a/test/tsp_test.cc Sun Jan 09 15:06:55 2011 +0100 +++ b/test/tsp_test.cc Thu Feb 28 17:13:14 2013 +0100 @@ -61,21 +61,23 @@ // } // Checks tour validity -bool checkTour(const FullGraph &gr, const std::vector &p) { +template +bool checkTour(const FullGraph &gr, const Container &p) { FullGraph::NodeMap used(gr, false); - int nodes = 0; - for (int i = 0; i < int(p.size()); ++i) { - if (used[p[i]]) return false; - used[p[i]] = true; - ++nodes; + int node_cnt = 0; + for (typename Container::const_iterator it = p.begin(); it != p.end(); ++it) { + FullGraph::Node node = *it; + if (used[node]) return false; + used[node] = true; + ++node_cnt; } - return (nodes == gr.nodeNum()); + return (node_cnt == gr.nodeNum()); } // Checks tour validity -bool checkTour(const FullGraph &gr, const Path &p) { +bool checkTourPath(const FullGraph &gr, const Path &p) { FullGraph::NodeMap used(gr, false); if (!checkPath(gr, p)) return false; @@ -134,21 +136,24 @@ check(alg.run() == esize, alg_name + ": Wrong total cost"); check(alg.tourCost() == esize, alg_name + ": Wrong total cost"); - std::list list; - std::vector vec; - alg.tourNodes(list); - alg.tourNodes(vec); - check(list.size() == nsize, alg_name + ": Wrong node sequence"); - check(vec.size() == nsize, alg_name + ": Wrong node sequence"); - check(alg.tourNodes().size() == nsize, alg_name + ": Wrong node sequence"); - check(checkTour(g, vec), alg_name + ": Wrong node sequence"); - check(checkCost(g, vec, constMap(1), esize), + std::list list1(nsize), list2; + std::vector vec1(nsize), vec2; + alg.tourNodes(list1.begin()); + alg.tourNodes(vec1.begin()); + alg.tourNodes(std::front_inserter(list2)); + alg.tourNodes(std::back_inserter(vec2)); + check(checkTour(g, alg.tourNodes()), alg_name + ": Wrong node sequence"); + check(checkTour(g, list1), alg_name + ": Wrong node sequence"); + check(checkTour(g, vec1), alg_name + ": Wrong node sequence"); + check(checkTour(g, list2), alg_name + ": Wrong node sequence"); + check(checkTour(g, vec2), alg_name + ": Wrong node sequence"); + check(checkCost(g, vec1, constMap(1), esize), alg_name + ": Wrong tour cost"); SimplePath path; alg.tour(path); check(path.length() == esize, alg_name + ": Wrong tour"); - check(checkTour(g, path), alg_name + ": Wrong tour"); + check(checkTourPath(g, path), alg_name + ": Wrong tour"); check(checkCost(g, path, constMap(1), esize), alg_name + ": Wrong tour cost"); } @@ -180,14 +185,14 @@ check(alg.run() > 0, alg_name + ": Wrong total cost"); std::vector vec; - alg.tourNodes(vec); + alg.tourNodes(std::back_inserter(vec)); check(checkTour(g, vec), alg_name + ": Wrong node sequence"); check(checkCost(g, vec, cost, alg.tourCost()), alg_name + ": Wrong tour cost"); SimplePath path; alg.tour(path); - check(checkTour(g, path), alg_name + ": Wrong tour"); + check(checkTourPath(g, path), alg_name + ": Wrong tour"); check(checkCost(g, path, cost, alg.tourCost()), alg_name + ": Wrong tour cost");