test/graph_test.h
changeset 1189 a12cca3ad15a
parent 463 88ed40ad0d4f
child 1193 c8fa41fcc4a7
equal deleted inserted replaced
6:6bbb55c41210 7:8e9fd58a134e
    39     check(n==INVALID,"Wrong Node list linking.");
    39     check(n==INVALID,"Wrong Node list linking.");
    40     check(countNodes(G)==cnt,"Wrong Node number.");
    40     check(countNodes(G)==cnt,"Wrong Node number.");
    41   }
    41   }
    42 
    42 
    43   template<class Graph>
    43   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>
    44   void checkGraphArcList(const Graph &G, int cnt)
    68   void checkGraphArcList(const Graph &G, int cnt)
    45   {
    69   {
    46     typename Graph::ArcIt e(G);
    70     typename Graph::ArcIt e(G);
    47     for(int i=0;i<cnt;i++) {
    71     for(int i=0;i<cnt;i++) {
    48       check(e!=INVALID,"Wrong Arc list linking.");
    72       check(e!=INVALID,"Wrong Arc list linking.");
   164     }
   188     }
   165   }
   189   }
   166 
   190 
   167   template <typename Graph>
   191   template <typename Graph>
   168   void checkNodeIds(const Graph& G) {
   192   void checkNodeIds(const Graph& G) {
       
   193     typedef typename Graph::Node Node;
   169     std::set<int> values;
   194     std::set<int> values;
   170     for (typename Graph::NodeIt n(G); n != INVALID; ++n) {
   195     for (typename Graph::NodeIt n(G); n != INVALID; ++n) {
   171       check(G.nodeFromId(G.id(n)) == n, "Wrong id");
   196       check(G.nodeFromId(G.id(n)) == n, "Wrong id");
   172       check(values.find(G.id(n)) == values.end(), "Wrong id");
   197       check(values.find(G.id(n)) == values.end(), "Wrong id");
   173       check(G.id(n) <= G.maxNodeId(), "Wrong maximum id");
   198       check(G.id(n) <= G.maxNodeId(), "Wrong maximum id");
   174       values.insert(G.id(n));
   199       values.insert(G.id(n));
   175     }
   200     }
       
   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");
   176   }
   230   }
   177 
   231 
   178   template <typename Graph>
   232   template <typename Graph>
   179   void checkArcIds(const Graph& G) {
   233   void checkArcIds(const Graph& G) {
       
   234     typedef typename Graph::Arc Arc;
   180     std::set<int> values;
   235     std::set<int> values;
   181     for (typename Graph::ArcIt a(G); a != INVALID; ++a) {
   236     for (typename Graph::ArcIt a(G); a != INVALID; ++a) {
   182       check(G.arcFromId(G.id(a)) == a, "Wrong id");
   237       check(G.arcFromId(G.id(a)) == a, "Wrong id");
   183       check(values.find(G.id(a)) == values.end(), "Wrong id");
   238       check(values.find(G.id(a)) == values.end(), "Wrong id");
   184       check(G.id(a) <= G.maxArcId(), "Wrong maximum id");
   239       check(G.id(a) <= G.maxArcId(), "Wrong maximum id");
   185       values.insert(G.id(a));
   240       values.insert(G.id(a));
   186     }
   241     }
       
   242     check(G.maxId(Arc()) <= G.maxArcId(), "Wrong maximum id");
   187   }
   243   }
   188 
   244 
   189   template <typename Graph>
   245   template <typename Graph>
   190   void checkEdgeIds(const Graph& G) {
   246   void checkEdgeIds(const Graph& G) {
       
   247     typedef typename Graph::Edge Edge;
   191     std::set<int> values;
   248     std::set<int> values;
   192     for (typename Graph::EdgeIt e(G); e != INVALID; ++e) {
   249     for (typename Graph::EdgeIt e(G); e != INVALID; ++e) {
   193       check(G.edgeFromId(G.id(e)) == e, "Wrong id");
   250       check(G.edgeFromId(G.id(e)) == e, "Wrong id");
   194       check(values.find(G.id(e)) == values.end(), "Wrong id");
   251       check(values.find(G.id(e)) == values.end(), "Wrong id");
   195       check(G.id(e) <= G.maxEdgeId(), "Wrong maximum id");
   252       check(G.id(e) <= G.maxEdgeId(), "Wrong maximum id");
   196       values.insert(G.id(e));
   253       values.insert(G.id(e));
   197     }
   254     }
       
   255     check(G.maxId(Edge()) <= G.maxEdgeId(), "Wrong maximum id");
   198   }
   256   }
   199 
   257 
   200   template <typename Graph>
   258   template <typename Graph>
   201   void checkGraphNodeMap(const Graph& G) {
   259   void checkGraphNodeMap(const Graph& G) {
   202     typedef typename Graph::Node Node;
   260     typedef typename Graph::Node Node;
   226     //   check(map[it] == 12, "Wrong operator[].");
   284     //   check(map[it] == 12, "Wrong operator[].");
   227     // }
   285     // }
   228   }
   286   }
   229 
   287 
   230   template <typename Graph>
   288   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>
   231   void checkGraphArcMap(const Graph& G) {
   349   void checkGraphArcMap(const Graph& G) {
   232     typedef typename Graph::Arc Arc;
   350     typedef typename Graph::Arc Arc;
   233     typedef typename Graph::ArcIt ArcIt;
   351     typedef typename Graph::ArcIt ArcIt;
   234 
   352 
   235     typedef typename Graph::template ArcMap<int> IntArcMap;
   353     typedef typename Graph::template ArcMap<int> IntArcMap;