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