test/maps_test.cc
changeset 1095 ad40f7d32846
parent 998 7fdaa05a69a1
parent 1083 3e711ee55d31
child 1086 97f1760dcd13
     1.1 --- a/test/maps_test.cc	Fri Aug 09 11:07:27 2013 +0200
     1.2 +++ b/test/maps_test.cc	Sun Aug 11 15:28:12 2013 +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-2010
     1.9   * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    1.10   * (Egervary Research Group on Combinatorial Optimization, EGRES).
    1.11   *
    1.12 @@ -23,6 +23,10 @@
    1.13  #include <lemon/concepts/maps.h>
    1.14  #include <lemon/maps.h>
    1.15  #include <lemon/list_graph.h>
    1.16 +#include <lemon/smart_graph.h>
    1.17 +#include <lemon/adaptors.h>
    1.18 +#include <lemon/dfs.h>
    1.19 +#include <algorithm>
    1.20  
    1.21  #include "test_tools.h"
    1.22  
    1.23 @@ -34,9 +38,22 @@
    1.24  struct B {};
    1.25  
    1.26  class C {
    1.27 -  int x;
    1.28 +  int _x;
    1.29  public:
    1.30 -  C(int _x) : x(_x) {}
    1.31 +  C(int x) : _x(x) {}
    1.32 +  int get() const { return _x; }
    1.33 +};
    1.34 +inline bool operator<(C c1, C c2) { return c1.get() < c2.get(); }
    1.35 +inline bool operator==(C c1, C c2) { return c1.get() == c2.get(); }
    1.36 +
    1.37 +C createC(int x) { return C(x); }
    1.38 +
    1.39 +template <typename T>
    1.40 +class Less {
    1.41 +  T _t;
    1.42 +public:
    1.43 +  Less(T t): _t(t) {}
    1.44 +  bool operator()(const T& t) const { return t < _t; }
    1.45  };
    1.46  
    1.47  class F {
    1.48 @@ -53,6 +70,14 @@
    1.49  
    1.50  int binc(int a, B) { return a+1; }
    1.51  
    1.52 +template <typename T>
    1.53 +class Sum {
    1.54 +  T& _sum;
    1.55 +public:
    1.56 +  Sum(T& sum) : _sum(sum) {}
    1.57 +  void operator()(const T& t) { _sum += t; }
    1.58 +};
    1.59 +
    1.60  typedef ReadMap<A, double> DoubleMap;
    1.61  typedef ReadWriteMap<A, double> DoubleWriteMap;
    1.62  typedef ReferenceMap<A, double, double&, const double&> DoubleRefMap;
    1.63 @@ -348,6 +373,10 @@
    1.64    // LoggerBoolMap
    1.65    {
    1.66      typedef std::vector<int> vec;
    1.67 +    checkConcept<WriteMap<int, bool>, LoggerBoolMap<vec::iterator> >();
    1.68 +    checkConcept<WriteMap<int, bool>,
    1.69 +                 LoggerBoolMap<std::back_insert_iterator<vec> > >();
    1.70 +
    1.71      vec v1;
    1.72      vec v2(10);
    1.73      LoggerBoolMap<std::back_insert_iterator<vec> >
    1.74 @@ -367,8 +396,158 @@
    1.75      for ( LoggerBoolMap<vec::iterator>::Iterator it = map2.begin();
    1.76            it != map2.end(); ++it )
    1.77        check(v1[i++] == *it, "Something is wrong with LoggerBoolMap");
    1.78 +
    1.79 +    typedef ListDigraph Graph;
    1.80 +    DIGRAPH_TYPEDEFS(Graph);
    1.81 +    Graph gr;
    1.82 +
    1.83 +    Node n0 = gr.addNode();
    1.84 +    Node n1 = gr.addNode();
    1.85 +    Node n2 = gr.addNode();
    1.86 +    Node n3 = gr.addNode();
    1.87 +
    1.88 +    gr.addArc(n3, n0);
    1.89 +    gr.addArc(n3, n2);
    1.90 +    gr.addArc(n0, n2);
    1.91 +    gr.addArc(n2, n1);
    1.92 +    gr.addArc(n0, n1);
    1.93 +
    1.94 +    {
    1.95 +      std::vector<Node> v;
    1.96 +      dfs(gr).processedMap(loggerBoolMap(std::back_inserter(v))).run();
    1.97 +
    1.98 +      check(v.size()==4 && v[0]==n1 && v[1]==n2 && v[2]==n0 && v[3]==n3,
    1.99 +            "Something is wrong with LoggerBoolMap");
   1.100 +    }
   1.101 +    {
   1.102 +      std::vector<Node> v(countNodes(gr));
   1.103 +      dfs(gr).processedMap(loggerBoolMap(v.begin())).run();
   1.104 +
   1.105 +      check(v.size()==4 && v[0]==n1 && v[1]==n2 && v[2]==n0 && v[3]==n3,
   1.106 +            "Something is wrong with LoggerBoolMap");
   1.107 +    }
   1.108    }
   1.109 -  
   1.110 +
   1.111 +  // IdMap, RangeIdMap
   1.112 +  {
   1.113 +    typedef ListDigraph Graph;
   1.114 +    DIGRAPH_TYPEDEFS(Graph);
   1.115 +
   1.116 +    checkConcept<ReadMap<Node, int>, IdMap<Graph, Node> >();
   1.117 +    checkConcept<ReadMap<Arc, int>, IdMap<Graph, Arc> >();
   1.118 +    checkConcept<ReadMap<Node, int>, RangeIdMap<Graph, Node> >();
   1.119 +    checkConcept<ReadMap<Arc, int>, RangeIdMap<Graph, Arc> >();
   1.120 +
   1.121 +    Graph gr;
   1.122 +    IdMap<Graph, Node> nmap(gr);
   1.123 +    IdMap<Graph, Arc> amap(gr);
   1.124 +    RangeIdMap<Graph, Node> nrmap(gr);
   1.125 +    RangeIdMap<Graph, Arc> armap(gr);
   1.126 +
   1.127 +    Node n0 = gr.addNode();
   1.128 +    Node n1 = gr.addNode();
   1.129 +    Node n2 = gr.addNode();
   1.130 +
   1.131 +    Arc a0 = gr.addArc(n0, n1);
   1.132 +    Arc a1 = gr.addArc(n0, n2);
   1.133 +    Arc a2 = gr.addArc(n2, n1);
   1.134 +    Arc a3 = gr.addArc(n2, n0);
   1.135 +
   1.136 +    check(nmap[n0] == gr.id(n0) && nmap(gr.id(n0)) == n0, "Wrong IdMap");
   1.137 +    check(nmap[n1] == gr.id(n1) && nmap(gr.id(n1)) == n1, "Wrong IdMap");
   1.138 +    check(nmap[n2] == gr.id(n2) && nmap(gr.id(n2)) == n2, "Wrong IdMap");
   1.139 +
   1.140 +    check(amap[a0] == gr.id(a0) && amap(gr.id(a0)) == a0, "Wrong IdMap");
   1.141 +    check(amap[a1] == gr.id(a1) && amap(gr.id(a1)) == a1, "Wrong IdMap");
   1.142 +    check(amap[a2] == gr.id(a2) && amap(gr.id(a2)) == a2, "Wrong IdMap");
   1.143 +    check(amap[a3] == gr.id(a3) && amap(gr.id(a3)) == a3, "Wrong IdMap");
   1.144 +
   1.145 +    check(nmap.inverse()[gr.id(n0)] == n0, "Wrong IdMap::InverseMap");
   1.146 +    check(amap.inverse()[gr.id(a0)] == a0, "Wrong IdMap::InverseMap");
   1.147 +
   1.148 +    check(nrmap.size() == 3 && armap.size() == 4,
   1.149 +          "Wrong RangeIdMap::size()");
   1.150 +
   1.151 +    check(nrmap[n0] == 0 && nrmap(0) == n0, "Wrong RangeIdMap");
   1.152 +    check(nrmap[n1] == 1 && nrmap(1) == n1, "Wrong RangeIdMap");
   1.153 +    check(nrmap[n2] == 2 && nrmap(2) == n2, "Wrong RangeIdMap");
   1.154 +
   1.155 +    check(armap[a0] == 0 && armap(0) == a0, "Wrong RangeIdMap");
   1.156 +    check(armap[a1] == 1 && armap(1) == a1, "Wrong RangeIdMap");
   1.157 +    check(armap[a2] == 2 && armap(2) == a2, "Wrong RangeIdMap");
   1.158 +    check(armap[a3] == 3 && armap(3) == a3, "Wrong RangeIdMap");
   1.159 +
   1.160 +    check(nrmap.inverse()[0] == n0, "Wrong RangeIdMap::InverseMap");
   1.161 +    check(armap.inverse()[0] == a0, "Wrong RangeIdMap::InverseMap");
   1.162 +
   1.163 +    gr.erase(n1);
   1.164 +
   1.165 +    if (nrmap[n0] == 1) nrmap.swap(n0, n2);
   1.166 +    nrmap.swap(n2, n0);
   1.167 +    if (armap[a1] == 1) armap.swap(a1, a3);
   1.168 +    armap.swap(a3, a1);
   1.169 +
   1.170 +    check(nrmap.size() == 2 && armap.size() == 2,
   1.171 +          "Wrong RangeIdMap::size()");
   1.172 +
   1.173 +    check(nrmap[n0] == 1 && nrmap(1) == n0, "Wrong RangeIdMap");
   1.174 +    check(nrmap[n2] == 0 && nrmap(0) == n2, "Wrong RangeIdMap");
   1.175 +
   1.176 +    check(armap[a1] == 1 && armap(1) == a1, "Wrong RangeIdMap");
   1.177 +    check(armap[a3] == 0 && armap(0) == a3, "Wrong RangeIdMap");
   1.178 +
   1.179 +    check(nrmap.inverse()[0] == n2, "Wrong RangeIdMap::InverseMap");
   1.180 +    check(armap.inverse()[0] == a3, "Wrong RangeIdMap::InverseMap");
   1.181 +  }
   1.182 +
   1.183 +  // SourceMap, TargetMap, ForwardMap, BackwardMap, InDegMap, OutDegMap
   1.184 +  {
   1.185 +    typedef ListGraph Graph;
   1.186 +    GRAPH_TYPEDEFS(Graph);
   1.187 +
   1.188 +    checkConcept<ReadMap<Arc, Node>, SourceMap<Graph> >();
   1.189 +    checkConcept<ReadMap<Arc, Node>, TargetMap<Graph> >();
   1.190 +    checkConcept<ReadMap<Edge, Arc>, ForwardMap<Graph> >();
   1.191 +    checkConcept<ReadMap<Edge, Arc>, BackwardMap<Graph> >();
   1.192 +    checkConcept<ReadMap<Node, int>, InDegMap<Graph> >();
   1.193 +    checkConcept<ReadMap<Node, int>, OutDegMap<Graph> >();
   1.194 +
   1.195 +    Graph gr;
   1.196 +    Node n0 = gr.addNode();
   1.197 +    Node n1 = gr.addNode();
   1.198 +    Node n2 = gr.addNode();
   1.199 +
   1.200 +    gr.addEdge(n0,n1);
   1.201 +    gr.addEdge(n1,n2);
   1.202 +    gr.addEdge(n0,n2);
   1.203 +    gr.addEdge(n2,n1);
   1.204 +    gr.addEdge(n1,n2);
   1.205 +    gr.addEdge(n0,n1);
   1.206 +
   1.207 +    for (EdgeIt e(gr); e != INVALID; ++e) {
   1.208 +      check(forwardMap(gr)[e] == gr.direct(e, true), "Wrong ForwardMap");
   1.209 +      check(backwardMap(gr)[e] == gr.direct(e, false), "Wrong BackwardMap");
   1.210 +    }
   1.211 +
   1.212 +    check(mapCompare(gr,
   1.213 +          sourceMap(orienter(gr, constMap<Edge, bool>(true))),
   1.214 +          targetMap(orienter(gr, constMap<Edge, bool>(false)))),
   1.215 +          "Wrong SourceMap or TargetMap");
   1.216 +
   1.217 +    typedef Orienter<Graph, const ConstMap<Edge, bool> > Digraph;
   1.218 +    Digraph dgr(gr, constMap<Edge, bool>(true));
   1.219 +    OutDegMap<Digraph> odm(dgr);
   1.220 +    InDegMap<Digraph> idm(dgr);
   1.221 +
   1.222 +    check(odm[n0] == 3 && odm[n1] == 2 && odm[n2] == 1, "Wrong OutDegMap");
   1.223 +    check(idm[n0] == 0 && idm[n1] == 3 && idm[n2] == 3, "Wrong InDegMap");
   1.224 +
   1.225 +    gr.addEdge(n2, n0);
   1.226 +
   1.227 +    check(odm[n0] == 3 && odm[n1] == 2 && odm[n2] == 2, "Wrong OutDegMap");
   1.228 +    check(idm[n0] == 1 && idm[n1] == 3 && idm[n2] == 3, "Wrong InDegMap");
   1.229 +  }
   1.230 +
   1.231    // CrossRefMap
   1.232    {
   1.233      typedef ListDigraph Graph;
   1.234 @@ -376,16 +555,83 @@
   1.235  
   1.236      checkConcept<ReadWriteMap<Node, int>,
   1.237                   CrossRefMap<Graph, Node, int> >();
   1.238 -    
   1.239 +    checkConcept<ReadWriteMap<Node, bool>,
   1.240 +                 CrossRefMap<Graph, Node, bool> >();
   1.241 +    checkConcept<ReadWriteMap<Node, double>,
   1.242 +                 CrossRefMap<Graph, Node, double> >();
   1.243 +
   1.244 +    Graph gr;
   1.245 +    typedef CrossRefMap<Graph, Node, char> CRMap;
   1.246 +    CRMap map(gr);
   1.247 +
   1.248 +    Node n0 = gr.addNode();
   1.249 +    Node n1 = gr.addNode();
   1.250 +    Node n2 = gr.addNode();
   1.251 +
   1.252 +    map.set(n0, 'A');
   1.253 +    map.set(n1, 'B');
   1.254 +    map.set(n2, 'C');
   1.255 +
   1.256 +    check(map[n0] == 'A' && map('A') == n0 && map.inverse()['A'] == n0,
   1.257 +          "Wrong CrossRefMap");
   1.258 +    check(map[n1] == 'B' && map('B') == n1 && map.inverse()['B'] == n1,
   1.259 +          "Wrong CrossRefMap");
   1.260 +    check(map[n2] == 'C' && map('C') == n2 && map.inverse()['C'] == n2,
   1.261 +          "Wrong CrossRefMap");
   1.262 +    check(map.count('A') == 1 && map.count('B') == 1 && map.count('C') == 1,
   1.263 +          "Wrong CrossRefMap::count()");
   1.264 +
   1.265 +    CRMap::ValueIt it = map.beginValue();
   1.266 +    check(*it++ == 'A' && *it++ == 'B' && *it++ == 'C' &&
   1.267 +          it == map.endValue(), "Wrong value iterator");
   1.268 +
   1.269 +    map.set(n2, 'A');
   1.270 +
   1.271 +    check(map[n0] == 'A' && map[n1] == 'B' && map[n2] == 'A',
   1.272 +          "Wrong CrossRefMap");
   1.273 +    check(map('A') == n0 && map.inverse()['A'] == n0, "Wrong CrossRefMap");
   1.274 +    check(map('B') == n1 && map.inverse()['B'] == n1, "Wrong CrossRefMap");
   1.275 +    check(map('C') == INVALID && map.inverse()['C'] == INVALID,
   1.276 +          "Wrong CrossRefMap");
   1.277 +    check(map.count('A') == 2 && map.count('B') == 1 && map.count('C') == 0,
   1.278 +          "Wrong CrossRefMap::count()");
   1.279 +
   1.280 +    it = map.beginValue();
   1.281 +    check(*it++ == 'A' && *it++ == 'A' && *it++ == 'B' &&
   1.282 +          it == map.endValue(), "Wrong value iterator");
   1.283 +
   1.284 +    map.set(n0, 'C');
   1.285 +
   1.286 +    check(map[n0] == 'C' && map[n1] == 'B' && map[n2] == 'A',
   1.287 +          "Wrong CrossRefMap");
   1.288 +    check(map('A') == n2 && map.inverse()['A'] == n2, "Wrong CrossRefMap");
   1.289 +    check(map('B') == n1 && map.inverse()['B'] == n1, "Wrong CrossRefMap");
   1.290 +    check(map('C') == n0 && map.inverse()['C'] == n0, "Wrong CrossRefMap");
   1.291 +    check(map.count('A') == 1 && map.count('B') == 1 && map.count('C') == 1,
   1.292 +          "Wrong CrossRefMap::count()");
   1.293 +
   1.294 +    it = map.beginValue();
   1.295 +    check(*it++ == 'A' && *it++ == 'B' && *it++ == 'C' &&
   1.296 +          it == map.endValue(), "Wrong value iterator");
   1.297 +  }
   1.298 +
   1.299 +  // CrossRefMap
   1.300 +  {
   1.301 +    typedef SmartDigraph Graph;
   1.302 +    DIGRAPH_TYPEDEFS(Graph);
   1.303 +
   1.304 +    checkConcept<ReadWriteMap<Node, int>,
   1.305 +                 CrossRefMap<Graph, Node, int> >();
   1.306 +
   1.307      Graph gr;
   1.308      typedef CrossRefMap<Graph, Node, char> CRMap;
   1.309      typedef CRMap::ValueIterator ValueIt;
   1.310      CRMap map(gr);
   1.311 -    
   1.312 +
   1.313      Node n0 = gr.addNode();
   1.314      Node n1 = gr.addNode();
   1.315      Node n2 = gr.addNode();
   1.316 -    
   1.317 +
   1.318      map.set(n0, 'A');
   1.319      map.set(n1, 'B');
   1.320      map.set(n2, 'C');
   1.321 @@ -403,5 +649,373 @@
   1.322            it == map.endValue(), "Wrong value iterator");
   1.323    }
   1.324  
   1.325 +  // Iterable bool map
   1.326 +  {
   1.327 +    typedef SmartGraph Graph;
   1.328 +    typedef SmartGraph::Node Item;
   1.329 +
   1.330 +    typedef IterableBoolMap<SmartGraph, SmartGraph::Node> Ibm;
   1.331 +    checkConcept<ReferenceMap<Item, bool, bool&, const bool&>, Ibm>();
   1.332 +
   1.333 +    const int num = 10;
   1.334 +    Graph g;
   1.335 +    Ibm map0(g, true);
   1.336 +    std::vector<Item> items;
   1.337 +    for (int i = 0; i < num; ++i) {
   1.338 +      items.push_back(g.addNode());
   1.339 +    }
   1.340 +
   1.341 +    Ibm map1(g, true);
   1.342 +    int n = 0;
   1.343 +    for (Ibm::TrueIt it(map1); it != INVALID; ++it) {
   1.344 +      check(map1[static_cast<Item>(it)], "Wrong TrueIt");
   1.345 +      ++n;
   1.346 +    }
   1.347 +    check(n == num, "Wrong number");
   1.348 +
   1.349 +    n = 0;
   1.350 +    for (Ibm::ItemIt it(map1, true); it != INVALID; ++it) {
   1.351 +        check(map1[static_cast<Item>(it)], "Wrong ItemIt for true");
   1.352 +        ++n;
   1.353 +    }
   1.354 +    check(n == num, "Wrong number");
   1.355 +    check(Ibm::FalseIt(map1) == INVALID, "Wrong FalseIt");
   1.356 +    check(Ibm::ItemIt(map1, false) == INVALID, "Wrong ItemIt for false");
   1.357 +
   1.358 +    map1[items[5]] = true;
   1.359 +
   1.360 +    n = 0;
   1.361 +    for (Ibm::ItemIt it(map1, true); it != INVALID; ++it) {
   1.362 +        check(map1[static_cast<Item>(it)], "Wrong ItemIt for true");
   1.363 +        ++n;
   1.364 +    }
   1.365 +    check(n == num, "Wrong number");
   1.366 +
   1.367 +    map1[items[num / 2]] = false;
   1.368 +    check(map1[items[num / 2]] == false, "Wrong map value");
   1.369 +
   1.370 +    n = 0;
   1.371 +    for (Ibm::TrueIt it(map1); it != INVALID; ++it) {
   1.372 +        check(map1[static_cast<Item>(it)], "Wrong TrueIt for true");
   1.373 +        ++n;
   1.374 +    }
   1.375 +    check(n == num - 1, "Wrong number");
   1.376 +
   1.377 +    n = 0;
   1.378 +    for (Ibm::FalseIt it(map1); it != INVALID; ++it) {
   1.379 +        check(!map1[static_cast<Item>(it)], "Wrong FalseIt for true");
   1.380 +        ++n;
   1.381 +    }
   1.382 +    check(n == 1, "Wrong number");
   1.383 +
   1.384 +    map1[items[0]] = false;
   1.385 +    check(map1[items[0]] == false, "Wrong map value");
   1.386 +
   1.387 +    map1[items[num - 1]] = false;
   1.388 +    check(map1[items[num - 1]] == false, "Wrong map value");
   1.389 +
   1.390 +    n = 0;
   1.391 +    for (Ibm::TrueIt it(map1); it != INVALID; ++it) {
   1.392 +        check(map1[static_cast<Item>(it)], "Wrong TrueIt for true");
   1.393 +        ++n;
   1.394 +    }
   1.395 +    check(n == num - 3, "Wrong number");
   1.396 +    check(map1.trueNum() == num - 3, "Wrong number");
   1.397 +
   1.398 +    n = 0;
   1.399 +    for (Ibm::FalseIt it(map1); it != INVALID; ++it) {
   1.400 +        check(!map1[static_cast<Item>(it)], "Wrong FalseIt for true");
   1.401 +        ++n;
   1.402 +    }
   1.403 +    check(n == 3, "Wrong number");
   1.404 +    check(map1.falseNum() == 3, "Wrong number");
   1.405 +  }
   1.406 +
   1.407 +  // Iterable int map
   1.408 +  {
   1.409 +    typedef SmartGraph Graph;
   1.410 +    typedef SmartGraph::Node Item;
   1.411 +    typedef IterableIntMap<SmartGraph, SmartGraph::Node> Iim;
   1.412 +
   1.413 +    checkConcept<ReferenceMap<Item, int, int&, const int&>, Iim>();
   1.414 +
   1.415 +    const int num = 10;
   1.416 +    Graph g;
   1.417 +    Iim map0(g, 0);
   1.418 +    std::vector<Item> items;
   1.419 +    for (int i = 0; i < num; ++i) {
   1.420 +      items.push_back(g.addNode());
   1.421 +    }
   1.422 +
   1.423 +    Iim map1(g);
   1.424 +    check(map1.size() == 0, "Wrong size");
   1.425 +
   1.426 +    for (int i = 0; i < num; ++i) {
   1.427 +      map1[items[i]] = i;
   1.428 +    }
   1.429 +    check(map1.size() == num, "Wrong size");
   1.430 +
   1.431 +    for (int i = 0; i < num; ++i) {
   1.432 +      Iim::ItemIt it(map1, i);
   1.433 +      check(static_cast<Item>(it) == items[i], "Wrong value");
   1.434 +      ++it;
   1.435 +      check(static_cast<Item>(it) == INVALID, "Wrong value");
   1.436 +    }
   1.437 +
   1.438 +    for (int i = 0; i < num; ++i) {
   1.439 +      map1[items[i]] = i % 2;
   1.440 +    }
   1.441 +    check(map1.size() == 2, "Wrong size");
   1.442 +
   1.443 +    int n = 0;
   1.444 +    for (Iim::ItemIt it(map1, 0); it != INVALID; ++it) {
   1.445 +      check(map1[static_cast<Item>(it)] == 0, "Wrong value");
   1.446 +      ++n;
   1.447 +    }
   1.448 +    check(n == (num + 1) / 2, "Wrong number");
   1.449 +
   1.450 +    for (Iim::ItemIt it(map1, 1); it != INVALID; ++it) {
   1.451 +      check(map1[static_cast<Item>(it)] == 1, "Wrong value");
   1.452 +      ++n;
   1.453 +    }
   1.454 +    check(n == num, "Wrong number");
   1.455 +
   1.456 +  }
   1.457 +
   1.458 +  // Iterable value map
   1.459 +  {
   1.460 +    typedef SmartGraph Graph;
   1.461 +    typedef SmartGraph::Node Item;
   1.462 +    typedef IterableValueMap<SmartGraph, SmartGraph::Node, double> Ivm;
   1.463 +
   1.464 +    checkConcept<ReadWriteMap<Item, double>, Ivm>();
   1.465 +
   1.466 +    const int num = 10;
   1.467 +    Graph g;
   1.468 +    Ivm map0(g, 0.0);
   1.469 +    std::vector<Item> items;
   1.470 +    for (int i = 0; i < num; ++i) {
   1.471 +      items.push_back(g.addNode());
   1.472 +    }
   1.473 +
   1.474 +    Ivm map1(g, 0.0);
   1.475 +    check(distance(map1.beginValue(), map1.endValue()) == 1, "Wrong size");
   1.476 +    check(*map1.beginValue() == 0.0, "Wrong value");
   1.477 +
   1.478 +    for (int i = 0; i < num; ++i) {
   1.479 +      map1.set(items[i], static_cast<double>(i));
   1.480 +    }
   1.481 +    check(distance(map1.beginValue(), map1.endValue()) == num, "Wrong size");
   1.482 +
   1.483 +    for (int i = 0; i < num; ++i) {
   1.484 +      Ivm::ItemIt it(map1, static_cast<double>(i));
   1.485 +      check(static_cast<Item>(it) == items[i], "Wrong value");
   1.486 +      ++it;
   1.487 +      check(static_cast<Item>(it) == INVALID, "Wrong value");
   1.488 +    }
   1.489 +
   1.490 +    for (Ivm::ValueIt vit = map1.beginValue();
   1.491 +         vit != map1.endValue(); ++vit) {
   1.492 +      check(map1[static_cast<Item>(Ivm::ItemIt(map1, *vit))] == *vit,
   1.493 +            "Wrong ValueIt");
   1.494 +    }
   1.495 +
   1.496 +    for (int i = 0; i < num; ++i) {
   1.497 +      map1.set(items[i], static_cast<double>(i % 2));
   1.498 +    }
   1.499 +    check(distance(map1.beginValue(), map1.endValue()) == 2, "Wrong size");
   1.500 +
   1.501 +    int n = 0;
   1.502 +    for (Ivm::ItemIt it(map1, 0.0); it != INVALID; ++it) {
   1.503 +      check(map1[static_cast<Item>(it)] == 0.0, "Wrong value");
   1.504 +      ++n;
   1.505 +    }
   1.506 +    check(n == (num + 1) / 2, "Wrong number");
   1.507 +
   1.508 +    for (Ivm::ItemIt it(map1, 1.0); it != INVALID; ++it) {
   1.509 +      check(map1[static_cast<Item>(it)] == 1.0, "Wrong value");
   1.510 +      ++n;
   1.511 +    }
   1.512 +    check(n == num, "Wrong number");
   1.513 +
   1.514 +  }
   1.515 +
   1.516 +  // Graph map utilities:
   1.517 +  // mapMin(), mapMax(), mapMinValue(), mapMaxValue()
   1.518 +  // mapFind(), mapFindIf(), mapCount(), mapCountIf()
   1.519 +  // mapCopy(), mapCompare(), mapFill()
   1.520 +  {
   1.521 +    DIGRAPH_TYPEDEFS(SmartDigraph);
   1.522 +
   1.523 +    SmartDigraph g;
   1.524 +    Node n1 = g.addNode();
   1.525 +    Node n2 = g.addNode();
   1.526 +    Node n3 = g.addNode();
   1.527 +
   1.528 +    SmartDigraph::NodeMap<int> map1(g);
   1.529 +    SmartDigraph::ArcMap<char> map2(g);
   1.530 +    ConstMap<Node, A> cmap1 = A();
   1.531 +    ConstMap<Arc, C> cmap2 = C(0);
   1.532 +
   1.533 +    map1[n1] = 10;
   1.534 +    map1[n2] = 5;
   1.535 +    map1[n3] = 12;
   1.536 +
   1.537 +    // mapMin(), mapMax(), mapMinValue(), mapMaxValue()
   1.538 +    check(mapMin(g, map1) == n2, "Wrong mapMin()");
   1.539 +    check(mapMax(g, map1) == n3, "Wrong mapMax()");
   1.540 +    check(mapMin(g, map1, std::greater<int>()) == n3, "Wrong mapMin()");
   1.541 +    check(mapMax(g, map1, std::greater<int>()) == n2, "Wrong mapMax()");
   1.542 +    check(mapMinValue(g, map1) == 5, "Wrong mapMinValue()");
   1.543 +    check(mapMaxValue(g, map1) == 12, "Wrong mapMaxValue()");
   1.544 +
   1.545 +    check(mapMin(g, map2) == INVALID, "Wrong mapMin()");
   1.546 +    check(mapMax(g, map2) == INVALID, "Wrong mapMax()");
   1.547 +
   1.548 +    check(mapMin(g, cmap1) != INVALID, "Wrong mapMin()");
   1.549 +    check(mapMax(g, cmap2) == INVALID, "Wrong mapMax()");
   1.550 +
   1.551 +    Arc a1 = g.addArc(n1, n2);
   1.552 +    Arc a2 = g.addArc(n1, n3);
   1.553 +    Arc a3 = g.addArc(n2, n3);
   1.554 +    Arc a4 = g.addArc(n3, n1);
   1.555 +
   1.556 +    map2[a1] = 'b';
   1.557 +    map2[a2] = 'a';
   1.558 +    map2[a3] = 'b';
   1.559 +    map2[a4] = 'c';
   1.560 +
   1.561 +    // mapMin(), mapMax(), mapMinValue(), mapMaxValue()
   1.562 +    check(mapMin(g, map2) == a2, "Wrong mapMin()");
   1.563 +    check(mapMax(g, map2) == a4, "Wrong mapMax()");
   1.564 +    check(mapMin(g, map2, std::greater<int>()) == a4, "Wrong mapMin()");
   1.565 +    check(mapMax(g, map2, std::greater<int>()) == a2, "Wrong mapMax()");
   1.566 +    check(mapMinValue(g, map2, std::greater<int>()) == 'c',
   1.567 +          "Wrong mapMinValue()");
   1.568 +    check(mapMaxValue(g, map2, std::greater<int>()) == 'a',
   1.569 +          "Wrong mapMaxValue()");
   1.570 +
   1.571 +    check(mapMin(g, cmap1) != INVALID, "Wrong mapMin()");
   1.572 +    check(mapMax(g, cmap2) != INVALID, "Wrong mapMax()");
   1.573 +    check(mapMaxValue(g, cmap2) == C(0), "Wrong mapMaxValue()");
   1.574 +
   1.575 +    check(mapMin(g, composeMap(functorToMap(&createC), map2)) == a2,
   1.576 +          "Wrong mapMin()");
   1.577 +    check(mapMax(g, composeMap(functorToMap(&createC), map2)) == a4,
   1.578 +          "Wrong mapMax()");
   1.579 +    check(mapMinValue(g, composeMap(functorToMap(&createC), map2)) == C('a'),
   1.580 +          "Wrong mapMinValue()");
   1.581 +    check(mapMaxValue(g, composeMap(functorToMap(&createC), map2)) == C('c'),
   1.582 +          "Wrong mapMaxValue()");
   1.583 +
   1.584 +    // mapFind(), mapFindIf()
   1.585 +    check(mapFind(g, map1, 5) == n2, "Wrong mapFind()");
   1.586 +    check(mapFind(g, map1, 6) == INVALID, "Wrong mapFind()");
   1.587 +    check(mapFind(g, map2, 'a') == a2, "Wrong mapFind()");
   1.588 +    check(mapFind(g, map2, 'e') == INVALID, "Wrong mapFind()");
   1.589 +    check(mapFind(g, cmap2, C(0)) == ArcIt(g), "Wrong mapFind()");
   1.590 +    check(mapFind(g, cmap2, C(1)) == INVALID, "Wrong mapFind()");
   1.591 +
   1.592 +    check(mapFindIf(g, map1, Less<int>(7)) == n2,
   1.593 +          "Wrong mapFindIf()");
   1.594 +    check(mapFindIf(g, map1, Less<int>(5)) == INVALID,
   1.595 +          "Wrong mapFindIf()");
   1.596 +    check(mapFindIf(g, map2, Less<char>('d')) == ArcIt(g),
   1.597 +          "Wrong mapFindIf()");
   1.598 +    check(mapFindIf(g, map2, Less<char>('a')) == INVALID,
   1.599 +          "Wrong mapFindIf()");
   1.600 +
   1.601 +    // mapCount(), mapCountIf()
   1.602 +    check(mapCount(g, map1, 5) == 1, "Wrong mapCount()");
   1.603 +    check(mapCount(g, map1, 6) == 0, "Wrong mapCount()");
   1.604 +    check(mapCount(g, map2, 'a') == 1, "Wrong mapCount()");
   1.605 +    check(mapCount(g, map2, 'b') == 2, "Wrong mapCount()");
   1.606 +    check(mapCount(g, map2, 'e') == 0, "Wrong mapCount()");
   1.607 +    check(mapCount(g, cmap2, C(0)) == 4, "Wrong mapCount()");
   1.608 +    check(mapCount(g, cmap2, C(1)) == 0, "Wrong mapCount()");
   1.609 +
   1.610 +    check(mapCountIf(g, map1, Less<int>(11)) == 2,
   1.611 +          "Wrong mapCountIf()");
   1.612 +    check(mapCountIf(g, map1, Less<int>(13)) == 3,
   1.613 +          "Wrong mapCountIf()");
   1.614 +    check(mapCountIf(g, map1, Less<int>(5)) == 0,
   1.615 +          "Wrong mapCountIf()");
   1.616 +    check(mapCountIf(g, map2, Less<char>('d')) == 4,
   1.617 +          "Wrong mapCountIf()");
   1.618 +    check(mapCountIf(g, map2, Less<char>('c')) == 3,
   1.619 +          "Wrong mapCountIf()");
   1.620 +    check(mapCountIf(g, map2, Less<char>('a')) == 0,
   1.621 +          "Wrong mapCountIf()");
   1.622 +
   1.623 +    // MapIt, ConstMapIt
   1.624 +/*
   1.625 +These tests can be used after applying bugfix #330
   1.626 +    typedef SmartDigraph::NodeMap<int>::MapIt MapIt;
   1.627 +    typedef SmartDigraph::NodeMap<int>::ConstMapIt ConstMapIt;
   1.628 +    check(*std::min_element(MapIt(map1), MapIt(INVALID)) == 5,
   1.629 +          "Wrong NodeMap<>::MapIt");
   1.630 +    check(*std::max_element(ConstMapIt(map1), ConstMapIt(INVALID)) == 12,
   1.631 +          "Wrong NodeMap<>::MapIt");
   1.632 +
   1.633 +    int sum = 0;
   1.634 +    std::for_each(MapIt(map1), MapIt(INVALID), Sum<int>(sum));
   1.635 +    check(sum == 27, "Wrong NodeMap<>::MapIt");
   1.636 +    std::for_each(ConstMapIt(map1), ConstMapIt(INVALID), Sum<int>(sum));
   1.637 +    check(sum == 54, "Wrong NodeMap<>::ConstMapIt");
   1.638 +*/
   1.639 +
   1.640 +    // mapCopy(), mapCompare(), mapFill()
   1.641 +    check(mapCompare(g, map1, map1), "Wrong mapCompare()");
   1.642 +    check(mapCompare(g, cmap2, cmap2), "Wrong mapCompare()");
   1.643 +    check(mapCompare(g, map1, shiftMap(map1, 0)), "Wrong mapCompare()");
   1.644 +    check(mapCompare(g, map2, scaleMap(map2, 1)), "Wrong mapCompare()");
   1.645 +    check(!mapCompare(g, map1, shiftMap(map1, 1)), "Wrong mapCompare()");
   1.646 +
   1.647 +    SmartDigraph::NodeMap<int> map3(g, 0);
   1.648 +    SmartDigraph::ArcMap<char> map4(g, 'a');
   1.649 +
   1.650 +    check(!mapCompare(g, map1, map3), "Wrong mapCompare()");
   1.651 +    check(!mapCompare(g, map2, map4), "Wrong mapCompare()");
   1.652 +
   1.653 +    mapCopy(g, map1, map3);
   1.654 +    mapCopy(g, map2, map4);
   1.655 +
   1.656 +    check(mapCompare(g, map1, map3), "Wrong mapCompare() or mapCopy()");
   1.657 +    check(mapCompare(g, map2, map4), "Wrong mapCompare() or mapCopy()");
   1.658 +
   1.659 +    Undirector<SmartDigraph> ug(g);
   1.660 +    Undirector<SmartDigraph>::EdgeMap<char> umap1(ug, 'x');
   1.661 +    Undirector<SmartDigraph>::ArcMap<double> umap2(ug, 3.14);
   1.662 +
   1.663 +    check(!mapCompare(g, map2, umap1), "Wrong mapCompare() or mapCopy()");
   1.664 +    check(!mapCompare(g, umap1, map2), "Wrong mapCompare() or mapCopy()");
   1.665 +    check(!mapCompare(ug, map2, umap1), "Wrong mapCompare() or mapCopy()");
   1.666 +    check(!mapCompare(ug, umap1, map2), "Wrong mapCompare() or mapCopy()");
   1.667 +
   1.668 +    mapCopy(g, map2, umap1);
   1.669 +
   1.670 +    check(mapCompare(g, map2, umap1), "Wrong mapCompare() or mapCopy()");
   1.671 +    check(mapCompare(g, umap1, map2), "Wrong mapCompare() or mapCopy()");
   1.672 +    check(mapCompare(ug, map2, umap1), "Wrong mapCompare() or mapCopy()");
   1.673 +    check(mapCompare(ug, umap1, map2), "Wrong mapCompare() or mapCopy()");
   1.674 +
   1.675 +    mapCopy(g, map2, umap1);
   1.676 +    mapCopy(g, umap1, map2);
   1.677 +    mapCopy(ug, map2, umap1);
   1.678 +    mapCopy(ug, umap1, map2);
   1.679 +
   1.680 +    check(!mapCompare(ug, umap1, umap2), "Wrong mapCompare() or mapCopy()");
   1.681 +    mapCopy(ug, umap1, umap2);
   1.682 +    check(mapCompare(ug, umap1, umap2), "Wrong mapCompare() or mapCopy()");
   1.683 +
   1.684 +    check(!mapCompare(g, map1, constMap<Node>(2)), "Wrong mapCompare()");
   1.685 +    mapFill(g, map1, 2);
   1.686 +    check(mapCompare(g, constMap<Node>(2), map1), "Wrong mapFill()");
   1.687 +
   1.688 +    check(!mapCompare(g, map2, constMap<Arc>('z')), "Wrong mapCompare()");
   1.689 +    mapCopy(g, constMap<Arc>('z'), map2);
   1.690 +    check(mapCompare(g, constMap<Arc>('z'), map2), "Wrong mapCopy()");
   1.691 +  }
   1.692 +
   1.693    return 0;
   1.694  }