# HG changeset patch # User Alpar Juttner # Date 1277438605 -7200 # Node ID a5cb98ee8d91243fdb4302b0af4a482d627f8215 # Parent 7faa990932a335bd534ad82758c8271f31ac14e3# Parent bb871cb8ac0664d5db95721a1d678d604762a3c2 Merge bugfix #371 to branch 1.0 diff -r 7faa990932a3 -r a5cb98ee8d91 lemon/core.h --- a/lemon/core.h Mon Apr 12 16:49:51 2010 +0200 +++ b/lemon/core.h Fri Jun 25 06:03:25 2010 +0200 @@ -384,6 +384,7 @@ template static void copy(const From& from, Digraph &to, NodeRefMap& nodeRefMap, ArcRefMap& arcRefMap) { + to.clear(); for (typename From::NodeIt it(from); it != INVALID; ++it) { nodeRefMap[it] = to.addNode(); } @@ -411,6 +412,7 @@ template static void copy(const From& from, Graph &to, NodeRefMap& nodeRefMap, EdgeRefMap& edgeRefMap) { + to.clear(); for (typename From::NodeIt it(from); it != INVALID; ++it) { nodeRefMap[it] = to.addNode(); } diff -r 7faa990932a3 -r a5cb98ee8d91 test/graph_copy_test.cc --- a/test/graph_copy_test.cc Mon Apr 12 16:49:51 2010 +0200 +++ b/test/graph_copy_test.cc Fri Jun 25 06:03:25 2010 +0200 @@ -29,6 +29,7 @@ void digraph_copy_test() { const int nn = 10; + // Build a digraph SmartDigraph from; SmartDigraph::NodeMap fnm(from); SmartDigraph::ArcMap fam(from); @@ -51,6 +52,7 @@ } } + // Test digraph copy ListDigraph to; ListDigraph::NodeMap tnm(to); ListDigraph::ArcMap tam(to); @@ -68,6 +70,9 @@ nodeRef(nr).arcRef(er). nodeCrossRef(ncr).arcCrossRef(ecr). node(fn, tn).arc(fa, ta).run(); + + check(countNodes(from) == countNodes(to), "Wrong copy."); + check(countArcs(from) == countArcs(to), "Wrong copy."); for (SmartDigraph::NodeIt it(from); it != INVALID; ++it) { check(ncr[nr[it]] == it, "Wrong copy."); @@ -90,11 +95,18 @@ } check(tn == nr[fn], "Wrong copy."); check(ta == er[fa], "Wrong copy."); + + // Test repeated copy + digraphCopy(from, to).run(); + + check(countNodes(from) == countNodes(to), "Wrong copy."); + check(countArcs(from) == countArcs(to), "Wrong copy."); } void graph_copy_test() { const int nn = 10; + // Build a graph SmartGraph from; SmartGraph::NodeMap fnm(from); SmartGraph::ArcMap fam(from); @@ -122,6 +134,7 @@ } } + // Test graph copy ListGraph to; ListGraph::NodeMap tnm(to); ListGraph::ArcMap tam(to); @@ -144,6 +157,10 @@ nodeCrossRef(ncr).arcCrossRef(acr).edgeCrossRef(ecr). node(fn, tn).arc(fa, ta).edge(fe, te).run(); + check(countNodes(from) == countNodes(to), "Wrong copy."); + check(countEdges(from) == countEdges(to), "Wrong copy."); + check(countArcs(from) == countArcs(to), "Wrong copy."); + for (SmartGraph::NodeIt it(from); it != INVALID; ++it) { check(ncr[nr[it]] == it, "Wrong copy."); check(fnm[it] == tnm[nr[it]], "Wrong copy."); @@ -180,6 +197,13 @@ check(tn == nr[fn], "Wrong copy."); check(ta == ar[fa], "Wrong copy."); check(te == er[fe], "Wrong copy."); + + // Test repeated copy + graphCopy(from, to).run(); + + check(countNodes(from) == countNodes(to), "Wrong copy."); + check(countEdges(from) == countEdges(to), "Wrong copy."); + check(countArcs(from) == countArcs(to), "Wrong copy."); }