COIN-OR::LEMON - Graph Library

Ticket #302: 302-acdd0bd75a55.patch

File 302-acdd0bd75a55.patch, 3.7 KB (added by Peter Kovacs, 10 years ago)
  • test/maps_test.cc

    # HG changeset patch
    # User Peter Kovacs <kpeter@inf.elte.hu>
    # Date 1253873557 -7200
    # Node ID acdd0bd75a55f3844e955aa37a69522457b193a7
    # Parent  b52189c479fb3b19a4757d246b140d7220250b90
    Extend maps_test.cc (#302)
    
    diff --git a/test/maps_test.cc b/test/maps_test.cc
    a b  
    2424#include <lemon/maps.h>
    2525#include <lemon/list_graph.h>
    2626#include <lemon/smart_graph.h>
     27#include <lemon/adaptors.h>
     28#include <lemon/dfs.h>
    2729
    2830#include "test_tools.h"
    2931
     
    6264typedef ReadWriteMap<A, bool> BoolWriteMap;
    6365typedef ReferenceMap<A, bool, bool&, const bool&> BoolRefMap;
    6466
     67template<typename Map1, typename Map2, typename ItemIt>
     68void 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
    6573int main()
    6674{
    6775  // Map concepts
     
    353361    for ( LoggerBoolMap<vec::iterator>::Iterator it = map2.begin();
    354362          it != map2.end(); ++it )
    355363      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    }
    356394  }
    357395 
    358396  // IdMap, RangeIdMap
     
    427465    check(armap.inverse()[0] == a3, "Wrong RangeIdMap::InverseMap");
    428466  }
    429467 
     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 
    430515  // CrossRefMap
    431516  {
    432517    typedef ListDigraph Graph;