gravatar
kpeter (Peter Kovacs)
kpeter@inf.elte.hu
Extend maps_test.cc (#302)
0 1 0
default
1 file changed with 85 insertions and 0 deletions:
↑ Collapse diff ↑
Ignore white space 192 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5 5
 * Copyright (C) 2003-2009
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 8
 *
9 9
 * Permission to use, modify and distribute this software is granted
10 10
 * provided that this copyright notice appears in all copies. For
11 11
 * precise terms see the accompanying LICENSE file.
12 12
 *
13 13
 * This software is provided "AS IS" with no warranty of any kind,
14 14
 * express or implied, and with no claim as to its suitability for any
15 15
 * purpose.
16 16
 *
17 17
 */
18 18

	
19 19
#include <deque>
20 20
#include <set>
21 21

	
22 22
#include <lemon/concept_check.h>
23 23
#include <lemon/concepts/maps.h>
24 24
#include <lemon/maps.h>
25 25
#include <lemon/list_graph.h>
26 26
#include <lemon/smart_graph.h>
27
#include <lemon/adaptors.h>
28
#include <lemon/dfs.h>
27 29

	
28 30
#include "test_tools.h"
29 31

	
30 32
using namespace lemon;
31 33
using namespace lemon::concepts;
32 34

	
33 35
struct A {};
34 36
inline bool operator<(A, A) { return true; }
35 37
struct B {};
36 38

	
37 39
class C {
38 40
  int x;
39 41
public:
40 42
  C(int _x) : x(_x) {}
41 43
};
42 44

	
43 45
class F {
44 46
public:
45 47
  typedef A argument_type;
46 48
  typedef B result_type;
47 49

	
48 50
  B operator()(const A&) const { return B(); }
49 51
private:
50 52
  F& operator=(const F&);
51 53
};
52 54

	
53 55
int func(A) { return 3; }
54 56

	
55 57
int binc(int a, B) { return a+1; }
56 58

	
57 59
typedef ReadMap<A, double> DoubleMap;
58 60
typedef ReadWriteMap<A, double> DoubleWriteMap;
59 61
typedef ReferenceMap<A, double, double&, const double&> DoubleRefMap;
60 62

	
61 63
typedef ReadMap<A, bool> BoolMap;
62 64
typedef ReadWriteMap<A, bool> BoolWriteMap;
63 65
typedef ReferenceMap<A, bool, bool&, const bool&> BoolRefMap;
64 66

	
67
template<typename Map1, typename Map2, typename ItemIt>
68
void compareMap(const Map1& map1, const Map2& map2, ItemIt it) {
69
  for (; it != INVALID; ++it)
70
    check(map1[it] == map2[it], "The maps are not equal");
71
}
72

	
65 73
int main()
66 74
{
67 75
  // Map concepts
68 76
  checkConcept<ReadMap<A,B>, ReadMap<A,B> >();
69 77
  checkConcept<ReadMap<A,C>, ReadMap<A,C> >();
70 78
  checkConcept<WriteMap<A,B>, WriteMap<A,B> >();
71 79
  checkConcept<WriteMap<A,C>, WriteMap<A,C> >();
72 80
  checkConcept<ReadWriteMap<A,B>, ReadWriteMap<A,B> >();
73 81
  checkConcept<ReadWriteMap<A,C>, ReadWriteMap<A,C> >();
74 82
  checkConcept<ReferenceMap<A,B,B&,const B&>, ReferenceMap<A,B,B&,const B&> >();
75 83
  checkConcept<ReferenceMap<A,C,C&,const C&>, ReferenceMap<A,C,C&,const C&> >();
76 84

	
77 85
  // NullMap
78 86
  {
79 87
    checkConcept<ReadWriteMap<A,B>, NullMap<A,B> >();
80 88
    NullMap<A,B> map1;
81 89
    NullMap<A,B> map2 = map1;
82 90
    map1 = nullMap<A,B>();
83 91
  }
84 92

	
85 93
  // ConstMap
86 94
  {
87 95
    checkConcept<ReadWriteMap<A,B>, ConstMap<A,B> >();
88 96
    checkConcept<ReadWriteMap<A,C>, ConstMap<A,C> >();
89 97
    ConstMap<A,B> map1;
90 98
    ConstMap<A,B> map2 = B();
91 99
    ConstMap<A,B> map3 = map1;
92 100
    map1 = constMap<A>(B());
93 101
    map1 = constMap<A,B>();
94 102
    map1.setAll(B());
95 103
    ConstMap<A,C> map4(C(1));
96 104
    ConstMap<A,C> map5 = map4;
97 105
    map4 = constMap<A>(C(2));
98 106
    map4.setAll(C(3));
99 107

	
100 108
    checkConcept<ReadWriteMap<A,int>, ConstMap<A,int> >();
101 109
    check(constMap<A>(10)[A()] == 10, "Something is wrong with ConstMap");
102 110

	
103 111
    checkConcept<ReadWriteMap<A,int>, ConstMap<A,Const<int,10> > >();
104 112
    ConstMap<A,Const<int,10> > map6;
105 113
    ConstMap<A,Const<int,10> > map7 = map6;
106 114
    map6 = constMap<A,int,10>();
107 115
    map7 = constMap<A,Const<int,10> >();
108 116
    check(map6[A()] == 10 && map7[A()] == 10,
109 117
          "Something is wrong with ConstMap");
110 118
  }
111 119

	
112 120
  // IdentityMap
113 121
  {
114 122
    checkConcept<ReadMap<A,A>, IdentityMap<A> >();
115 123
    IdentityMap<A> map1;
116 124
    IdentityMap<A> map2 = map1;
117 125
    map1 = identityMap<A>();
118 126

	
119 127
    checkConcept<ReadMap<double,double>, IdentityMap<double> >();
120 128
    check(identityMap<double>()[1.0] == 1.0 &&
121 129
          identityMap<double>()[3.14] == 3.14,
122 130
          "Something is wrong with IdentityMap");
123 131
  }
124 132

	
125 133
  // RangeMap
126 134
  {
127 135
    checkConcept<ReferenceMap<int,B,B&,const B&>, RangeMap<B> >();
128 136
    RangeMap<B> map1;
129 137
    RangeMap<B> map2(10);
130 138
    RangeMap<B> map3(10,B());
131 139
    RangeMap<B> map4 = map1;
132 140
    RangeMap<B> map5 = rangeMap<B>();
133 141
    RangeMap<B> map6 = rangeMap<B>(10);
134 142
    RangeMap<B> map7 = rangeMap(10,B());
135 143

	
136 144
    checkConcept< ReferenceMap<int, double, double&, const double&>,
137 145
                  RangeMap<double> >();
138 146
    std::vector<double> v(10, 0);
139 147
    v[5] = 100;
140 148
    RangeMap<double> map8(v);
141 149
    RangeMap<double> map9 = rangeMap(v);
142 150
    check(map9.size() == 10 && map9[2] == 0 && map9[5] == 100,
143 151
          "Something is wrong with RangeMap");
144 152
  }
145 153

	
146 154
  // SparseMap
147 155
  {
148 156
    checkConcept<ReferenceMap<A,B,B&,const B&>, SparseMap<A,B> >();
149 157
    SparseMap<A,B> map1;
150 158
    SparseMap<A,B> map2 = B();
151 159
    SparseMap<A,B> map3 = sparseMap<A,B>();
152 160
    SparseMap<A,B> map4 = sparseMap<A>(B());
153 161

	
154 162
    checkConcept< ReferenceMap<double, int, int&, const int&>,
155 163
                  SparseMap<double, int> >();
156 164
    std::map<double, int> m;
157 165
    SparseMap<double, int> map5(m);
158 166
    SparseMap<double, int> map6(m,10);
159 167
    SparseMap<double, int> map7 = sparseMap(m);
160 168
    SparseMap<double, int> map8 = sparseMap(m,10);
... ...
@@ -260,266 +268,343 @@
260 268
    check(mulMap(id,c2)[0] == 0    && mulMap(id,c2)[2]  == 6.28,
261 269
          "Something is wrong with MulMap");
262 270
    check(divMap(c2,id)[1] == 3.14 && divMap(c2,id)[2]  == 1.57,
263 271
          "Something is wrong with DivMap");
264 272

	
265 273
    checkConcept<DoubleMap, ShiftMap<DoubleMap> >();
266 274
    checkConcept<DoubleWriteMap, ShiftWriteMap<DoubleWriteMap> >();
267 275
    checkConcept<DoubleMap, ScaleMap<DoubleMap> >();
268 276
    checkConcept<DoubleWriteMap, ScaleWriteMap<DoubleWriteMap> >();
269 277
    checkConcept<DoubleMap, NegMap<DoubleMap> >();
270 278
    checkConcept<DoubleWriteMap, NegWriteMap<DoubleWriteMap> >();
271 279
    checkConcept<DoubleMap, AbsMap<DoubleMap> >();
272 280

	
273 281
    check(shiftMap(id, 2.0)[1] == 3.0 && shiftMap(id, 2.0)[10] == 12.0,
274 282
          "Something is wrong with ShiftMap");
275 283
    check(shiftWriteMap(id, 2.0)[1] == 3.0 &&
276 284
          shiftWriteMap(id, 2.0)[10] == 12.0,
277 285
          "Something is wrong with ShiftWriteMap");
278 286
    check(scaleMap(id, 2.0)[1] == 2.0 && scaleMap(id, 2.0)[10] == 20.0,
279 287
          "Something is wrong with ScaleMap");
280 288
    check(scaleWriteMap(id, 2.0)[1] == 2.0 &&
281 289
          scaleWriteMap(id, 2.0)[10] == 20.0,
282 290
          "Something is wrong with ScaleWriteMap");
283 291
    check(negMap(id)[1] == -1.0 && negMap(id)[-10] == 10.0,
284 292
          "Something is wrong with NegMap");
285 293
    check(negWriteMap(id)[1] == -1.0 && negWriteMap(id)[-10] == 10.0,
286 294
          "Something is wrong with NegWriteMap");
287 295
    check(absMap(id)[1] == 1.0 && absMap(id)[-10] == 10.0,
288 296
          "Something is wrong with AbsMap");
289 297
  }
290 298

	
291 299
  // Logical maps:
292 300
  // - TrueMap, FalseMap
293 301
  // - AndMap, OrMap
294 302
  // - NotMap, NotWriteMap
295 303
  // - EqualMap, LessMap
296 304
  {
297 305
    checkConcept<BoolMap, TrueMap<A> >();
298 306
    checkConcept<BoolMap, FalseMap<A> >();
299 307
    checkConcept<BoolMap, AndMap<BoolMap,BoolMap> >();
300 308
    checkConcept<BoolMap, OrMap<BoolMap,BoolMap> >();
301 309
    checkConcept<BoolMap, NotMap<BoolMap> >();
302 310
    checkConcept<BoolWriteMap, NotWriteMap<BoolWriteMap> >();
303 311
    checkConcept<BoolMap, EqualMap<DoubleMap,DoubleMap> >();
304 312
    checkConcept<BoolMap, LessMap<DoubleMap,DoubleMap> >();
305 313

	
306 314
    TrueMap<int> tm;
307 315
    FalseMap<int> fm;
308 316
    RangeMap<bool> rm(2);
309 317
    rm[0] = true; rm[1] = false;
310 318
    check(andMap(tm,rm)[0] && !andMap(tm,rm)[1] &&
311 319
          !andMap(fm,rm)[0] && !andMap(fm,rm)[1],
312 320
          "Something is wrong with AndMap");
313 321
    check(orMap(tm,rm)[0] && orMap(tm,rm)[1] &&
314 322
          orMap(fm,rm)[0] && !orMap(fm,rm)[1],
315 323
          "Something is wrong with OrMap");
316 324
    check(!notMap(rm)[0] && notMap(rm)[1],
317 325
          "Something is wrong with NotMap");
318 326
    check(!notWriteMap(rm)[0] && notWriteMap(rm)[1],
319 327
          "Something is wrong with NotWriteMap");
320 328

	
321 329
    ConstMap<int, double> cm(2.0);
322 330
    IdentityMap<int> im;
323 331
    ConvertMap<IdentityMap<int>, double> id(im);
324 332
    check(lessMap(id,cm)[1] && !lessMap(id,cm)[2] && !lessMap(id,cm)[3],
325 333
          "Something is wrong with LessMap");
326 334
    check(!equalMap(id,cm)[1] && equalMap(id,cm)[2] && !equalMap(id,cm)[3],
327 335
          "Something is wrong with EqualMap");
328 336
  }
329 337

	
330 338
  // LoggerBoolMap
331 339
  {
332 340
    typedef std::vector<int> vec;
333 341
    checkConcept<WriteMap<int, bool>, LoggerBoolMap<vec::iterator> >();
334 342
    checkConcept<WriteMap<int, bool>,
335 343
                 LoggerBoolMap<std::back_insert_iterator<vec> > >();
336 344

	
337 345
    vec v1;
338 346
    vec v2(10);
339 347
    LoggerBoolMap<std::back_insert_iterator<vec> >
340 348
      map1(std::back_inserter(v1));
341 349
    LoggerBoolMap<vec::iterator> map2(v2.begin());
342 350
    map1.set(10, false);
343 351
    map1.set(20, true);   map2.set(20, true);
344 352
    map1.set(30, false);  map2.set(40, false);
345 353
    map1.set(50, true);   map2.set(50, true);
346 354
    map1.set(60, true);   map2.set(60, true);
347 355
    check(v1.size() == 3 && v2.size() == 10 &&
348 356
          v1[0]==20 && v1[1]==50 && v1[2]==60 &&
349 357
          v2[0]==20 && v2[1]==50 && v2[2]==60,
350 358
          "Something is wrong with LoggerBoolMap");
351 359

	
352 360
    int i = 0;
353 361
    for ( LoggerBoolMap<vec::iterator>::Iterator it = map2.begin();
354 362
          it != map2.end(); ++it )
355 363
      check(v1[i++] == *it, "Something is wrong with LoggerBoolMap");
364
    
365
    typedef ListDigraph Graph;
366
    DIGRAPH_TYPEDEFS(Graph);
367
    Graph gr;
368

	
369
    Node n0 = gr.addNode();
370
    Node n1 = gr.addNode();
371
    Node n2 = gr.addNode();
372
    Node n3 = gr.addNode();
373
    
374
    gr.addArc(n3, n0);
375
    gr.addArc(n3, n2);
376
    gr.addArc(n0, n2);
377
    gr.addArc(n2, n1);
378
    gr.addArc(n0, n1);
379
    
380
    {
381
      std::vector<Node> v;
382
      dfs(gr).processedMap(loggerBoolMap(std::back_inserter(v))).run();
383

	
384
      check(v.size()==4 && v[0]==n1 && v[1]==n2 && v[2]==n0 && v[3]==n3,
385
            "Something is wrong with LoggerBoolMap");
386
    }
387
    {
388
      std::vector<Node> v(countNodes(gr));
389
      dfs(gr).processedMap(loggerBoolMap(v.begin())).run();
390
      
391
      check(v.size()==4 && v[0]==n1 && v[1]==n2 && v[2]==n0 && v[3]==n3,
392
            "Something is wrong with LoggerBoolMap");
393
    }
356 394
  }
357 395
  
358 396
  // IdMap, RangeIdMap
359 397
  {
360 398
    typedef ListDigraph Graph;
361 399
    DIGRAPH_TYPEDEFS(Graph);
362 400

	
363 401
    checkConcept<ReadMap<Node, int>, IdMap<Graph, Node> >();
364 402
    checkConcept<ReadMap<Arc, int>, IdMap<Graph, Arc> >();
365 403
    checkConcept<ReadMap<Node, int>, RangeIdMap<Graph, Node> >();
366 404
    checkConcept<ReadMap<Arc, int>, RangeIdMap<Graph, Arc> >();
367 405
    
368 406
    Graph gr;
369 407
    IdMap<Graph, Node> nmap(gr);
370 408
    IdMap<Graph, Arc> amap(gr);
371 409
    RangeIdMap<Graph, Node> nrmap(gr);
372 410
    RangeIdMap<Graph, Arc> armap(gr);
373 411
    
374 412
    Node n0 = gr.addNode();
375 413
    Node n1 = gr.addNode();
376 414
    Node n2 = gr.addNode();
377 415
    
378 416
    Arc a0 = gr.addArc(n0, n1);
379 417
    Arc a1 = gr.addArc(n0, n2);
380 418
    Arc a2 = gr.addArc(n2, n1);
381 419
    Arc a3 = gr.addArc(n2, n0);
382 420
    
383 421
    check(nmap[n0] == gr.id(n0) && nmap(gr.id(n0)) == n0, "Wrong IdMap");
384 422
    check(nmap[n1] == gr.id(n1) && nmap(gr.id(n1)) == n1, "Wrong IdMap");
385 423
    check(nmap[n2] == gr.id(n2) && nmap(gr.id(n2)) == n2, "Wrong IdMap");
386 424

	
387 425
    check(amap[a0] == gr.id(a0) && amap(gr.id(a0)) == a0, "Wrong IdMap");
388 426
    check(amap[a1] == gr.id(a1) && amap(gr.id(a1)) == a1, "Wrong IdMap");
389 427
    check(amap[a2] == gr.id(a2) && amap(gr.id(a2)) == a2, "Wrong IdMap");
390 428
    check(amap[a3] == gr.id(a3) && amap(gr.id(a3)) == a3, "Wrong IdMap");
391 429

	
392 430
    check(nmap.inverse()[gr.id(n0)] == n0, "Wrong IdMap::InverseMap");
393 431
    check(amap.inverse()[gr.id(a0)] == a0, "Wrong IdMap::InverseMap");
394 432
    
395 433
    check(nrmap.size() == 3 && armap.size() == 4,
396 434
          "Wrong RangeIdMap::size()");
397 435

	
398 436
    check(nrmap[n0] == 0 && nrmap(0) == n0, "Wrong RangeIdMap");
399 437
    check(nrmap[n1] == 1 && nrmap(1) == n1, "Wrong RangeIdMap");
400 438
    check(nrmap[n2] == 2 && nrmap(2) == n2, "Wrong RangeIdMap");
401 439
    
402 440
    check(armap[a0] == 0 && armap(0) == a0, "Wrong RangeIdMap");
403 441
    check(armap[a1] == 1 && armap(1) == a1, "Wrong RangeIdMap");
404 442
    check(armap[a2] == 2 && armap(2) == a2, "Wrong RangeIdMap");
405 443
    check(armap[a3] == 3 && armap(3) == a3, "Wrong RangeIdMap");
406 444

	
407 445
    check(nrmap.inverse()[0] == n0, "Wrong RangeIdMap::InverseMap");
408 446
    check(armap.inverse()[0] == a0, "Wrong RangeIdMap::InverseMap");
409 447
    
410 448
    gr.erase(n1);
411 449
    
412 450
    if (nrmap[n0] == 1) nrmap.swap(n0, n2);
413 451
    nrmap.swap(n2, n0);
414 452
    if (armap[a1] == 1) armap.swap(a1, a3);
415 453
    armap.swap(a3, a1);
416 454
    
417 455
    check(nrmap.size() == 2 && armap.size() == 2,
418 456
          "Wrong RangeIdMap::size()");
419 457

	
420 458
    check(nrmap[n0] == 1 && nrmap(1) == n0, "Wrong RangeIdMap");
421 459
    check(nrmap[n2] == 0 && nrmap(0) == n2, "Wrong RangeIdMap");
422 460
    
423 461
    check(armap[a1] == 1 && armap(1) == a1, "Wrong RangeIdMap");
424 462
    check(armap[a3] == 0 && armap(0) == a3, "Wrong RangeIdMap");
425 463

	
426 464
    check(nrmap.inverse()[0] == n2, "Wrong RangeIdMap::InverseMap");
427 465
    check(armap.inverse()[0] == a3, "Wrong RangeIdMap::InverseMap");
428 466
  }
429 467
  
468
  // SourceMap, TargetMap, ForwardMap, BackwardMap, InDegMap, OutDegMap
469
  {
470
    typedef ListGraph Graph;
471
    GRAPH_TYPEDEFS(Graph);
472
    
473
    checkConcept<ReadMap<Arc, Node>, SourceMap<Graph> >();
474
    checkConcept<ReadMap<Arc, Node>, TargetMap<Graph> >();
475
    checkConcept<ReadMap<Edge, Arc>, ForwardMap<Graph> >();
476
    checkConcept<ReadMap<Edge, Arc>, BackwardMap<Graph> >();
477
    checkConcept<ReadMap<Node, int>, InDegMap<Graph> >();
478
    checkConcept<ReadMap<Node, int>, OutDegMap<Graph> >();
479

	
480
    Graph gr;
481
    Node n0 = gr.addNode();
482
    Node n1 = gr.addNode();
483
    Node n2 = gr.addNode();
484
    
485
    gr.addEdge(n0,n1);
486
    gr.addEdge(n1,n2);
487
    gr.addEdge(n0,n2);
488
    gr.addEdge(n2,n1);
489
    gr.addEdge(n1,n2);
490
    gr.addEdge(n0,n1);
491
    
492
    for (EdgeIt e(gr); e != INVALID; ++e) {
493
      check(forwardMap(gr)[e] == gr.direct(e, true), "Wrong ForwardMap");
494
      check(backwardMap(gr)[e] == gr.direct(e, false), "Wrong BackwardMap");
495
    }
496
    
497
    compareMap(sourceMap(orienter(gr, constMap<Edge, bool>(true))),
498
               targetMap(orienter(gr, constMap<Edge, bool>(false))),
499
               EdgeIt(gr));
500

	
501
    typedef Orienter<Graph, const ConstMap<Edge, bool> > Digraph;
502
    Digraph dgr(gr, constMap<Edge, bool>(true));
503
    OutDegMap<Digraph> odm(dgr);
504
    InDegMap<Digraph> idm(dgr);
505
    
506
    check(odm[n0] == 3 && odm[n1] == 2 && odm[n2] == 1, "Wrong OutDegMap");
507
    check(idm[n0] == 0 && idm[n1] == 3 && idm[n2] == 3, "Wrong InDegMap");
508
   
509
    gr.addEdge(n2, n0);
510

	
511
    check(odm[n0] == 3 && odm[n1] == 2 && odm[n2] == 2, "Wrong OutDegMap");
512
    check(idm[n0] == 1 && idm[n1] == 3 && idm[n2] == 3, "Wrong InDegMap");
513
  }
514
  
430 515
  // CrossRefMap
431 516
  {
432 517
    typedef ListDigraph Graph;
433 518
    DIGRAPH_TYPEDEFS(Graph);
434 519

	
435 520
    checkConcept<ReadWriteMap<Node, int>,
436 521
                 CrossRefMap<Graph, Node, int> >();
437 522
    checkConcept<ReadWriteMap<Node, bool>,
438 523
                 CrossRefMap<Graph, Node, bool> >();
439 524
    checkConcept<ReadWriteMap<Node, double>,
440 525
                 CrossRefMap<Graph, Node, double> >();
441 526
    
442 527
    Graph gr;
443 528
    typedef CrossRefMap<Graph, Node, char> CRMap;
444 529
    typedef CRMap::ValueIterator ValueIt;
445 530
    CRMap map(gr);
446 531
    
447 532
    Node n0 = gr.addNode();
448 533
    Node n1 = gr.addNode();
449 534
    Node n2 = gr.addNode();
450 535
    
451 536
    map.set(n0, 'A');
452 537
    map.set(n1, 'B');
453 538
    map.set(n2, 'C');
454 539
    
455 540
    check(map[n0] == 'A' && map('A') == n0 && map.inverse()['A'] == n0,
456 541
          "Wrong CrossRefMap");
457 542
    check(map[n1] == 'B' && map('B') == n1 && map.inverse()['B'] == n1,
458 543
          "Wrong CrossRefMap");
459 544
    check(map[n2] == 'C' && map('C') == n2 && map.inverse()['C'] == n2,
460 545
          "Wrong CrossRefMap");
461 546
    check(map.count('A') == 1 && map.count('B') == 1 && map.count('C') == 1,
462 547
          "Wrong CrossRefMap::count()");
463 548
    
464 549
    ValueIt it = map.beginValue();
465 550
    check(*it++ == 'A' && *it++ == 'B' && *it++ == 'C' &&
466 551
          it == map.endValue(), "Wrong value iterator");
467 552
    
468 553
    map.set(n2, 'A');
469 554

	
470 555
    check(map[n0] == 'A' && map[n1] == 'B' && map[n2] == 'A',
471 556
          "Wrong CrossRefMap");
472 557
    check(map('A') == n0 && map.inverse()['A'] == n0, "Wrong CrossRefMap");
473 558
    check(map('B') == n1 && map.inverse()['B'] == n1, "Wrong CrossRefMap");
474 559
    check(map('C') == INVALID && map.inverse()['C'] == INVALID,
475 560
          "Wrong CrossRefMap");
476 561
    check(map.count('A') == 2 && map.count('B') == 1 && map.count('C') == 0,
477 562
          "Wrong CrossRefMap::count()");
478 563

	
479 564
    it = map.beginValue();
480 565
    check(*it++ == 'A' && *it++ == 'A' && *it++ == 'B' &&
481 566
          it == map.endValue(), "Wrong value iterator");
482 567

	
483 568
    map.set(n0, 'C');
484 569

	
485 570
    check(map[n0] == 'C' && map[n1] == 'B' && map[n2] == 'A',
486 571
          "Wrong CrossRefMap");
487 572
    check(map('A') == n2 && map.inverse()['A'] == n2, "Wrong CrossRefMap");
488 573
    check(map('B') == n1 && map.inverse()['B'] == n1, "Wrong CrossRefMap");
489 574
    check(map('C') == n0 && map.inverse()['C'] == n0, "Wrong CrossRefMap");
490 575
    check(map.count('A') == 1 && map.count('B') == 1 && map.count('C') == 1,
491 576
          "Wrong CrossRefMap::count()");
492 577

	
493 578
    it = map.beginValue();
494 579
    check(*it++ == 'A' && *it++ == 'B' && *it++ == 'C' &&
495 580
          it == map.endValue(), "Wrong value iterator");
496 581
  }
497 582

	
498 583
  // Iterable bool map
499 584
  {
500 585
    typedef SmartGraph Graph;
501 586
    typedef SmartGraph::Node Item;
502 587

	
503 588
    typedef IterableBoolMap<SmartGraph, SmartGraph::Node> Ibm;
504 589
    checkConcept<ReferenceMap<Item, bool, bool&, const bool&>, Ibm>();
505 590

	
506 591
    const int num = 10;
507 592
    Graph g;
508 593
    std::vector<Item> items;
509 594
    for (int i = 0; i < num; ++i) {
510 595
      items.push_back(g.addNode());
511 596
    }
512 597

	
513 598
    Ibm map1(g, true);
514 599
    int n = 0;
515 600
    for (Ibm::TrueIt it(map1); it != INVALID; ++it) {
516 601
      check(map1[static_cast<Item>(it)], "Wrong TrueIt");
517 602
      ++n;
518 603
    }
519 604
    check(n == num, "Wrong number");
520 605

	
521 606
    n = 0;
522 607
    for (Ibm::ItemIt it(map1, true); it != INVALID; ++it) {
523 608
        check(map1[static_cast<Item>(it)], "Wrong ItemIt for true");
524 609
        ++n;
525 610
    }
0 comments (0 inline)