test/graph_copy_test.cc
changeset 990 dca9eed2c375
parent 984 9f22c22fe227
child 1190 523e45e37e52
equal deleted inserted replaced
6:0942a9569053 7:4de9041bafd9
    16  *
    16  *
    17  */
    17  */
    18 
    18 
    19 #include <lemon/smart_graph.h>
    19 #include <lemon/smart_graph.h>
    20 #include <lemon/list_graph.h>
    20 #include <lemon/list_graph.h>
       
    21 #include <lemon/static_graph.h>
    21 #include <lemon/lgf_reader.h>
    22 #include <lemon/lgf_reader.h>
    22 #include <lemon/error.h>
    23 #include <lemon/error.h>
    23 
    24 
    24 #include "test_tools.h"
    25 #include "test_tools.h"
    25 
    26 
    26 using namespace std;
    27 using namespace std;
    27 using namespace lemon;
    28 using namespace lemon;
    28 
    29 
       
    30 template <typename GR>
    29 void digraph_copy_test() {
    31 void digraph_copy_test() {
    30   const int nn = 10;
    32   const int nn = 10;
    31 
    33 
    32   // Build a digraph
    34   // Build a digraph
    33   SmartDigraph from;
    35   SmartDigraph from;
    49       SmartDigraph::Arc arc = from.addArc(fnv[i], fnv[j]);
    51       SmartDigraph::Arc arc = from.addArc(fnv[i], fnv[j]);
    50       fam[arc] = i + j * j;
    52       fam[arc] = i + j * j;
    51       if (i == 0 && j == 0) fa = arc;
    53       if (i == 0 && j == 0) fa = arc;
    52     }
    54     }
    53   }
    55   }
    54 
    56   
    55   // Test digraph copy
    57   // Test digraph copy
    56   ListDigraph to;
    58   GR to;
    57   ListDigraph::NodeMap<int> tnm(to);
    59   typename GR::template NodeMap<int> tnm(to);
    58   ListDigraph::ArcMap<int> tam(to);
    60   typename GR::template ArcMap<int> tam(to);
    59   ListDigraph::Node tn;
    61   typename GR::Node tn;
    60   ListDigraph::Arc ta;
    62   typename GR::Arc ta;
    61 
    63 
    62   SmartDigraph::NodeMap<ListDigraph::Node> nr(from);
    64   SmartDigraph::NodeMap<typename GR::Node> nr(from);
    63   SmartDigraph::ArcMap<ListDigraph::Arc> er(from);
    65   SmartDigraph::ArcMap<typename GR::Arc> er(from);
    64 
    66 
    65   ListDigraph::NodeMap<SmartDigraph::Node> ncr(to);
    67   typename GR::template NodeMap<SmartDigraph::Node> ncr(to);
    66   ListDigraph::ArcMap<SmartDigraph::Arc> ecr(to);
    68   typename GR::template ArcMap<SmartDigraph::Arc> ecr(to);
    67 
    69 
    68   digraphCopy(from, to).
    70   digraphCopy(from, to).
    69     nodeMap(fnm, tnm).arcMap(fam, tam).
    71     nodeMap(fnm, tnm).arcMap(fam, tam).
    70     nodeRef(nr).arcRef(er).
    72     nodeRef(nr).arcRef(er).
    71     nodeCrossRef(ncr).arcCrossRef(ecr).
    73     nodeCrossRef(ncr).arcCrossRef(ecr).
    84     check(fam[it] == tam[er[it]], "Wrong copy.");
    86     check(fam[it] == tam[er[it]], "Wrong copy.");
    85     check(nr[from.source(it)] == to.source(er[it]), "Wrong copy.");
    87     check(nr[from.source(it)] == to.source(er[it]), "Wrong copy.");
    86     check(nr[from.target(it)] == to.target(er[it]), "Wrong copy.");
    88     check(nr[from.target(it)] == to.target(er[it]), "Wrong copy.");
    87   }
    89   }
    88 
    90 
    89   for (ListDigraph::NodeIt it(to); it != INVALID; ++it) {
    91   for (typename GR::NodeIt it(to); it != INVALID; ++it) {
    90     check(nr[ncr[it]] == it, "Wrong copy.");
    92     check(nr[ncr[it]] == it, "Wrong copy.");
    91   }
    93   }
    92 
    94 
    93   for (ListDigraph::ArcIt it(to); it != INVALID; ++it) {
    95   for (typename GR::ArcIt it(to); it != INVALID; ++it) {
    94     check(er[ecr[it]] == it, "Wrong copy.");
    96     check(er[ecr[it]] == it, "Wrong copy.");
    95   }
    97   }
    96   check(tn == nr[fn], "Wrong copy.");
    98   check(tn == nr[fn], "Wrong copy.");
    97   check(ta == er[fa], "Wrong copy.");
    99   check(ta == er[fa], "Wrong copy.");
    98 
   100 
   101   
   103   
   102   check(countNodes(from) == countNodes(to), "Wrong copy.");
   104   check(countNodes(from) == countNodes(to), "Wrong copy.");
   103   check(countArcs(from) == countArcs(to), "Wrong copy.");
   105   check(countArcs(from) == countArcs(to), "Wrong copy.");
   104 }
   106 }
   105 
   107 
       
   108 template <typename GR>
   106 void graph_copy_test() {
   109 void graph_copy_test() {
   107   const int nn = 10;
   110   const int nn = 10;
   108 
   111 
   109   // Build a graph
   112   // Build a graph
   110   SmartGraph from;
   113   SmartGraph from;
   133       if (i == 0 && j == 0) fe = edge;
   136       if (i == 0 && j == 0) fe = edge;
   134     }
   137     }
   135   }
   138   }
   136 
   139 
   137   // Test graph copy
   140   // Test graph copy
   138   ListGraph to;
   141   GR to;
   139   ListGraph::NodeMap<int> tnm(to);
   142   typename GR::template NodeMap<int> tnm(to);
   140   ListGraph::ArcMap<int> tam(to);
   143   typename GR::template ArcMap<int> tam(to);
   141   ListGraph::EdgeMap<int> tem(to);
   144   typename GR::template EdgeMap<int> tem(to);
   142   ListGraph::Node tn;
   145   typename GR::Node tn;
   143   ListGraph::Arc ta;
   146   typename GR::Arc ta;
   144   ListGraph::Edge te;
   147   typename GR::Edge te;
   145 
   148 
   146   SmartGraph::NodeMap<ListGraph::Node> nr(from);
   149   SmartGraph::NodeMap<typename GR::Node> nr(from);
   147   SmartGraph::ArcMap<ListGraph::Arc> ar(from);
   150   SmartGraph::ArcMap<typename GR::Arc> ar(from);
   148   SmartGraph::EdgeMap<ListGraph::Edge> er(from);
   151   SmartGraph::EdgeMap<typename GR::Edge> er(from);
   149 
   152 
   150   ListGraph::NodeMap<SmartGraph::Node> ncr(to);
   153   typename GR::template NodeMap<SmartGraph::Node> ncr(to);
   151   ListGraph::ArcMap<SmartGraph::Arc> acr(to);
   154   typename GR::template ArcMap<SmartGraph::Arc> acr(to);
   152   ListGraph::EdgeMap<SmartGraph::Edge> ecr(to);
   155   typename GR::template EdgeMap<SmartGraph::Edge> ecr(to);
   153 
   156 
   154   graphCopy(from, to).
   157   graphCopy(from, to).
   155     nodeMap(fnm, tnm).arcMap(fam, tam).edgeMap(fem, tem).
   158     nodeMap(fnm, tnm).arcMap(fam, tam).edgeMap(fem, tem).
   156     nodeRef(nr).arcRef(ar).edgeRef(er).
   159     nodeRef(nr).arcRef(ar).edgeRef(er).
   157     nodeCrossRef(ncr).arcCrossRef(acr).edgeCrossRef(ecr).
   160     nodeCrossRef(ncr).arcCrossRef(acr).edgeCrossRef(ecr).
   182           "Wrong copy.");
   185           "Wrong copy.");
   183     check((from.u(it) != from.v(it)) == (to.u(er[it]) != to.v(er[it])),
   186     check((from.u(it) != from.v(it)) == (to.u(er[it]) != to.v(er[it])),
   184           "Wrong copy.");
   187           "Wrong copy.");
   185   }
   188   }
   186 
   189 
   187   for (ListGraph::NodeIt it(to); it != INVALID; ++it) {
   190   for (typename GR::NodeIt it(to); it != INVALID; ++it) {
   188     check(nr[ncr[it]] == it, "Wrong copy.");
   191     check(nr[ncr[it]] == it, "Wrong copy.");
   189   }
   192   }
   190 
   193 
   191   for (ListGraph::ArcIt it(to); it != INVALID; ++it) {
   194   for (typename GR::ArcIt it(to); it != INVALID; ++it) {
   192     check(ar[acr[it]] == it, "Wrong copy.");
   195     check(ar[acr[it]] == it, "Wrong copy.");
   193   }
   196   }
   194   for (ListGraph::EdgeIt it(to); it != INVALID; ++it) {
   197   for (typename GR::EdgeIt it(to); it != INVALID; ++it) {
   195     check(er[ecr[it]] == it, "Wrong copy.");
   198     check(er[ecr[it]] == it, "Wrong copy.");
   196   }
   199   }
   197   check(tn == nr[fn], "Wrong copy.");
   200   check(tn == nr[fn], "Wrong copy.");
   198   check(ta == ar[fa], "Wrong copy.");
   201   check(ta == ar[fa], "Wrong copy.");
   199   check(te == er[fe], "Wrong copy.");
   202   check(te == er[fe], "Wrong copy.");
   206   check(countArcs(from) == countArcs(to), "Wrong copy.");
   209   check(countArcs(from) == countArcs(to), "Wrong copy.");
   207 }
   210 }
   208 
   211 
   209 
   212 
   210 int main() {
   213 int main() {
   211   digraph_copy_test();
   214   digraph_copy_test<SmartDigraph>();
   212   graph_copy_test();
   215   digraph_copy_test<ListDigraph>();
       
   216   digraph_copy_test<StaticDigraph>();
       
   217   graph_copy_test<SmartGraph>();
       
   218   graph_copy_test<ListGraph>();
   213 
   219 
   214   return 0;
   220   return 0;
   215 }
   221 }