test/graph_copy_test.cc
changeset 1023 939ee6d1e525
parent 894 24b3f18ed9e2
child 1025 c8fa41fcc4a7
equal deleted inserted replaced
7:4de9041bafd9 8:23a4b0fded60
   207   check(countNodes(from) == countNodes(to), "Wrong copy.");
   207   check(countNodes(from) == countNodes(to), "Wrong copy.");
   208   check(countEdges(from) == countEdges(to), "Wrong copy.");
   208   check(countEdges(from) == countEdges(to), "Wrong copy.");
   209   check(countArcs(from) == countArcs(to), "Wrong copy.");
   209   check(countArcs(from) == countArcs(to), "Wrong copy.");
   210 }
   210 }
   211 
   211 
       
   212 template <typename GR>
       
   213 void bpgraph_copy_test() {
       
   214   const int nn = 10;
       
   215 
       
   216   // Build a graph
       
   217   SmartBpGraph from;
       
   218   SmartBpGraph::NodeMap<int> fnm(from);
       
   219   SmartBpGraph::RedMap<int> frnm(from);
       
   220   SmartBpGraph::BlueMap<int> fbnm(from);
       
   221   SmartBpGraph::ArcMap<int> fam(from);
       
   222   SmartBpGraph::EdgeMap<int> fem(from);
       
   223   SmartBpGraph::Node fn = INVALID;
       
   224   SmartBpGraph::Arc fa = INVALID;
       
   225   SmartBpGraph::Edge fe = INVALID;
       
   226 
       
   227   std::vector<SmartBpGraph::Node> frnv;
       
   228   for (int i = 0; i < nn; ++i) {
       
   229     SmartBpGraph::Node node = from.addRedNode();
       
   230     frnv.push_back(node);
       
   231     fnm[node] = i * i;
       
   232     frnm[node] = i + i;
       
   233     if (i == 0) fn = node;
       
   234   }
       
   235 
       
   236   std::vector<SmartBpGraph::Node> fbnv;
       
   237   for (int i = 0; i < nn; ++i) {
       
   238     SmartBpGraph::Node node = from.addBlueNode();
       
   239     fbnv.push_back(node);
       
   240     fnm[node] = i * i;
       
   241     fbnm[node] = i + i;
       
   242   }
       
   243 
       
   244   for (int i = 0; i < nn; ++i) {
       
   245     for (int j = 0; j < nn; ++j) {
       
   246       SmartBpGraph::Edge edge = from.addEdge(frnv[i], fbnv[j]);
       
   247       fem[edge] = i * i + j * j;
       
   248       fam[from.direct(edge, true)] = i + j * j;
       
   249       fam[from.direct(edge, false)] = i * i + j;
       
   250       if (i == 0 && j == 0) fa = from.direct(edge, true);
       
   251       if (i == 0 && j == 0) fe = edge;
       
   252     }
       
   253   }
       
   254 
       
   255   // Test graph copy
       
   256   GR to;
       
   257   typename GR::template NodeMap<int> tnm(to);
       
   258   typename GR::template RedMap<int> trnm(to);
       
   259   typename GR::template BlueMap<int> tbnm(to);
       
   260   typename GR::template ArcMap<int> tam(to);
       
   261   typename GR::template EdgeMap<int> tem(to);
       
   262   typename GR::Node tn;
       
   263   typename GR::Arc ta;
       
   264   typename GR::Edge te;
       
   265 
       
   266   SmartBpGraph::NodeMap<typename GR::Node> nr(from);
       
   267   SmartBpGraph::RedMap<typename GR::Node> rnr(from);
       
   268   SmartBpGraph::BlueMap<typename GR::Node> bnr(from);
       
   269   SmartBpGraph::ArcMap<typename GR::Arc> ar(from);
       
   270   SmartBpGraph::EdgeMap<typename GR::Edge> er(from);
       
   271 
       
   272   typename GR::template NodeMap<SmartBpGraph::Node> ncr(to);
       
   273   typename GR::template RedMap<SmartBpGraph::Node> rncr(to);
       
   274   typename GR::template BlueMap<SmartBpGraph::Node> bncr(to);
       
   275   typename GR::template ArcMap<SmartBpGraph::Arc> acr(to);
       
   276   typename GR::template EdgeMap<SmartBpGraph::Edge> ecr(to);
       
   277 
       
   278   bpGraphCopy(from, to).
       
   279     nodeMap(fnm, tnm).redMap(frnm, trnm).blueMap(fbnm, tbnm).
       
   280     arcMap(fam, tam).edgeMap(fem, tem).
       
   281     nodeRef(nr).redRef(rnr).blueRef(bnr).
       
   282     arcRef(ar).edgeRef(er).
       
   283     nodeCrossRef(ncr).redCrossRef(rncr).blueCrossRef(bncr).
       
   284     arcCrossRef(acr).edgeCrossRef(ecr).
       
   285     node(fn, tn).arc(fa, ta).edge(fe, te).run();
       
   286 
       
   287   check(countNodes(from) == countNodes(to), "Wrong copy.");
       
   288   check(countRedNodes(from) == countRedNodes(to), "Wrong copy.");
       
   289   check(countBlueNodes(from) == countBlueNodes(to), "Wrong copy.");
       
   290   check(countEdges(from) == countEdges(to), "Wrong copy.");
       
   291   check(countArcs(from) == countArcs(to), "Wrong copy.");
       
   292 
       
   293   for (SmartBpGraph::NodeIt it(from); it != INVALID; ++it) {
       
   294     check(ncr[nr[it]] == it, "Wrong copy.");
       
   295     check(fnm[it] == tnm[nr[it]], "Wrong copy.");
       
   296     if (from.red(it)) {
       
   297       check(rnr[it] == nr[it], "Wrong copy.");
       
   298       check(rncr[rnr[it]] == it, "Wrong copy.");
       
   299       check(frnm[it] == trnm[rnr[it]], "Wrong copy.");
       
   300       check(to.red(rnr[it]), "Wrong copy.");
       
   301     } else {
       
   302       check(bnr[it] == nr[it], "Wrong copy.");
       
   303       check(bncr[bnr[it]] == it, "Wrong copy.");
       
   304       check(fbnm[it] == tbnm[bnr[it]], "Wrong copy.");
       
   305       check(to.blue(bnr[it]), "Wrong copy.");
       
   306     }
       
   307   }
       
   308 
       
   309   for (SmartBpGraph::ArcIt it(from); it != INVALID; ++it) {
       
   310     check(acr[ar[it]] == it, "Wrong copy.");
       
   311     check(fam[it] == tam[ar[it]], "Wrong copy.");
       
   312     check(nr[from.source(it)] == to.source(ar[it]), "Wrong copy.");
       
   313     check(nr[from.target(it)] == to.target(ar[it]), "Wrong copy.");
       
   314   }
       
   315 
       
   316   for (SmartBpGraph::EdgeIt it(from); it != INVALID; ++it) {
       
   317     check(ecr[er[it]] == it, "Wrong copy.");
       
   318     check(fem[it] == tem[er[it]], "Wrong copy.");
       
   319     check(nr[from.u(it)] == to.u(er[it]) || nr[from.u(it)] == to.v(er[it]),
       
   320           "Wrong copy.");
       
   321     check(nr[from.v(it)] == to.u(er[it]) || nr[from.v(it)] == to.v(er[it]),
       
   322           "Wrong copy.");
       
   323     check((from.u(it) != from.v(it)) == (to.u(er[it]) != to.v(er[it])),
       
   324           "Wrong copy.");
       
   325   }
       
   326 
       
   327   for (typename GR::NodeIt it(to); it != INVALID; ++it) {
       
   328     check(nr[ncr[it]] == it, "Wrong copy.");
       
   329   }
       
   330   for (typename GR::RedIt it(to); it != INVALID; ++it) {
       
   331     check(rncr[it] == ncr[it], "Wrong copy.");
       
   332     check(rnr[rncr[it]] == it, "Wrong copy.");
       
   333   }
       
   334   for (typename GR::BlueIt it(to); it != INVALID; ++it) {
       
   335     check(bncr[it] == ncr[it], "Wrong copy.");
       
   336     check(bnr[bncr[it]] == it, "Wrong copy.");
       
   337   }
       
   338   for (typename GR::ArcIt it(to); it != INVALID; ++it) {
       
   339     check(ar[acr[it]] == it, "Wrong copy.");
       
   340   }
       
   341   for (typename GR::EdgeIt it(to); it != INVALID; ++it) {
       
   342     check(er[ecr[it]] == it, "Wrong copy.");
       
   343   }
       
   344   check(tn == nr[fn], "Wrong copy.");
       
   345   check(ta == ar[fa], "Wrong copy.");
       
   346   check(te == er[fe], "Wrong copy.");
       
   347 
       
   348   // Test repeated copy
       
   349   bpGraphCopy(from, to).run();
       
   350   
       
   351   check(countNodes(from) == countNodes(to), "Wrong copy.");
       
   352   check(countRedNodes(from) == countRedNodes(to), "Wrong copy.");
       
   353   check(countBlueNodes(from) == countBlueNodes(to), "Wrong copy.");
       
   354   check(countEdges(from) == countEdges(to), "Wrong copy.");
       
   355   check(countArcs(from) == countArcs(to), "Wrong copy.");
       
   356 }
       
   357 
   212 
   358 
   213 int main() {
   359 int main() {
   214   digraph_copy_test<SmartDigraph>();
   360   digraph_copy_test<SmartDigraph>();
   215   digraph_copy_test<ListDigraph>();
   361   digraph_copy_test<ListDigraph>();
   216   digraph_copy_test<StaticDigraph>();
   362   digraph_copy_test<StaticDigraph>();
   217   graph_copy_test<SmartGraph>();
   363   graph_copy_test<SmartGraph>();
   218   graph_copy_test<ListGraph>();
   364   graph_copy_test<ListGraph>();
       
   365   bpgraph_copy_test<SmartBpGraph>();
       
   366   bpgraph_copy_test<ListBpGraph>();
   219 
   367 
   220   return 0;
   368   return 0;
   221 }
   369 }