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 24 line context
... ...
@@ -15,24 +15,26 @@
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;
... ...
@@ -53,24 +55,30 @@
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

	
... ...
@@ -344,24 +352,54 @@
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
    
... ...
@@ -418,24 +456,71 @@
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
    
0 comments (0 inline)