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 ↑
Show white space 6 line context
... ...
@@ -26,2 +26,4 @@
26 26
#include <lemon/smart_graph.h>
27
#include <lemon/adaptors.h>
28
#include <lemon/dfs.h>
27 29

	
... ...
@@ -64,2 +66,8 @@
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()
... ...
@@ -355,2 +363,32 @@
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
  }
... ...
@@ -429,2 +467,49 @@
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
0 comments (0 inline)