COIN-OR::LEMON - Graph Library

Changeset 1193:c8fa41fcc4a7 in lemon for test


Ignore:
Timestamp:
12/01/11 09:05:47 (8 years ago)
Author:
Balazs Dezso <deba@…>
Branch:
default
Phase:
public
Message:

Type safe red and blue node set (#69)

Location:
test
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • test/bpgraph_test.cc

    r1189 r1193  
    4242  G.reserveEdge(3);
    4343
    44   Node
     44  RedNode
    4545    rn1 = G.addRedNode();
    4646  checkGraphNodeList(G, 1);
     
    5050  checkGraphArcList(G, 0);
    5151
    52   Node
     52  BlueNode
    5353    bn1 = G.addBlueNode(),
    5454    bn2 = G.addBlueNode();
     
    7777
    7878  Edge
    79     e2 = G.addEdge(rn1, bn1),
     79    e2 = G.addEdge(bn1, rn1),
    8080    e3 = G.addEdge(rn1, bn2);
    8181
     
    113113
    114114  BpGraph G;
    115   Node
    116     n1 = G.addRedNode(), n2 = G.addBlueNode(),
    117     n3 = G.addBlueNode(), n4 = G.addRedNode();
     115  RedNode
     116    n1 = G.addRedNode(), n4 = G.addRedNode();
     117  BlueNode
     118    n2 = G.addBlueNode(), n3 = G.addBlueNode();
    118119  Edge
    119120    e1 = G.addEdge(n1, n2), e2 = G.addEdge(n1, n3),
     
    160161
    161162  BpGraph G;
    162   Node
    163     n1 = G.addRedNode(), n2 = G.addBlueNode(),
    164     n3 = G.addBlueNode(), n4 = G.addRedNode();
     163  RedNode
     164    n1 = G.addRedNode(), n4 = G.addRedNode();
     165  BlueNode
     166    n2 = G.addBlueNode(), n3 = G.addBlueNode();
    165167  Edge
    166168    e1 = G.addEdge(n1, n2), e2 = G.addEdge(n1, n3),
     
    210212
    211213  BpGraph G;
    212   Node
    213     n1 = G.addRedNode(),
     214  RedNode
     215    n1 = G.addRedNode();
     216  BlueNode
    214217    n2 = G.addBlueNode(),
    215218    n3 = G.addBlueNode();
     
    226229  typename BpGraph::Snapshot snapshot(G);
    227230
    228   Node n4 = G.addRedNode();
     231  RedNode n4 = G.addRedNode();
    229232  G.addEdge(n4, n2);
    230233  G.addEdge(n4, n3);
     
    293296  BpGraph g;
    294297
    295   Node
    296     n1 = g.addRedNode(),
     298  RedNode
     299    n1 = g.addRedNode();
     300  BlueNode
    297301    n2 = g.addBlueNode(),
    298302    n3 = g.addBlueNode();
     
    397401  for (int i = 0; i < G.redNum(); ++i) {
    398402    check(G.red(G.redNode(i)), "Wrong node");
    399     check(G.redIndex(G.redNode(i)) == i, "Wrong index");
     403    check(G.index(G.redNode(i)) == i, "Wrong index");
    400404  }
    401405
    402406  for (int i = 0; i < G.blueNum(); ++i) {
    403407    check(G.blue(G.blueNode(i)), "Wrong node");
    404     check(G.blueIndex(G.blueNode(i)) == i, "Wrong index");
     408    check(G.index(G.blueNode(i)) == i, "Wrong index");
    405409  }
    406410
  • test/graph_copy_test.cc

    r1190 r1193  
    222222  SmartBpGraph::EdgeMap<int> fem(from);
    223223  SmartBpGraph::Node fn = INVALID;
     224  SmartBpGraph::RedNode frn = INVALID;
     225  SmartBpGraph::BlueNode fbn = INVALID;
    224226  SmartBpGraph::Arc fa = INVALID;
    225227  SmartBpGraph::Edge fe = INVALID;
    226228
    227   std::vector<SmartBpGraph::Node> frnv;
    228   for (int i = 0; i < nn; ++i) {
    229     SmartBpGraph::Node node = from.addRedNode();
     229  std::vector<SmartBpGraph::RedNode> frnv;
     230  for (int i = 0; i < nn; ++i) {
     231    SmartBpGraph::RedNode node = from.addRedNode();
    230232    frnv.push_back(node);
    231233    fnm[node] = i * i;
    232234    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();
     235    if (i == 0) {
     236      fn = node;
     237      frn = node;
     238    }
     239  }
     240
     241  std::vector<SmartBpGraph::BlueNode> fbnv;
     242  for (int i = 0; i < nn; ++i) {
     243    SmartBpGraph::BlueNode node = from.addBlueNode();
    239244    fbnv.push_back(node);
    240245    fnm[node] = i * i;
    241246    fbnm[node] = i + i;
     247    if (i == 0) fbn = node;
    242248  }
    243249
     
    261267  typename GR::template EdgeMap<int> tem(to);
    262268  typename GR::Node tn;
     269  typename GR::RedNode trn;
     270  typename GR::BlueNode tbn;
    263271  typename GR::Arc ta;
    264272  typename GR::Edge te;
    265273
    266274  SmartBpGraph::NodeMap<typename GR::Node> nr(from);
    267   SmartBpGraph::RedMap<typename GR::Node> rnr(from);
    268   SmartBpGraph::BlueMap<typename GR::Node> bnr(from);
     275  SmartBpGraph::RedMap<typename GR::RedNode> rnr(from);
     276  SmartBpGraph::BlueMap<typename GR::BlueNode> bnr(from);
    269277  SmartBpGraph::ArcMap<typename GR::Arc> ar(from);
    270278  SmartBpGraph::EdgeMap<typename GR::Edge> er(from);
    271279
    272280  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);
     281  typename GR::template RedMap<SmartBpGraph::RedNode> rncr(to);
     282  typename GR::template BlueMap<SmartBpGraph::BlueNode> bncr(to);
    275283  typename GR::template ArcMap<SmartBpGraph::Arc> acr(to);
    276284  typename GR::template EdgeMap<SmartBpGraph::Edge> ecr(to);
     
    283291    nodeCrossRef(ncr).redCrossRef(rncr).blueCrossRef(bncr).
    284292    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();
    286295
    287296  check(countNodes(from) == countNodes(to), "Wrong copy.");
     
    294303    check(ncr[nr[it]] == it, "Wrong copy.");
    295304    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     }
     305  }
     306
     307  for (SmartBpGraph::RedIt it(from); it != INVALID; ++it) {
     308    check(ncr[nr[it]] == it, "Wrong copy.");
     309    check(fnm[it] == tnm[nr[it]], "Wrong copy.");
     310    check(rnr[it] == nr[it], "Wrong copy.");
     311    check(rncr[rnr[it]] == it, "Wrong copy.");
     312    check(frnm[it] == trnm[rnr[it]], "Wrong copy.");
     313    check(to.red(rnr[it]), "Wrong copy.");
     314  }
     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.");
    307323  }
    308324
     
    343359  }
    344360  check(tn == nr[fn], "Wrong copy.");
     361  check(trn == rnr[frn], "Wrong copy.");
     362  check(tbn == bnr[fbn], "Wrong copy.");
    345363  check(ta == ar[fa], "Wrong copy.");
    346364  check(te == er[fe], "Wrong copy.");
  • test/graph_test.h

    r1187 r1193  
    4747    for(int i=0;i<cnt;i++) {
    4848      check(n!=INVALID,"Wrong red Node list linking.");
     49      check(G.red(n),"Wrong node set check.");
     50      check(!G.blue(n),"Wrong node set check.");
     51      typename Graph::Node nn = n;
     52      check(G.asRedNodeUnsafe(nn) == n,"Wrong node conversion.");
     53      check(G.asRedNode(nn) == n,"Wrong node conversion.");
     54      check(G.asBlueNode(nn) == INVALID,"Wrong node conversion.");
     55      std::pair<typename Graph::RedNode, typename Graph::BlueNode> rbn =
     56        G.asRedBlueNode(nn);
     57      check(rbn.first == n,"Wrong node conversion.");
     58      check(rbn.second == INVALID,"Wrong node conversion.");
    4959      ++n;
    5060    }
     
    5969    for(int i=0;i<cnt;i++) {
    6070      check(n!=INVALID,"Wrong blue Node list linking.");
     71      check(G.blue(n),"Wrong node set check.");
     72      check(!G.red(n),"Wrong node set check.");
     73      typename Graph::Node nn = n;
     74      check(G.asBlueNodeUnsafe(nn) == n,"Wrong node conversion.");
     75      check(G.asBlueNode(nn) == n,"Wrong node conversion.");
     76      check(G.asRedNode(nn) == INVALID,"Wrong node conversion.");
     77      std::pair<typename Graph::RedNode, typename Graph::BlueNode> rbn =
     78        G.asRedBlueNode(nn);
     79      check(rbn.first == INVALID,"Wrong node conversion.");
     80      check(rbn.second == n,"Wrong node conversion.");
    6181      ++n;
    6282    }
     
    208228    for (typename Graph::RedIt n(G); n != INVALID; ++n) {
    209229      check(G.red(n), "Wrong partition");
    210       check(G.redId(n) == G.id(RedNode(n)), "Wrong id");
    211       check(values.find(G.redId(n)) == values.end(), "Wrong id");
    212       check(G.redId(n) <= G.maxRedId(), "Wrong maximum id");
     230      check(values.find(G.id(n)) == values.end(), "Wrong id");
     231      check(G.id(n) <= G.maxRedId(), "Wrong maximum id");
    213232      values.insert(G.id(n));
    214233    }
     
    222241    for (typename Graph::BlueIt n(G); n != INVALID; ++n) {
    223242      check(G.blue(n), "Wrong partition");
    224       check(G.blueId(n) == G.id(BlueNode(n)), "Wrong id");
    225       check(values.find(G.blueId(n)) == values.end(), "Wrong id");
    226       check(G.blueId(n) <= G.maxBlueId(), "Wrong maximum id");
     243      check(values.find(G.id(n)) == values.end(), "Wrong id");
     244      check(G.id(n) <= G.maxBlueId(), "Wrong maximum id");
    227245      values.insert(G.id(n));
    228246    }
Note: See TracChangeset for help on using the changeset viewer.