test/graph_copy_test.cc
changeset 1193 c8fa41fcc4a7
parent 1190 523e45e37e52
child 1194 699c7eac2c6d
equal deleted inserted replaced
10:23a4b0fded60 11:8b1b2c15ed14
   219   SmartBpGraph::RedMap<int> frnm(from);
   219   SmartBpGraph::RedMap<int> frnm(from);
   220   SmartBpGraph::BlueMap<int> fbnm(from);
   220   SmartBpGraph::BlueMap<int> fbnm(from);
   221   SmartBpGraph::ArcMap<int> fam(from);
   221   SmartBpGraph::ArcMap<int> fam(from);
   222   SmartBpGraph::EdgeMap<int> fem(from);
   222   SmartBpGraph::EdgeMap<int> fem(from);
   223   SmartBpGraph::Node fn = INVALID;
   223   SmartBpGraph::Node fn = INVALID;
       
   224   SmartBpGraph::RedNode frn = INVALID;
       
   225   SmartBpGraph::BlueNode fbn = INVALID;
   224   SmartBpGraph::Arc fa = INVALID;
   226   SmartBpGraph::Arc fa = INVALID;
   225   SmartBpGraph::Edge fe = INVALID;
   227   SmartBpGraph::Edge fe = INVALID;
   226 
   228 
   227   std::vector<SmartBpGraph::Node> frnv;
   229   std::vector<SmartBpGraph::RedNode> frnv;
   228   for (int i = 0; i < nn; ++i) {
   230   for (int i = 0; i < nn; ++i) {
   229     SmartBpGraph::Node node = from.addRedNode();
   231     SmartBpGraph::RedNode node = from.addRedNode();
   230     frnv.push_back(node);
   232     frnv.push_back(node);
   231     fnm[node] = i * i;
   233     fnm[node] = i * i;
   232     frnm[node] = i + i;
   234     frnm[node] = i + i;
   233     if (i == 0) fn = node;
   235     if (i == 0) {
   234   }
   236       fn = node;
   235 
   237       frn = node;
   236   std::vector<SmartBpGraph::Node> fbnv;
   238     }
   237   for (int i = 0; i < nn; ++i) {
   239   }
   238     SmartBpGraph::Node node = from.addBlueNode();
   240 
       
   241   std::vector<SmartBpGraph::BlueNode> fbnv;
       
   242   for (int i = 0; i < nn; ++i) {
       
   243     SmartBpGraph::BlueNode node = from.addBlueNode();
   239     fbnv.push_back(node);
   244     fbnv.push_back(node);
   240     fnm[node] = i * i;
   245     fnm[node] = i * i;
   241     fbnm[node] = i + i;
   246     fbnm[node] = i + i;
       
   247     if (i == 0) fbn = node;
   242   }
   248   }
   243 
   249 
   244   for (int i = 0; i < nn; ++i) {
   250   for (int i = 0; i < nn; ++i) {
   245     for (int j = 0; j < nn; ++j) {
   251     for (int j = 0; j < nn; ++j) {
   246       SmartBpGraph::Edge edge = from.addEdge(frnv[i], fbnv[j]);
   252       SmartBpGraph::Edge edge = from.addEdge(frnv[i], fbnv[j]);
   258   typename GR::template RedMap<int> trnm(to);
   264   typename GR::template RedMap<int> trnm(to);
   259   typename GR::template BlueMap<int> tbnm(to);
   265   typename GR::template BlueMap<int> tbnm(to);
   260   typename GR::template ArcMap<int> tam(to);
   266   typename GR::template ArcMap<int> tam(to);
   261   typename GR::template EdgeMap<int> tem(to);
   267   typename GR::template EdgeMap<int> tem(to);
   262   typename GR::Node tn;
   268   typename GR::Node tn;
       
   269   typename GR::RedNode trn;
       
   270   typename GR::BlueNode tbn;
   263   typename GR::Arc ta;
   271   typename GR::Arc ta;
   264   typename GR::Edge te;
   272   typename GR::Edge te;
   265 
   273 
   266   SmartBpGraph::NodeMap<typename GR::Node> nr(from);
   274   SmartBpGraph::NodeMap<typename GR::Node> nr(from);
   267   SmartBpGraph::RedMap<typename GR::Node> rnr(from);
   275   SmartBpGraph::RedMap<typename GR::RedNode> rnr(from);
   268   SmartBpGraph::BlueMap<typename GR::Node> bnr(from);
   276   SmartBpGraph::BlueMap<typename GR::BlueNode> bnr(from);
   269   SmartBpGraph::ArcMap<typename GR::Arc> ar(from);
   277   SmartBpGraph::ArcMap<typename GR::Arc> ar(from);
   270   SmartBpGraph::EdgeMap<typename GR::Edge> er(from);
   278   SmartBpGraph::EdgeMap<typename GR::Edge> er(from);
   271 
   279 
   272   typename GR::template NodeMap<SmartBpGraph::Node> ncr(to);
   280   typename GR::template NodeMap<SmartBpGraph::Node> ncr(to);
   273   typename GR::template RedMap<SmartBpGraph::Node> rncr(to);
   281   typename GR::template RedMap<SmartBpGraph::RedNode> rncr(to);
   274   typename GR::template BlueMap<SmartBpGraph::Node> bncr(to);
   282   typename GR::template BlueMap<SmartBpGraph::BlueNode> bncr(to);
   275   typename GR::template ArcMap<SmartBpGraph::Arc> acr(to);
   283   typename GR::template ArcMap<SmartBpGraph::Arc> acr(to);
   276   typename GR::template EdgeMap<SmartBpGraph::Edge> ecr(to);
   284   typename GR::template EdgeMap<SmartBpGraph::Edge> ecr(to);
   277 
   285 
   278   bpGraphCopy(from, to).
   286   bpGraphCopy(from, to).
   279     nodeMap(fnm, tnm).redMap(frnm, trnm).blueMap(fbnm, tbnm).
   287     nodeMap(fnm, tnm).redMap(frnm, trnm).blueMap(fbnm, tbnm).
   280     arcMap(fam, tam).edgeMap(fem, tem).
   288     arcMap(fam, tam).edgeMap(fem, tem).
   281     nodeRef(nr).redRef(rnr).blueRef(bnr).
   289     nodeRef(nr).redRef(rnr).blueRef(bnr).
   282     arcRef(ar).edgeRef(er).
   290     arcRef(ar).edgeRef(er).
   283     nodeCrossRef(ncr).redCrossRef(rncr).blueCrossRef(bncr).
   291     nodeCrossRef(ncr).redCrossRef(rncr).blueCrossRef(bncr).
   284     arcCrossRef(acr).edgeCrossRef(ecr).
   292     arcCrossRef(acr).edgeCrossRef(ecr).
   285     node(fn, tn).arc(fa, ta).edge(fe, te).run();
   293     node(fn, tn).redNode(frn, trn).blueNode(fbn, tbn).
       
   294     arc(fa, ta).edge(fe, te).run();
   286 
   295 
   287   check(countNodes(from) == countNodes(to), "Wrong copy.");
   296   check(countNodes(from) == countNodes(to), "Wrong copy.");
   288   check(countRedNodes(from) == countRedNodes(to), "Wrong copy.");
   297   check(countRedNodes(from) == countRedNodes(to), "Wrong copy.");
   289   check(countBlueNodes(from) == countBlueNodes(to), "Wrong copy.");
   298   check(countBlueNodes(from) == countBlueNodes(to), "Wrong copy.");
   290   check(countEdges(from) == countEdges(to), "Wrong copy.");
   299   check(countEdges(from) == countEdges(to), "Wrong copy.");
   291   check(countArcs(from) == countArcs(to), "Wrong copy.");
   300   check(countArcs(from) == countArcs(to), "Wrong copy.");
   292 
   301 
   293   for (SmartBpGraph::NodeIt it(from); it != INVALID; ++it) {
   302   for (SmartBpGraph::NodeIt it(from); it != INVALID; ++it) {
   294     check(ncr[nr[it]] == it, "Wrong copy.");
   303     check(ncr[nr[it]] == it, "Wrong copy.");
   295     check(fnm[it] == tnm[nr[it]], "Wrong copy.");
   304     check(fnm[it] == tnm[nr[it]], "Wrong copy.");
   296     if (from.red(it)) {
   305   }
   297       check(rnr[it] == nr[it], "Wrong copy.");
   306 
   298       check(rncr[rnr[it]] == it, "Wrong copy.");
   307   for (SmartBpGraph::RedIt it(from); it != INVALID; ++it) {
   299       check(frnm[it] == trnm[rnr[it]], "Wrong copy.");
   308     check(ncr[nr[it]] == it, "Wrong copy.");
   300       check(to.red(rnr[it]), "Wrong copy.");
   309     check(fnm[it] == tnm[nr[it]], "Wrong copy.");
   301     } else {
   310     check(rnr[it] == nr[it], "Wrong copy.");
   302       check(bnr[it] == nr[it], "Wrong copy.");
   311     check(rncr[rnr[it]] == it, "Wrong copy.");
   303       check(bncr[bnr[it]] == it, "Wrong copy.");
   312     check(frnm[it] == trnm[rnr[it]], "Wrong copy.");
   304       check(fbnm[it] == tbnm[bnr[it]], "Wrong copy.");
   313     check(to.red(rnr[it]), "Wrong copy.");
   305       check(to.blue(bnr[it]), "Wrong copy.");
   314   }
   306     }
   315 
       
   316   for (SmartBpGraph::BlueIt it(from); it != INVALID; ++it) {
       
   317     check(ncr[nr[it]] == it, "Wrong copy.");
       
   318     check(fnm[it] == tnm[nr[it]], "Wrong copy.");
       
   319     check(bnr[it] == nr[it], "Wrong copy.");
       
   320     check(bncr[bnr[it]] == it, "Wrong copy.");
       
   321     check(fbnm[it] == tbnm[bnr[it]], "Wrong copy.");
       
   322     check(to.blue(bnr[it]), "Wrong copy.");
   307   }
   323   }
   308 
   324 
   309   for (SmartBpGraph::ArcIt it(from); it != INVALID; ++it) {
   325   for (SmartBpGraph::ArcIt it(from); it != INVALID; ++it) {
   310     check(acr[ar[it]] == it, "Wrong copy.");
   326     check(acr[ar[it]] == it, "Wrong copy.");
   311     check(fam[it] == tam[ar[it]], "Wrong copy.");
   327     check(fam[it] == tam[ar[it]], "Wrong copy.");
   340   }
   356   }
   341   for (typename GR::EdgeIt it(to); it != INVALID; ++it) {
   357   for (typename GR::EdgeIt it(to); it != INVALID; ++it) {
   342     check(er[ecr[it]] == it, "Wrong copy.");
   358     check(er[ecr[it]] == it, "Wrong copy.");
   343   }
   359   }
   344   check(tn == nr[fn], "Wrong copy.");
   360   check(tn == nr[fn], "Wrong copy.");
       
   361   check(trn == rnr[frn], "Wrong copy.");
       
   362   check(tbn == bnr[fbn], "Wrong copy.");
   345   check(ta == ar[fa], "Wrong copy.");
   363   check(ta == ar[fa], "Wrong copy.");
   346   check(te == er[fe], "Wrong copy.");
   364   check(te == er[fe], "Wrong copy.");
   347 
   365 
   348   // Test repeated copy
   366   // Test repeated copy
   349   bpGraphCopy(from, to).run();
   367   bpGraphCopy(from, to).run();