Extend maps_test.cc (#302)
authorPeter Kovacs <kpeter@inf.elte.hu>
Fri, 25 Sep 2009 12:12:37 +0200
changeset 770acdd0bd75a55
parent 769 b52189c479fb
child 771 d8073df341f6
Extend maps_test.cc (#302)
test/maps_test.cc
     1.1 --- a/test/maps_test.cc	Sun Aug 02 17:22:43 2009 +0200
     1.2 +++ b/test/maps_test.cc	Fri Sep 25 12:12:37 2009 +0200
     1.3 @@ -24,6 +24,8 @@
     1.4  #include <lemon/maps.h>
     1.5  #include <lemon/list_graph.h>
     1.6  #include <lemon/smart_graph.h>
     1.7 +#include <lemon/adaptors.h>
     1.8 +#include <lemon/dfs.h>
     1.9  
    1.10  #include "test_tools.h"
    1.11  
    1.12 @@ -62,6 +64,12 @@
    1.13  typedef ReadWriteMap<A, bool> BoolWriteMap;
    1.14  typedef ReferenceMap<A, bool, bool&, const bool&> BoolRefMap;
    1.15  
    1.16 +template<typename Map1, typename Map2, typename ItemIt>
    1.17 +void compareMap(const Map1& map1, const Map2& map2, ItemIt it) {
    1.18 +  for (; it != INVALID; ++it)
    1.19 +    check(map1[it] == map2[it], "The maps are not equal");
    1.20 +}
    1.21 +
    1.22  int main()
    1.23  {
    1.24    // Map concepts
    1.25 @@ -353,6 +361,36 @@
    1.26      for ( LoggerBoolMap<vec::iterator>::Iterator it = map2.begin();
    1.27            it != map2.end(); ++it )
    1.28        check(v1[i++] == *it, "Something is wrong with LoggerBoolMap");
    1.29 +    
    1.30 +    typedef ListDigraph Graph;
    1.31 +    DIGRAPH_TYPEDEFS(Graph);
    1.32 +    Graph gr;
    1.33 +
    1.34 +    Node n0 = gr.addNode();
    1.35 +    Node n1 = gr.addNode();
    1.36 +    Node n2 = gr.addNode();
    1.37 +    Node n3 = gr.addNode();
    1.38 +    
    1.39 +    gr.addArc(n3, n0);
    1.40 +    gr.addArc(n3, n2);
    1.41 +    gr.addArc(n0, n2);
    1.42 +    gr.addArc(n2, n1);
    1.43 +    gr.addArc(n0, n1);
    1.44 +    
    1.45 +    {
    1.46 +      std::vector<Node> v;
    1.47 +      dfs(gr).processedMap(loggerBoolMap(std::back_inserter(v))).run();
    1.48 +
    1.49 +      check(v.size()==4 && v[0]==n1 && v[1]==n2 && v[2]==n0 && v[3]==n3,
    1.50 +            "Something is wrong with LoggerBoolMap");
    1.51 +    }
    1.52 +    {
    1.53 +      std::vector<Node> v(countNodes(gr));
    1.54 +      dfs(gr).processedMap(loggerBoolMap(v.begin())).run();
    1.55 +      
    1.56 +      check(v.size()==4 && v[0]==n1 && v[1]==n2 && v[2]==n0 && v[3]==n3,
    1.57 +            "Something is wrong with LoggerBoolMap");
    1.58 +    }
    1.59    }
    1.60    
    1.61    // IdMap, RangeIdMap
    1.62 @@ -427,6 +465,53 @@
    1.63      check(armap.inverse()[0] == a3, "Wrong RangeIdMap::InverseMap");
    1.64    }
    1.65    
    1.66 +  // SourceMap, TargetMap, ForwardMap, BackwardMap, InDegMap, OutDegMap
    1.67 +  {
    1.68 +    typedef ListGraph Graph;
    1.69 +    GRAPH_TYPEDEFS(Graph);
    1.70 +    
    1.71 +    checkConcept<ReadMap<Arc, Node>, SourceMap<Graph> >();
    1.72 +    checkConcept<ReadMap<Arc, Node>, TargetMap<Graph> >();
    1.73 +    checkConcept<ReadMap<Edge, Arc>, ForwardMap<Graph> >();
    1.74 +    checkConcept<ReadMap<Edge, Arc>, BackwardMap<Graph> >();
    1.75 +    checkConcept<ReadMap<Node, int>, InDegMap<Graph> >();
    1.76 +    checkConcept<ReadMap<Node, int>, OutDegMap<Graph> >();
    1.77 +
    1.78 +    Graph gr;
    1.79 +    Node n0 = gr.addNode();
    1.80 +    Node n1 = gr.addNode();
    1.81 +    Node n2 = gr.addNode();
    1.82 +    
    1.83 +    gr.addEdge(n0,n1);
    1.84 +    gr.addEdge(n1,n2);
    1.85 +    gr.addEdge(n0,n2);
    1.86 +    gr.addEdge(n2,n1);
    1.87 +    gr.addEdge(n1,n2);
    1.88 +    gr.addEdge(n0,n1);
    1.89 +    
    1.90 +    for (EdgeIt e(gr); e != INVALID; ++e) {
    1.91 +      check(forwardMap(gr)[e] == gr.direct(e, true), "Wrong ForwardMap");
    1.92 +      check(backwardMap(gr)[e] == gr.direct(e, false), "Wrong BackwardMap");
    1.93 +    }
    1.94 +    
    1.95 +    compareMap(sourceMap(orienter(gr, constMap<Edge, bool>(true))),
    1.96 +               targetMap(orienter(gr, constMap<Edge, bool>(false))),
    1.97 +               EdgeIt(gr));
    1.98 +
    1.99 +    typedef Orienter<Graph, const ConstMap<Edge, bool> > Digraph;
   1.100 +    Digraph dgr(gr, constMap<Edge, bool>(true));
   1.101 +    OutDegMap<Digraph> odm(dgr);
   1.102 +    InDegMap<Digraph> idm(dgr);
   1.103 +    
   1.104 +    check(odm[n0] == 3 && odm[n1] == 2 && odm[n2] == 1, "Wrong OutDegMap");
   1.105 +    check(idm[n0] == 0 && idm[n1] == 3 && idm[n2] == 3, "Wrong InDegMap");
   1.106 +   
   1.107 +    gr.addEdge(n2, n0);
   1.108 +
   1.109 +    check(odm[n0] == 3 && odm[n1] == 2 && odm[n2] == 2, "Wrong OutDegMap");
   1.110 +    check(idm[n0] == 1 && idm[n1] == 3 && idm[n2] == 3, "Wrong InDegMap");
   1.111 +  }
   1.112 +  
   1.113    // CrossRefMap
   1.114    {
   1.115      typedef ListDigraph Graph;