1.1 --- a/lemon/core.h Mon Apr 12 13:59:41 2010 +0200
1.2 +++ b/lemon/core.h Tue Jun 22 15:39:26 2010 +0200
1.3 @@ -384,6 +384,7 @@
1.4 template <typename From, typename NodeRefMap, typename ArcRefMap>
1.5 static void copy(const From& from, Digraph &to,
1.6 NodeRefMap& nodeRefMap, ArcRefMap& arcRefMap) {
1.7 + to.clear();
1.8 for (typename From::NodeIt it(from); it != INVALID; ++it) {
1.9 nodeRefMap[it] = to.addNode();
1.10 }
1.11 @@ -411,6 +412,7 @@
1.12 template <typename From, typename NodeRefMap, typename EdgeRefMap>
1.13 static void copy(const From& from, Graph &to,
1.14 NodeRefMap& nodeRefMap, EdgeRefMap& edgeRefMap) {
1.15 + to.clear();
1.16 for (typename From::NodeIt it(from); it != INVALID; ++it) {
1.17 nodeRefMap[it] = to.addNode();
1.18 }
2.1 --- a/test/graph_copy_test.cc Mon Apr 12 13:59:41 2010 +0200
2.2 +++ b/test/graph_copy_test.cc Tue Jun 22 15:39:26 2010 +0200
2.3 @@ -29,6 +29,7 @@
2.4 void digraph_copy_test() {
2.5 const int nn = 10;
2.6
2.7 + // Build a digraph
2.8 SmartDigraph from;
2.9 SmartDigraph::NodeMap<int> fnm(from);
2.10 SmartDigraph::ArcMap<int> fam(from);
2.11 @@ -51,6 +52,7 @@
2.12 }
2.13 }
2.14
2.15 + // Test digraph copy
2.16 ListDigraph to;
2.17 ListDigraph::NodeMap<int> tnm(to);
2.18 ListDigraph::ArcMap<int> tam(to);
2.19 @@ -68,6 +70,9 @@
2.20 nodeRef(nr).arcRef(er).
2.21 nodeCrossRef(ncr).arcCrossRef(ecr).
2.22 node(fn, tn).arc(fa, ta).run();
2.23 +
2.24 + check(countNodes(from) == countNodes(to), "Wrong copy.");
2.25 + check(countArcs(from) == countArcs(to), "Wrong copy.");
2.26
2.27 for (SmartDigraph::NodeIt it(from); it != INVALID; ++it) {
2.28 check(ncr[nr[it]] == it, "Wrong copy.");
2.29 @@ -90,11 +95,18 @@
2.30 }
2.31 check(tn == nr[fn], "Wrong copy.");
2.32 check(ta == er[fa], "Wrong copy.");
2.33 +
2.34 + // Test repeated copy
2.35 + digraphCopy(from, to).run();
2.36 +
2.37 + check(countNodes(from) == countNodes(to), "Wrong copy.");
2.38 + check(countArcs(from) == countArcs(to), "Wrong copy.");
2.39 }
2.40
2.41 void graph_copy_test() {
2.42 const int nn = 10;
2.43
2.44 + // Build a graph
2.45 SmartGraph from;
2.46 SmartGraph::NodeMap<int> fnm(from);
2.47 SmartGraph::ArcMap<int> fam(from);
2.48 @@ -122,6 +134,7 @@
2.49 }
2.50 }
2.51
2.52 + // Test graph copy
2.53 ListGraph to;
2.54 ListGraph::NodeMap<int> tnm(to);
2.55 ListGraph::ArcMap<int> tam(to);
2.56 @@ -144,6 +157,10 @@
2.57 nodeCrossRef(ncr).arcCrossRef(acr).edgeCrossRef(ecr).
2.58 node(fn, tn).arc(fa, ta).edge(fe, te).run();
2.59
2.60 + check(countNodes(from) == countNodes(to), "Wrong copy.");
2.61 + check(countEdges(from) == countEdges(to), "Wrong copy.");
2.62 + check(countArcs(from) == countArcs(to), "Wrong copy.");
2.63 +
2.64 for (SmartGraph::NodeIt it(from); it != INVALID; ++it) {
2.65 check(ncr[nr[it]] == it, "Wrong copy.");
2.66 check(fnm[it] == tnm[nr[it]], "Wrong copy.");
2.67 @@ -180,6 +197,13 @@
2.68 check(tn == nr[fn], "Wrong copy.");
2.69 check(ta == ar[fa], "Wrong copy.");
2.70 check(te == er[fe], "Wrong copy.");
2.71 +
2.72 + // Test repeated copy
2.73 + graphCopy(from, to).run();
2.74 +
2.75 + check(countNodes(from) == countNodes(to), "Wrong copy.");
2.76 + check(countEdges(from) == countEdges(to), "Wrong copy.");
2.77 + check(countArcs(from) == countArcs(to), "Wrong copy.");
2.78 }
2.79
2.80