test/graph_test.h
changeset 1402 3c00344f49c9
parent 1195 8b2b9e61d8ce
child 1337 4add05447ca0
     1.1 --- a/test/graph_test.h	Mon Jul 16 16:21:40 2018 +0200
     1.2 +++ b/test/graph_test.h	Wed Oct 17 19:14:07 2018 +0200
     1.3 @@ -2,7 +2,7 @@
     1.4   *
     1.5   * This file is a part of LEMON, a generic C++ optimization library.
     1.6   *
     1.7 - * Copyright (C) 2003-2009
     1.8 + * Copyright (C) 2003-2013
     1.9   * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    1.10   * (Egervary Research Group on Combinatorial Optimization, EGRES).
    1.11   *
    1.12 @@ -41,6 +41,42 @@
    1.13    }
    1.14  
    1.15    template<class Graph>
    1.16 +  void checkGraphRedNodeList(const Graph &G, int cnt)
    1.17 +  {
    1.18 +    typename Graph::RedNodeIt n(G);
    1.19 +    for(int i=0;i<cnt;i++) {
    1.20 +      check(n!=INVALID,"Wrong red Node list linking.");
    1.21 +      check(G.red(n),"Wrong node set check.");
    1.22 +      check(!G.blue(n),"Wrong node set check.");
    1.23 +      typename Graph::Node nn = n;
    1.24 +      check(G.asRedNodeUnsafe(nn) == n,"Wrong node conversion.");
    1.25 +      check(G.asRedNode(nn) == n,"Wrong node conversion.");
    1.26 +      check(G.asBlueNode(nn) == INVALID,"Wrong node conversion.");
    1.27 +      ++n;
    1.28 +    }
    1.29 +    check(n==INVALID,"Wrong red Node list linking.");
    1.30 +    check(countRedNodes(G)==cnt,"Wrong red Node number.");
    1.31 +  }
    1.32 +
    1.33 +  template<class Graph>
    1.34 +  void checkGraphBlueNodeList(const Graph &G, int cnt)
    1.35 +  {
    1.36 +    typename Graph::BlueNodeIt n(G);
    1.37 +    for(int i=0;i<cnt;i++) {
    1.38 +      check(n!=INVALID,"Wrong blue Node list linking.");
    1.39 +      check(G.blue(n),"Wrong node set check.");
    1.40 +      check(!G.red(n),"Wrong node set check.");
    1.41 +      typename Graph::Node nn = n;
    1.42 +      check(G.asBlueNodeUnsafe(nn) == n,"Wrong node conversion.");
    1.43 +      check(G.asBlueNode(nn) == n,"Wrong node conversion.");
    1.44 +      check(G.asRedNode(nn) == INVALID,"Wrong node conversion.");
    1.45 +      ++n;
    1.46 +    }
    1.47 +    check(n==INVALID,"Wrong blue Node list linking.");
    1.48 +    check(countBlueNodes(G)==cnt,"Wrong blue Node number.");
    1.49 +  }
    1.50 +
    1.51 +  template<class Graph>
    1.52    void checkGraphArcList(const Graph &G, int cnt)
    1.53    {
    1.54      typename Graph::ArcIt e(G);
    1.55 @@ -166,6 +202,7 @@
    1.56  
    1.57    template <typename Graph>
    1.58    void checkNodeIds(const Graph& G) {
    1.59 +    typedef typename Graph::Node Node;
    1.60      std::set<int> values;
    1.61      for (typename Graph::NodeIt n(G); n != INVALID; ++n) {
    1.62        check(G.nodeFromId(G.id(n)) == n, "Wrong id");
    1.63 @@ -173,10 +210,38 @@
    1.64        check(G.id(n) <= G.maxNodeId(), "Wrong maximum id");
    1.65        values.insert(G.id(n));
    1.66      }
    1.67 +    check(G.maxId(Node()) <= G.maxNodeId(), "Wrong maximum id");
    1.68 +  }
    1.69 +
    1.70 +  template <typename Graph>
    1.71 +  void checkRedNodeIds(const Graph& G) {
    1.72 +    typedef typename Graph::RedNode RedNode;
    1.73 +    std::set<int> values;
    1.74 +    for (typename Graph::RedNodeIt n(G); n != INVALID; ++n) {
    1.75 +      check(G.red(n), "Wrong partition");
    1.76 +      check(values.find(G.id(n)) == values.end(), "Wrong id");
    1.77 +      check(G.id(n) <= G.maxRedId(), "Wrong maximum id");
    1.78 +      values.insert(G.id(n));
    1.79 +    }
    1.80 +    check(G.maxId(RedNode()) == G.maxRedId(), "Wrong maximum id");
    1.81 +  }
    1.82 +
    1.83 +  template <typename Graph>
    1.84 +  void checkBlueNodeIds(const Graph& G) {
    1.85 +    typedef typename Graph::BlueNode BlueNode;
    1.86 +    std::set<int> values;
    1.87 +    for (typename Graph::BlueNodeIt n(G); n != INVALID; ++n) {
    1.88 +      check(G.blue(n), "Wrong partition");
    1.89 +      check(values.find(G.id(n)) == values.end(), "Wrong id");
    1.90 +      check(G.id(n) <= G.maxBlueId(), "Wrong maximum id");
    1.91 +      values.insert(G.id(n));
    1.92 +    }
    1.93 +    check(G.maxId(BlueNode()) == G.maxBlueId(), "Wrong maximum id");
    1.94    }
    1.95  
    1.96    template <typename Graph>
    1.97    void checkArcIds(const Graph& G) {
    1.98 +    typedef typename Graph::Arc Arc;
    1.99      std::set<int> values;
   1.100      for (typename Graph::ArcIt a(G); a != INVALID; ++a) {
   1.101        check(G.arcFromId(G.id(a)) == a, "Wrong id");
   1.102 @@ -184,10 +249,12 @@
   1.103        check(G.id(a) <= G.maxArcId(), "Wrong maximum id");
   1.104        values.insert(G.id(a));
   1.105      }
   1.106 +    check(G.maxId(Arc()) <= G.maxArcId(), "Wrong maximum id");
   1.107    }
   1.108  
   1.109    template <typename Graph>
   1.110    void checkEdgeIds(const Graph& G) {
   1.111 +    typedef typename Graph::Edge Edge;
   1.112      std::set<int> values;
   1.113      for (typename Graph::EdgeIt e(G); e != INVALID; ++e) {
   1.114        check(G.edgeFromId(G.id(e)) == e, "Wrong id");
   1.115 @@ -195,6 +262,7 @@
   1.116        check(G.id(e) <= G.maxEdgeId(), "Wrong maximum id");
   1.117        values.insert(G.id(e));
   1.118      }
   1.119 +    check(G.maxId(Edge()) <= G.maxEdgeId(), "Wrong maximum id");
   1.120    }
   1.121  
   1.122    template <typename Graph>
   1.123 @@ -228,6 +296,66 @@
   1.124    }
   1.125  
   1.126    template <typename Graph>
   1.127 +  void checkGraphRedNodeMap(const Graph& G) {
   1.128 +    typedef typename Graph::Node Node;
   1.129 +    typedef typename Graph::RedNodeIt RedNodeIt;
   1.130 +
   1.131 +    typedef typename Graph::template RedNodeMap<int> IntRedNodeMap;
   1.132 +    IntRedNodeMap map(G, 42);
   1.133 +    for (RedNodeIt it(G); it != INVALID; ++it) {
   1.134 +      check(map[it] == 42, "Wrong map constructor.");
   1.135 +    }
   1.136 +    int s = 0;
   1.137 +    for (RedNodeIt it(G); it != INVALID; ++it) {
   1.138 +      map[it] = 0;
   1.139 +      check(map[it] == 0, "Wrong operator[].");
   1.140 +      map.set(it, s);
   1.141 +      check(map[it] == s, "Wrong set.");
   1.142 +      ++s;
   1.143 +    }
   1.144 +    s = s * (s - 1) / 2;
   1.145 +    for (RedNodeIt it(G); it != INVALID; ++it) {
   1.146 +      s -= map[it];
   1.147 +    }
   1.148 +    check(s == 0, "Wrong sum.");
   1.149 +
   1.150 +    // map = constMap<Node>(12);
   1.151 +    // for (NodeIt it(G); it != INVALID; ++it) {
   1.152 +    //   check(map[it] == 12, "Wrong operator[].");
   1.153 +    // }
   1.154 +  }
   1.155 +
   1.156 +  template <typename Graph>
   1.157 +  void checkGraphBlueNodeMap(const Graph& G) {
   1.158 +    typedef typename Graph::Node Node;
   1.159 +    typedef typename Graph::BlueNodeIt BlueNodeIt;
   1.160 +
   1.161 +    typedef typename Graph::template BlueNodeMap<int> IntBlueNodeMap;
   1.162 +    IntBlueNodeMap map(G, 42);
   1.163 +    for (BlueNodeIt it(G); it != INVALID; ++it) {
   1.164 +      check(map[it] == 42, "Wrong map constructor.");
   1.165 +    }
   1.166 +    int s = 0;
   1.167 +    for (BlueNodeIt it(G); it != INVALID; ++it) {
   1.168 +      map[it] = 0;
   1.169 +      check(map[it] == 0, "Wrong operator[].");
   1.170 +      map.set(it, s);
   1.171 +      check(map[it] == s, "Wrong set.");
   1.172 +      ++s;
   1.173 +    }
   1.174 +    s = s * (s - 1) / 2;
   1.175 +    for (BlueNodeIt it(G); it != INVALID; ++it) {
   1.176 +      s -= map[it];
   1.177 +    }
   1.178 +    check(s == 0, "Wrong sum.");
   1.179 +
   1.180 +    // map = constMap<Node>(12);
   1.181 +    // for (NodeIt it(G); it != INVALID; ++it) {
   1.182 +    //   check(map[it] == 12, "Wrong operator[].");
   1.183 +    // }
   1.184 +  }
   1.185 +
   1.186 +  template <typename Graph>
   1.187    void checkGraphArcMap(const Graph& G) {
   1.188      typedef typename Graph::Arc Arc;
   1.189      typedef typename Graph::ArcIt ArcIt;