test/graph_test.h
changeset 1019 4c89e925cfe2
parent 440 88ed40ad0d4f
child 1025 c8fa41fcc4a7
     1.1 --- a/test/graph_test.h	Sun Nov 14 16:35:31 2010 +0100
     1.2 +++ b/test/graph_test.h	Sun Nov 14 20:06:23 2010 +0100
     1.3 @@ -41,6 +41,30 @@
     1.4    }
     1.5  
     1.6    template<class Graph>
     1.7 +  void checkGraphRedNodeList(const Graph &G, int cnt)
     1.8 +  {
     1.9 +    typename Graph::RedIt n(G);
    1.10 +    for(int i=0;i<cnt;i++) {
    1.11 +      check(n!=INVALID,"Wrong red Node list linking.");
    1.12 +      ++n;
    1.13 +    }
    1.14 +    check(n==INVALID,"Wrong red Node list linking.");
    1.15 +    check(countRedNodes(G)==cnt,"Wrong red Node number.");
    1.16 +  }
    1.17 +
    1.18 +  template<class Graph>
    1.19 +  void checkGraphBlueNodeList(const Graph &G, int cnt)
    1.20 +  {
    1.21 +    typename Graph::BlueIt n(G);
    1.22 +    for(int i=0;i<cnt;i++) {
    1.23 +      check(n!=INVALID,"Wrong blue Node list linking.");
    1.24 +      ++n;
    1.25 +    }
    1.26 +    check(n==INVALID,"Wrong blue Node list linking.");
    1.27 +    check(countBlueNodes(G)==cnt,"Wrong blue Node number.");
    1.28 +  }
    1.29 +
    1.30 +  template<class Graph>
    1.31    void checkGraphArcList(const Graph &G, int cnt)
    1.32    {
    1.33      typename Graph::ArcIt e(G);
    1.34 @@ -166,6 +190,7 @@
    1.35  
    1.36    template <typename Graph>
    1.37    void checkNodeIds(const Graph& G) {
    1.38 +    typedef typename Graph::Node Node;
    1.39      std::set<int> values;
    1.40      for (typename Graph::NodeIt n(G); n != INVALID; ++n) {
    1.41        check(G.nodeFromId(G.id(n)) == n, "Wrong id");
    1.42 @@ -173,10 +198,40 @@
    1.43        check(G.id(n) <= G.maxNodeId(), "Wrong maximum id");
    1.44        values.insert(G.id(n));
    1.45      }
    1.46 +    check(G.maxId(Node()) <= G.maxNodeId(), "Wrong maximum id");
    1.47 +  }
    1.48 +
    1.49 +  template <typename Graph>
    1.50 +  void checkRedNodeIds(const Graph& G) {
    1.51 +    typedef typename Graph::RedNode RedNode;
    1.52 +    std::set<int> values;
    1.53 +    for (typename Graph::RedIt n(G); n != INVALID; ++n) {
    1.54 +      check(G.red(n), "Wrong partition");
    1.55 +      check(G.redId(n) == G.id(RedNode(n)), "Wrong id");
    1.56 +      check(values.find(G.redId(n)) == values.end(), "Wrong id");
    1.57 +      check(G.redId(n) <= G.maxRedId(), "Wrong maximum id");
    1.58 +      values.insert(G.id(n));
    1.59 +    }
    1.60 +    check(G.maxId(RedNode()) == G.maxRedId(), "Wrong maximum id");
    1.61 +  }
    1.62 +
    1.63 +  template <typename Graph>
    1.64 +  void checkBlueNodeIds(const Graph& G) {
    1.65 +    typedef typename Graph::BlueNode BlueNode;
    1.66 +    std::set<int> values;
    1.67 +    for (typename Graph::BlueIt n(G); n != INVALID; ++n) {
    1.68 +      check(G.blue(n), "Wrong partition");
    1.69 +      check(G.blueId(n) == G.id(BlueNode(n)), "Wrong id");
    1.70 +      check(values.find(G.blueId(n)) == values.end(), "Wrong id");
    1.71 +      check(G.blueId(n) <= G.maxBlueId(), "Wrong maximum id");
    1.72 +      values.insert(G.id(n));
    1.73 +    }
    1.74 +    check(G.maxId(BlueNode()) == G.maxBlueId(), "Wrong maximum id");
    1.75    }
    1.76  
    1.77    template <typename Graph>
    1.78    void checkArcIds(const Graph& G) {
    1.79 +    typedef typename Graph::Arc Arc;
    1.80      std::set<int> values;
    1.81      for (typename Graph::ArcIt a(G); a != INVALID; ++a) {
    1.82        check(G.arcFromId(G.id(a)) == a, "Wrong id");
    1.83 @@ -184,10 +239,12 @@
    1.84        check(G.id(a) <= G.maxArcId(), "Wrong maximum id");
    1.85        values.insert(G.id(a));
    1.86      }
    1.87 +    check(G.maxId(Arc()) <= G.maxArcId(), "Wrong maximum id");
    1.88    }
    1.89  
    1.90    template <typename Graph>
    1.91    void checkEdgeIds(const Graph& G) {
    1.92 +    typedef typename Graph::Edge Edge;
    1.93      std::set<int> values;
    1.94      for (typename Graph::EdgeIt e(G); e != INVALID; ++e) {
    1.95        check(G.edgeFromId(G.id(e)) == e, "Wrong id");
    1.96 @@ -195,6 +252,7 @@
    1.97        check(G.id(e) <= G.maxEdgeId(), "Wrong maximum id");
    1.98        values.insert(G.id(e));
    1.99      }
   1.100 +    check(G.maxId(Edge()) <= G.maxEdgeId(), "Wrong maximum id");
   1.101    }
   1.102  
   1.103    template <typename Graph>
   1.104 @@ -228,6 +286,66 @@
   1.105    }
   1.106  
   1.107    template <typename Graph>
   1.108 +  void checkGraphRedMap(const Graph& G) {
   1.109 +    typedef typename Graph::Node Node;
   1.110 +    typedef typename Graph::RedIt RedIt;
   1.111 +
   1.112 +    typedef typename Graph::template RedMap<int> IntRedMap;
   1.113 +    IntRedMap map(G, 42);
   1.114 +    for (RedIt it(G); it != INVALID; ++it) {
   1.115 +      check(map[it] == 42, "Wrong map constructor.");
   1.116 +    }
   1.117 +    int s = 0;
   1.118 +    for (RedIt it(G); it != INVALID; ++it) {
   1.119 +      map[it] = 0;
   1.120 +      check(map[it] == 0, "Wrong operator[].");
   1.121 +      map.set(it, s);
   1.122 +      check(map[it] == s, "Wrong set.");
   1.123 +      ++s;
   1.124 +    }
   1.125 +    s = s * (s - 1) / 2;
   1.126 +    for (RedIt it(G); it != INVALID; ++it) {
   1.127 +      s -= map[it];
   1.128 +    }
   1.129 +    check(s == 0, "Wrong sum.");
   1.130 +
   1.131 +    // map = constMap<Node>(12);
   1.132 +    // for (NodeIt it(G); it != INVALID; ++it) {
   1.133 +    //   check(map[it] == 12, "Wrong operator[].");
   1.134 +    // }
   1.135 +  }
   1.136 +
   1.137 +  template <typename Graph>
   1.138 +  void checkGraphBlueMap(const Graph& G) {
   1.139 +    typedef typename Graph::Node Node;
   1.140 +    typedef typename Graph::BlueIt BlueIt;
   1.141 +
   1.142 +    typedef typename Graph::template BlueMap<int> IntBlueMap;
   1.143 +    IntBlueMap map(G, 42);
   1.144 +    for (BlueIt it(G); it != INVALID; ++it) {
   1.145 +      check(map[it] == 42, "Wrong map constructor.");
   1.146 +    }
   1.147 +    int s = 0;
   1.148 +    for (BlueIt it(G); it != INVALID; ++it) {
   1.149 +      map[it] = 0;
   1.150 +      check(map[it] == 0, "Wrong operator[].");
   1.151 +      map.set(it, s);
   1.152 +      check(map[it] == s, "Wrong set.");
   1.153 +      ++s;
   1.154 +    }
   1.155 +    s = s * (s - 1) / 2;
   1.156 +    for (BlueIt it(G); it != INVALID; ++it) {
   1.157 +      s -= map[it];
   1.158 +    }
   1.159 +    check(s == 0, "Wrong sum.");
   1.160 +
   1.161 +    // map = constMap<Node>(12);
   1.162 +    // for (NodeIt it(G); it != INVALID; ++it) {
   1.163 +    //   check(map[it] == 12, "Wrong operator[].");
   1.164 +    // }
   1.165 +  }
   1.166 +
   1.167 +  template <typename Graph>
   1.168    void checkGraphArcMap(const Graph& G) {
   1.169      typedef typename Graph::Arc Arc;
   1.170      typedef typename Graph::ArcIt ArcIt;