test/graph_copy_test.cc
branch1.1
changeset 984 9f22c22fe227
parent 463 88ed40ad0d4f
parent 980 bb871cb8ac06
child 989 24b3f18ed9e2
child 1081 f1398882a928
equal deleted inserted replaced
4:e404105f6c86 6:0942a9569053
    27 using namespace lemon;
    27 using namespace lemon;
    28 
    28 
    29 void digraph_copy_test() {
    29 void digraph_copy_test() {
    30   const int nn = 10;
    30   const int nn = 10;
    31 
    31 
       
    32   // Build a digraph
    32   SmartDigraph from;
    33   SmartDigraph from;
    33   SmartDigraph::NodeMap<int> fnm(from);
    34   SmartDigraph::NodeMap<int> fnm(from);
    34   SmartDigraph::ArcMap<int> fam(from);
    35   SmartDigraph::ArcMap<int> fam(from);
    35   SmartDigraph::Node fn = INVALID;
    36   SmartDigraph::Node fn = INVALID;
    36   SmartDigraph::Arc fa = INVALID;
    37   SmartDigraph::Arc fa = INVALID;
    49       fam[arc] = i + j * j;
    50       fam[arc] = i + j * j;
    50       if (i == 0 && j == 0) fa = arc;
    51       if (i == 0 && j == 0) fa = arc;
    51     }
    52     }
    52   }
    53   }
    53 
    54 
       
    55   // Test digraph copy
    54   ListDigraph to;
    56   ListDigraph to;
    55   ListDigraph::NodeMap<int> tnm(to);
    57   ListDigraph::NodeMap<int> tnm(to);
    56   ListDigraph::ArcMap<int> tam(to);
    58   ListDigraph::ArcMap<int> tam(to);
    57   ListDigraph::Node tn;
    59   ListDigraph::Node tn;
    58   ListDigraph::Arc ta;
    60   ListDigraph::Arc ta;
    66   digraphCopy(from, to).
    68   digraphCopy(from, to).
    67     nodeMap(fnm, tnm).arcMap(fam, tam).
    69     nodeMap(fnm, tnm).arcMap(fam, tam).
    68     nodeRef(nr).arcRef(er).
    70     nodeRef(nr).arcRef(er).
    69     nodeCrossRef(ncr).arcCrossRef(ecr).
    71     nodeCrossRef(ncr).arcCrossRef(ecr).
    70     node(fn, tn).arc(fa, ta).run();
    72     node(fn, tn).arc(fa, ta).run();
       
    73   
       
    74   check(countNodes(from) == countNodes(to), "Wrong copy.");
       
    75   check(countArcs(from) == countArcs(to), "Wrong copy.");
    71 
    76 
    72   for (SmartDigraph::NodeIt it(from); it != INVALID; ++it) {
    77   for (SmartDigraph::NodeIt it(from); it != INVALID; ++it) {
    73     check(ncr[nr[it]] == it, "Wrong copy.");
    78     check(ncr[nr[it]] == it, "Wrong copy.");
    74     check(fnm[it] == tnm[nr[it]], "Wrong copy.");
    79     check(fnm[it] == tnm[nr[it]], "Wrong copy.");
    75   }
    80   }
    88   for (ListDigraph::ArcIt it(to); it != INVALID; ++it) {
    93   for (ListDigraph::ArcIt it(to); it != INVALID; ++it) {
    89     check(er[ecr[it]] == it, "Wrong copy.");
    94     check(er[ecr[it]] == it, "Wrong copy.");
    90   }
    95   }
    91   check(tn == nr[fn], "Wrong copy.");
    96   check(tn == nr[fn], "Wrong copy.");
    92   check(ta == er[fa], "Wrong copy.");
    97   check(ta == er[fa], "Wrong copy.");
       
    98 
       
    99   // Test repeated copy
       
   100   digraphCopy(from, to).run();
       
   101   
       
   102   check(countNodes(from) == countNodes(to), "Wrong copy.");
       
   103   check(countArcs(from) == countArcs(to), "Wrong copy.");
    93 }
   104 }
    94 
   105 
    95 void graph_copy_test() {
   106 void graph_copy_test() {
    96   const int nn = 10;
   107   const int nn = 10;
    97 
   108 
       
   109   // Build a graph
    98   SmartGraph from;
   110   SmartGraph from;
    99   SmartGraph::NodeMap<int> fnm(from);
   111   SmartGraph::NodeMap<int> fnm(from);
   100   SmartGraph::ArcMap<int> fam(from);
   112   SmartGraph::ArcMap<int> fam(from);
   101   SmartGraph::EdgeMap<int> fem(from);
   113   SmartGraph::EdgeMap<int> fem(from);
   102   SmartGraph::Node fn = INVALID;
   114   SmartGraph::Node fn = INVALID;
   120       if (i == 0 && j == 0) fa = from.direct(edge, true);
   132       if (i == 0 && j == 0) fa = from.direct(edge, true);
   121       if (i == 0 && j == 0) fe = edge;
   133       if (i == 0 && j == 0) fe = edge;
   122     }
   134     }
   123   }
   135   }
   124 
   136 
       
   137   // Test graph copy
   125   ListGraph to;
   138   ListGraph to;
   126   ListGraph::NodeMap<int> tnm(to);
   139   ListGraph::NodeMap<int> tnm(to);
   127   ListGraph::ArcMap<int> tam(to);
   140   ListGraph::ArcMap<int> tam(to);
   128   ListGraph::EdgeMap<int> tem(to);
   141   ListGraph::EdgeMap<int> tem(to);
   129   ListGraph::Node tn;
   142   ListGraph::Node tn;
   141   graphCopy(from, to).
   154   graphCopy(from, to).
   142     nodeMap(fnm, tnm).arcMap(fam, tam).edgeMap(fem, tem).
   155     nodeMap(fnm, tnm).arcMap(fam, tam).edgeMap(fem, tem).
   143     nodeRef(nr).arcRef(ar).edgeRef(er).
   156     nodeRef(nr).arcRef(ar).edgeRef(er).
   144     nodeCrossRef(ncr).arcCrossRef(acr).edgeCrossRef(ecr).
   157     nodeCrossRef(ncr).arcCrossRef(acr).edgeCrossRef(ecr).
   145     node(fn, tn).arc(fa, ta).edge(fe, te).run();
   158     node(fn, tn).arc(fa, ta).edge(fe, te).run();
       
   159 
       
   160   check(countNodes(from) == countNodes(to), "Wrong copy.");
       
   161   check(countEdges(from) == countEdges(to), "Wrong copy.");
       
   162   check(countArcs(from) == countArcs(to), "Wrong copy.");
   146 
   163 
   147   for (SmartGraph::NodeIt it(from); it != INVALID; ++it) {
   164   for (SmartGraph::NodeIt it(from); it != INVALID; ++it) {
   148     check(ncr[nr[it]] == it, "Wrong copy.");
   165     check(ncr[nr[it]] == it, "Wrong copy.");
   149     check(fnm[it] == tnm[nr[it]], "Wrong copy.");
   166     check(fnm[it] == tnm[nr[it]], "Wrong copy.");
   150   }
   167   }
   178     check(er[ecr[it]] == it, "Wrong copy.");
   195     check(er[ecr[it]] == it, "Wrong copy.");
   179   }
   196   }
   180   check(tn == nr[fn], "Wrong copy.");
   197   check(tn == nr[fn], "Wrong copy.");
   181   check(ta == ar[fa], "Wrong copy.");
   198   check(ta == ar[fa], "Wrong copy.");
   182   check(te == er[fe], "Wrong copy.");
   199   check(te == er[fe], "Wrong copy.");
       
   200 
       
   201   // Test repeated copy
       
   202   graphCopy(from, to).run();
       
   203   
       
   204   check(countNodes(from) == countNodes(to), "Wrong copy.");
       
   205   check(countEdges(from) == countEdges(to), "Wrong copy.");
       
   206   check(countArcs(from) == countArcs(to), "Wrong copy.");
   183 }
   207 }
   184 
   208 
   185 
   209 
   186 int main() {
   210 int main() {
   187   digraph_copy_test();
   211   digraph_copy_test();