test/graph_copy_test.cc
changeset 1022 523e45e37e52
parent 894 24b3f18ed9e2
child 1025 c8fa41fcc4a7
     1.1 --- a/test/graph_copy_test.cc	Mon Nov 15 09:46:08 2010 +0100
     1.2 +++ b/test/graph_copy_test.cc	Tue Nov 16 00:59:36 2010 +0100
     1.3 @@ -209,6 +209,152 @@
     1.4    check(countArcs(from) == countArcs(to), "Wrong copy.");
     1.5  }
     1.6  
     1.7 +template <typename GR>
     1.8 +void bpgraph_copy_test() {
     1.9 +  const int nn = 10;
    1.10 +
    1.11 +  // Build a graph
    1.12 +  SmartBpGraph from;
    1.13 +  SmartBpGraph::NodeMap<int> fnm(from);
    1.14 +  SmartBpGraph::RedMap<int> frnm(from);
    1.15 +  SmartBpGraph::BlueMap<int> fbnm(from);
    1.16 +  SmartBpGraph::ArcMap<int> fam(from);
    1.17 +  SmartBpGraph::EdgeMap<int> fem(from);
    1.18 +  SmartBpGraph::Node fn = INVALID;
    1.19 +  SmartBpGraph::Arc fa = INVALID;
    1.20 +  SmartBpGraph::Edge fe = INVALID;
    1.21 +
    1.22 +  std::vector<SmartBpGraph::Node> frnv;
    1.23 +  for (int i = 0; i < nn; ++i) {
    1.24 +    SmartBpGraph::Node node = from.addRedNode();
    1.25 +    frnv.push_back(node);
    1.26 +    fnm[node] = i * i;
    1.27 +    frnm[node] = i + i;
    1.28 +    if (i == 0) fn = node;
    1.29 +  }
    1.30 +
    1.31 +  std::vector<SmartBpGraph::Node> fbnv;
    1.32 +  for (int i = 0; i < nn; ++i) {
    1.33 +    SmartBpGraph::Node node = from.addBlueNode();
    1.34 +    fbnv.push_back(node);
    1.35 +    fnm[node] = i * i;
    1.36 +    fbnm[node] = i + i;
    1.37 +  }
    1.38 +
    1.39 +  for (int i = 0; i < nn; ++i) {
    1.40 +    for (int j = 0; j < nn; ++j) {
    1.41 +      SmartBpGraph::Edge edge = from.addEdge(frnv[i], fbnv[j]);
    1.42 +      fem[edge] = i * i + j * j;
    1.43 +      fam[from.direct(edge, true)] = i + j * j;
    1.44 +      fam[from.direct(edge, false)] = i * i + j;
    1.45 +      if (i == 0 && j == 0) fa = from.direct(edge, true);
    1.46 +      if (i == 0 && j == 0) fe = edge;
    1.47 +    }
    1.48 +  }
    1.49 +
    1.50 +  // Test graph copy
    1.51 +  GR to;
    1.52 +  typename GR::template NodeMap<int> tnm(to);
    1.53 +  typename GR::template RedMap<int> trnm(to);
    1.54 +  typename GR::template BlueMap<int> tbnm(to);
    1.55 +  typename GR::template ArcMap<int> tam(to);
    1.56 +  typename GR::template EdgeMap<int> tem(to);
    1.57 +  typename GR::Node tn;
    1.58 +  typename GR::Arc ta;
    1.59 +  typename GR::Edge te;
    1.60 +
    1.61 +  SmartBpGraph::NodeMap<typename GR::Node> nr(from);
    1.62 +  SmartBpGraph::RedMap<typename GR::Node> rnr(from);
    1.63 +  SmartBpGraph::BlueMap<typename GR::Node> bnr(from);
    1.64 +  SmartBpGraph::ArcMap<typename GR::Arc> ar(from);
    1.65 +  SmartBpGraph::EdgeMap<typename GR::Edge> er(from);
    1.66 +
    1.67 +  typename GR::template NodeMap<SmartBpGraph::Node> ncr(to);
    1.68 +  typename GR::template RedMap<SmartBpGraph::Node> rncr(to);
    1.69 +  typename GR::template BlueMap<SmartBpGraph::Node> bncr(to);
    1.70 +  typename GR::template ArcMap<SmartBpGraph::Arc> acr(to);
    1.71 +  typename GR::template EdgeMap<SmartBpGraph::Edge> ecr(to);
    1.72 +
    1.73 +  bpGraphCopy(from, to).
    1.74 +    nodeMap(fnm, tnm).redMap(frnm, trnm).blueMap(fbnm, tbnm).
    1.75 +    arcMap(fam, tam).edgeMap(fem, tem).
    1.76 +    nodeRef(nr).redRef(rnr).blueRef(bnr).
    1.77 +    arcRef(ar).edgeRef(er).
    1.78 +    nodeCrossRef(ncr).redCrossRef(rncr).blueCrossRef(bncr).
    1.79 +    arcCrossRef(acr).edgeCrossRef(ecr).
    1.80 +    node(fn, tn).arc(fa, ta).edge(fe, te).run();
    1.81 +
    1.82 +  check(countNodes(from) == countNodes(to), "Wrong copy.");
    1.83 +  check(countRedNodes(from) == countRedNodes(to), "Wrong copy.");
    1.84 +  check(countBlueNodes(from) == countBlueNodes(to), "Wrong copy.");
    1.85 +  check(countEdges(from) == countEdges(to), "Wrong copy.");
    1.86 +  check(countArcs(from) == countArcs(to), "Wrong copy.");
    1.87 +
    1.88 +  for (SmartBpGraph::NodeIt it(from); it != INVALID; ++it) {
    1.89 +    check(ncr[nr[it]] == it, "Wrong copy.");
    1.90 +    check(fnm[it] == tnm[nr[it]], "Wrong copy.");
    1.91 +    if (from.red(it)) {
    1.92 +      check(rnr[it] == nr[it], "Wrong copy.");
    1.93 +      check(rncr[rnr[it]] == it, "Wrong copy.");
    1.94 +      check(frnm[it] == trnm[rnr[it]], "Wrong copy.");
    1.95 +      check(to.red(rnr[it]), "Wrong copy.");
    1.96 +    } else {
    1.97 +      check(bnr[it] == nr[it], "Wrong copy.");
    1.98 +      check(bncr[bnr[it]] == it, "Wrong copy.");
    1.99 +      check(fbnm[it] == tbnm[bnr[it]], "Wrong copy.");
   1.100 +      check(to.blue(bnr[it]), "Wrong copy.");
   1.101 +    }
   1.102 +  }
   1.103 +
   1.104 +  for (SmartBpGraph::ArcIt it(from); it != INVALID; ++it) {
   1.105 +    check(acr[ar[it]] == it, "Wrong copy.");
   1.106 +    check(fam[it] == tam[ar[it]], "Wrong copy.");
   1.107 +    check(nr[from.source(it)] == to.source(ar[it]), "Wrong copy.");
   1.108 +    check(nr[from.target(it)] == to.target(ar[it]), "Wrong copy.");
   1.109 +  }
   1.110 +
   1.111 +  for (SmartBpGraph::EdgeIt it(from); it != INVALID; ++it) {
   1.112 +    check(ecr[er[it]] == it, "Wrong copy.");
   1.113 +    check(fem[it] == tem[er[it]], "Wrong copy.");
   1.114 +    check(nr[from.u(it)] == to.u(er[it]) || nr[from.u(it)] == to.v(er[it]),
   1.115 +          "Wrong copy.");
   1.116 +    check(nr[from.v(it)] == to.u(er[it]) || nr[from.v(it)] == to.v(er[it]),
   1.117 +          "Wrong copy.");
   1.118 +    check((from.u(it) != from.v(it)) == (to.u(er[it]) != to.v(er[it])),
   1.119 +          "Wrong copy.");
   1.120 +  }
   1.121 +
   1.122 +  for (typename GR::NodeIt it(to); it != INVALID; ++it) {
   1.123 +    check(nr[ncr[it]] == it, "Wrong copy.");
   1.124 +  }
   1.125 +  for (typename GR::RedIt it(to); it != INVALID; ++it) {
   1.126 +    check(rncr[it] == ncr[it], "Wrong copy.");
   1.127 +    check(rnr[rncr[it]] == it, "Wrong copy.");
   1.128 +  }
   1.129 +  for (typename GR::BlueIt it(to); it != INVALID; ++it) {
   1.130 +    check(bncr[it] == ncr[it], "Wrong copy.");
   1.131 +    check(bnr[bncr[it]] == it, "Wrong copy.");
   1.132 +  }
   1.133 +  for (typename GR::ArcIt it(to); it != INVALID; ++it) {
   1.134 +    check(ar[acr[it]] == it, "Wrong copy.");
   1.135 +  }
   1.136 +  for (typename GR::EdgeIt it(to); it != INVALID; ++it) {
   1.137 +    check(er[ecr[it]] == it, "Wrong copy.");
   1.138 +  }
   1.139 +  check(tn == nr[fn], "Wrong copy.");
   1.140 +  check(ta == ar[fa], "Wrong copy.");
   1.141 +  check(te == er[fe], "Wrong copy.");
   1.142 +
   1.143 +  // Test repeated copy
   1.144 +  bpGraphCopy(from, to).run();
   1.145 +  
   1.146 +  check(countNodes(from) == countNodes(to), "Wrong copy.");
   1.147 +  check(countRedNodes(from) == countRedNodes(to), "Wrong copy.");
   1.148 +  check(countBlueNodes(from) == countBlueNodes(to), "Wrong copy.");
   1.149 +  check(countEdges(from) == countEdges(to), "Wrong copy.");
   1.150 +  check(countArcs(from) == countArcs(to), "Wrong copy.");
   1.151 +}
   1.152 +
   1.153  
   1.154  int main() {
   1.155    digraph_copy_test<SmartDigraph>();
   1.156 @@ -216,6 +362,8 @@
   1.157    digraph_copy_test<StaticDigraph>();
   1.158    graph_copy_test<SmartGraph>();
   1.159    graph_copy_test<ListGraph>();
   1.160 +  bpgraph_copy_test<SmartBpGraph>();
   1.161 +  bpgraph_copy_test<ListBpGraph>();
   1.162  
   1.163    return 0;
   1.164  }