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