COIN-OR::LEMON - Graph Library

Changeset 1187:4c89e925cfe2 in lemon for test/graph_test.h


Ignore:
Timestamp:
11/14/10 20:06:23 (13 years ago)
Author:
Balazs Dezso <deba@…>
Branch:
default
Phase:
public
Message:

SmartBpGraph? implementation (#69)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • test/graph_test.h

    r463 r1187  
    4242
    4343  template<class Graph>
     44  void checkGraphRedNodeList(const Graph &G, int cnt)
     45  {
     46    typename Graph::RedIt n(G);
     47    for(int i=0;i<cnt;i++) {
     48      check(n!=INVALID,"Wrong red Node list linking.");
     49      ++n;
     50    }
     51    check(n==INVALID,"Wrong red Node list linking.");
     52    check(countRedNodes(G)==cnt,"Wrong red Node number.");
     53  }
     54
     55  template<class Graph>
     56  void checkGraphBlueNodeList(const Graph &G, int cnt)
     57  {
     58    typename Graph::BlueIt n(G);
     59    for(int i=0;i<cnt;i++) {
     60      check(n!=INVALID,"Wrong blue Node list linking.");
     61      ++n;
     62    }
     63    check(n==INVALID,"Wrong blue Node list linking.");
     64    check(countBlueNodes(G)==cnt,"Wrong blue Node number.");
     65  }
     66
     67  template<class Graph>
    4468  void checkGraphArcList(const Graph &G, int cnt)
    4569  {
     
    167191  template <typename Graph>
    168192  void checkNodeIds(const Graph& G) {
     193    typedef typename Graph::Node Node;
    169194    std::set<int> values;
    170195    for (typename Graph::NodeIt n(G); n != INVALID; ++n) {
     
    174199      values.insert(G.id(n));
    175200    }
     201    check(G.maxId(Node()) <= G.maxNodeId(), "Wrong maximum id");
     202  }
     203
     204  template <typename Graph>
     205  void checkRedNodeIds(const Graph& G) {
     206    typedef typename Graph::RedNode RedNode;
     207    std::set<int> values;
     208    for (typename Graph::RedIt n(G); n != INVALID; ++n) {
     209      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");
     213      values.insert(G.id(n));
     214    }
     215    check(G.maxId(RedNode()) == G.maxRedId(), "Wrong maximum id");
     216  }
     217
     218  template <typename Graph>
     219  void checkBlueNodeIds(const Graph& G) {
     220    typedef typename Graph::BlueNode BlueNode;
     221    std::set<int> values;
     222    for (typename Graph::BlueIt n(G); n != INVALID; ++n) {
     223      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");
     227      values.insert(G.id(n));
     228    }
     229    check(G.maxId(BlueNode()) == G.maxBlueId(), "Wrong maximum id");
    176230  }
    177231
    178232  template <typename Graph>
    179233  void checkArcIds(const Graph& G) {
     234    typedef typename Graph::Arc Arc;
    180235    std::set<int> values;
    181236    for (typename Graph::ArcIt a(G); a != INVALID; ++a) {
     
    185240      values.insert(G.id(a));
    186241    }
     242    check(G.maxId(Arc()) <= G.maxArcId(), "Wrong maximum id");
    187243  }
    188244
    189245  template <typename Graph>
    190246  void checkEdgeIds(const Graph& G) {
     247    typedef typename Graph::Edge Edge;
    191248    std::set<int> values;
    192249    for (typename Graph::EdgeIt e(G); e != INVALID; ++e) {
     
    196253      values.insert(G.id(e));
    197254    }
     255    check(G.maxId(Edge()) <= G.maxEdgeId(), "Wrong maximum id");
    198256  }
    199257
     
    229287
    230288  template <typename Graph>
     289  void checkGraphRedMap(const Graph& G) {
     290    typedef typename Graph::Node Node;
     291    typedef typename Graph::RedIt RedIt;
     292
     293    typedef typename Graph::template RedMap<int> IntRedMap;
     294    IntRedMap map(G, 42);
     295    for (RedIt it(G); it != INVALID; ++it) {
     296      check(map[it] == 42, "Wrong map constructor.");
     297    }
     298    int s = 0;
     299    for (RedIt it(G); it != INVALID; ++it) {
     300      map[it] = 0;
     301      check(map[it] == 0, "Wrong operator[].");
     302      map.set(it, s);
     303      check(map[it] == s, "Wrong set.");
     304      ++s;
     305    }
     306    s = s * (s - 1) / 2;
     307    for (RedIt it(G); it != INVALID; ++it) {
     308      s -= map[it];
     309    }
     310    check(s == 0, "Wrong sum.");
     311
     312    // map = constMap<Node>(12);
     313    // for (NodeIt it(G); it != INVALID; ++it) {
     314    //   check(map[it] == 12, "Wrong operator[].");
     315    // }
     316  }
     317
     318  template <typename Graph>
     319  void checkGraphBlueMap(const Graph& G) {
     320    typedef typename Graph::Node Node;
     321    typedef typename Graph::BlueIt BlueIt;
     322
     323    typedef typename Graph::template BlueMap<int> IntBlueMap;
     324    IntBlueMap map(G, 42);
     325    for (BlueIt it(G); it != INVALID; ++it) {
     326      check(map[it] == 42, "Wrong map constructor.");
     327    }
     328    int s = 0;
     329    for (BlueIt it(G); it != INVALID; ++it) {
     330      map[it] = 0;
     331      check(map[it] == 0, "Wrong operator[].");
     332      map.set(it, s);
     333      check(map[it] == s, "Wrong set.");
     334      ++s;
     335    }
     336    s = s * (s - 1) / 2;
     337    for (BlueIt it(G); it != INVALID; ++it) {
     338      s -= map[it];
     339    }
     340    check(s == 0, "Wrong sum.");
     341
     342    // map = constMap<Node>(12);
     343    // for (NodeIt it(G); it != INVALID; ++it) {
     344    //   check(map[it] == 12, "Wrong operator[].");
     345    // }
     346  }
     347
     348  template <typename Graph>
    231349  void checkGraphArcMap(const Graph& G) {
    232350    typedef typename Graph::Arc Arc;
Note: See TracChangeset for help on using the changeset viewer.