test/maps_test.cc
changeset 894 24b3f18ed9e2
parent 789 8ddb7deabab9
child 942 633956ca9421
equal deleted inserted replaced
22:3eb5ca24e997 23:f5866f57ae2a
     1 /* -*- mode: C++; indent-tabs-mode: nil; -*-
     1 /* -*- mode: C++; indent-tabs-mode: nil; -*-
     2  *
     2  *
     3  * This file is a part of LEMON, a generic C++ optimization library.
     3  * This file is a part of LEMON, a generic C++ optimization library.
     4  *
     4  *
     5  * Copyright (C) 2003-2009
     5  * Copyright (C) 2003-2010
     6  * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
     6  * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
     7  * (Egervary Research Group on Combinatorial Optimization, EGRES).
     7  * (Egervary Research Group on Combinatorial Optimization, EGRES).
     8  *
     8  *
     9  * Permission to use, modify and distribute this software is granted
     9  * Permission to use, modify and distribute this software is granted
    10  * provided that this copyright notice appears in all copies. For
    10  * provided that this copyright notice appears in all copies. For
   223     FunctorToMap<F> map1;
   223     FunctorToMap<F> map1;
   224     FunctorToMap<F> map2 = FunctorToMap<F>(F());
   224     FunctorToMap<F> map2 = FunctorToMap<F>(F());
   225     B b = functorToMap(F())[A()];
   225     B b = functorToMap(F())[A()];
   226 
   226 
   227     checkConcept<ReadMap<A,B>, MapToFunctor<ReadMap<A,B> > >();
   227     checkConcept<ReadMap<A,B>, MapToFunctor<ReadMap<A,B> > >();
   228     MapToFunctor<ReadMap<A,B> > map = MapToFunctor<ReadMap<A,B> >(ReadMap<A,B>());
   228     MapToFunctor<ReadMap<A,B> > map =
       
   229       MapToFunctor<ReadMap<A,B> >(ReadMap<A,B>());
   229 
   230 
   230     check(functorToMap(&func)[A()] == 3,
   231     check(functorToMap(&func)[A()] == 3,
   231           "Something is wrong with FunctorToMap");
   232           "Something is wrong with FunctorToMap");
   232     check(mapToFunctor(constMap<A,int>(2))(A()) == 2,
   233     check(mapToFunctor(constMap<A,int>(2))(A()) == 2,
   233           "Something is wrong with MapToFunctor");
   234           "Something is wrong with MapToFunctor");
   375 
   376 
   376     int i = 0;
   377     int i = 0;
   377     for ( LoggerBoolMap<vec::iterator>::Iterator it = map2.begin();
   378     for ( LoggerBoolMap<vec::iterator>::Iterator it = map2.begin();
   378           it != map2.end(); ++it )
   379           it != map2.end(); ++it )
   379       check(v1[i++] == *it, "Something is wrong with LoggerBoolMap");
   380       check(v1[i++] == *it, "Something is wrong with LoggerBoolMap");
   380     
   381 
   381     typedef ListDigraph Graph;
   382     typedef ListDigraph Graph;
   382     DIGRAPH_TYPEDEFS(Graph);
   383     DIGRAPH_TYPEDEFS(Graph);
   383     Graph gr;
   384     Graph gr;
   384 
   385 
   385     Node n0 = gr.addNode();
   386     Node n0 = gr.addNode();
   386     Node n1 = gr.addNode();
   387     Node n1 = gr.addNode();
   387     Node n2 = gr.addNode();
   388     Node n2 = gr.addNode();
   388     Node n3 = gr.addNode();
   389     Node n3 = gr.addNode();
   389     
   390 
   390     gr.addArc(n3, n0);
   391     gr.addArc(n3, n0);
   391     gr.addArc(n3, n2);
   392     gr.addArc(n3, n2);
   392     gr.addArc(n0, n2);
   393     gr.addArc(n0, n2);
   393     gr.addArc(n2, n1);
   394     gr.addArc(n2, n1);
   394     gr.addArc(n0, n1);
   395     gr.addArc(n0, n1);
   395     
   396 
   396     {
   397     {
   397       std::vector<Node> v;
   398       std::vector<Node> v;
   398       dfs(gr).processedMap(loggerBoolMap(std::back_inserter(v))).run();
   399       dfs(gr).processedMap(loggerBoolMap(std::back_inserter(v))).run();
   399 
   400 
   400       check(v.size()==4 && v[0]==n1 && v[1]==n2 && v[2]==n0 && v[3]==n3,
   401       check(v.size()==4 && v[0]==n1 && v[1]==n2 && v[2]==n0 && v[3]==n3,
   401             "Something is wrong with LoggerBoolMap");
   402             "Something is wrong with LoggerBoolMap");
   402     }
   403     }
   403     {
   404     {
   404       std::vector<Node> v(countNodes(gr));
   405       std::vector<Node> v(countNodes(gr));
   405       dfs(gr).processedMap(loggerBoolMap(v.begin())).run();
   406       dfs(gr).processedMap(loggerBoolMap(v.begin())).run();
   406       
   407 
   407       check(v.size()==4 && v[0]==n1 && v[1]==n2 && v[2]==n0 && v[3]==n3,
   408       check(v.size()==4 && v[0]==n1 && v[1]==n2 && v[2]==n0 && v[3]==n3,
   408             "Something is wrong with LoggerBoolMap");
   409             "Something is wrong with LoggerBoolMap");
   409     }
   410     }
   410   }
   411   }
   411   
   412 
   412   // IdMap, RangeIdMap
   413   // IdMap, RangeIdMap
   413   {
   414   {
   414     typedef ListDigraph Graph;
   415     typedef ListDigraph Graph;
   415     DIGRAPH_TYPEDEFS(Graph);
   416     DIGRAPH_TYPEDEFS(Graph);
   416 
   417 
   417     checkConcept<ReadMap<Node, int>, IdMap<Graph, Node> >();
   418     checkConcept<ReadMap<Node, int>, IdMap<Graph, Node> >();
   418     checkConcept<ReadMap<Arc, int>, IdMap<Graph, Arc> >();
   419     checkConcept<ReadMap<Arc, int>, IdMap<Graph, Arc> >();
   419     checkConcept<ReadMap<Node, int>, RangeIdMap<Graph, Node> >();
   420     checkConcept<ReadMap<Node, int>, RangeIdMap<Graph, Node> >();
   420     checkConcept<ReadMap<Arc, int>, RangeIdMap<Graph, Arc> >();
   421     checkConcept<ReadMap<Arc, int>, RangeIdMap<Graph, Arc> >();
   421     
   422 
   422     Graph gr;
   423     Graph gr;
   423     IdMap<Graph, Node> nmap(gr);
   424     IdMap<Graph, Node> nmap(gr);
   424     IdMap<Graph, Arc> amap(gr);
   425     IdMap<Graph, Arc> amap(gr);
   425     RangeIdMap<Graph, Node> nrmap(gr);
   426     RangeIdMap<Graph, Node> nrmap(gr);
   426     RangeIdMap<Graph, Arc> armap(gr);
   427     RangeIdMap<Graph, Arc> armap(gr);
   427     
   428 
   428     Node n0 = gr.addNode();
   429     Node n0 = gr.addNode();
   429     Node n1 = gr.addNode();
   430     Node n1 = gr.addNode();
   430     Node n2 = gr.addNode();
   431     Node n2 = gr.addNode();
   431     
   432 
   432     Arc a0 = gr.addArc(n0, n1);
   433     Arc a0 = gr.addArc(n0, n1);
   433     Arc a1 = gr.addArc(n0, n2);
   434     Arc a1 = gr.addArc(n0, n2);
   434     Arc a2 = gr.addArc(n2, n1);
   435     Arc a2 = gr.addArc(n2, n1);
   435     Arc a3 = gr.addArc(n2, n0);
   436     Arc a3 = gr.addArc(n2, n0);
   436     
   437 
   437     check(nmap[n0] == gr.id(n0) && nmap(gr.id(n0)) == n0, "Wrong IdMap");
   438     check(nmap[n0] == gr.id(n0) && nmap(gr.id(n0)) == n0, "Wrong IdMap");
   438     check(nmap[n1] == gr.id(n1) && nmap(gr.id(n1)) == n1, "Wrong IdMap");
   439     check(nmap[n1] == gr.id(n1) && nmap(gr.id(n1)) == n1, "Wrong IdMap");
   439     check(nmap[n2] == gr.id(n2) && nmap(gr.id(n2)) == n2, "Wrong IdMap");
   440     check(nmap[n2] == gr.id(n2) && nmap(gr.id(n2)) == n2, "Wrong IdMap");
   440 
   441 
   441     check(amap[a0] == gr.id(a0) && amap(gr.id(a0)) == a0, "Wrong IdMap");
   442     check(amap[a0] == gr.id(a0) && amap(gr.id(a0)) == a0, "Wrong IdMap");
   443     check(amap[a2] == gr.id(a2) && amap(gr.id(a2)) == a2, "Wrong IdMap");
   444     check(amap[a2] == gr.id(a2) && amap(gr.id(a2)) == a2, "Wrong IdMap");
   444     check(amap[a3] == gr.id(a3) && amap(gr.id(a3)) == a3, "Wrong IdMap");
   445     check(amap[a3] == gr.id(a3) && amap(gr.id(a3)) == a3, "Wrong IdMap");
   445 
   446 
   446     check(nmap.inverse()[gr.id(n0)] == n0, "Wrong IdMap::InverseMap");
   447     check(nmap.inverse()[gr.id(n0)] == n0, "Wrong IdMap::InverseMap");
   447     check(amap.inverse()[gr.id(a0)] == a0, "Wrong IdMap::InverseMap");
   448     check(amap.inverse()[gr.id(a0)] == a0, "Wrong IdMap::InverseMap");
   448     
   449 
   449     check(nrmap.size() == 3 && armap.size() == 4,
   450     check(nrmap.size() == 3 && armap.size() == 4,
   450           "Wrong RangeIdMap::size()");
   451           "Wrong RangeIdMap::size()");
   451 
   452 
   452     check(nrmap[n0] == 0 && nrmap(0) == n0, "Wrong RangeIdMap");
   453     check(nrmap[n0] == 0 && nrmap(0) == n0, "Wrong RangeIdMap");
   453     check(nrmap[n1] == 1 && nrmap(1) == n1, "Wrong RangeIdMap");
   454     check(nrmap[n1] == 1 && nrmap(1) == n1, "Wrong RangeIdMap");
   454     check(nrmap[n2] == 2 && nrmap(2) == n2, "Wrong RangeIdMap");
   455     check(nrmap[n2] == 2 && nrmap(2) == n2, "Wrong RangeIdMap");
   455     
   456 
   456     check(armap[a0] == 0 && armap(0) == a0, "Wrong RangeIdMap");
   457     check(armap[a0] == 0 && armap(0) == a0, "Wrong RangeIdMap");
   457     check(armap[a1] == 1 && armap(1) == a1, "Wrong RangeIdMap");
   458     check(armap[a1] == 1 && armap(1) == a1, "Wrong RangeIdMap");
   458     check(armap[a2] == 2 && armap(2) == a2, "Wrong RangeIdMap");
   459     check(armap[a2] == 2 && armap(2) == a2, "Wrong RangeIdMap");
   459     check(armap[a3] == 3 && armap(3) == a3, "Wrong RangeIdMap");
   460     check(armap[a3] == 3 && armap(3) == a3, "Wrong RangeIdMap");
   460 
   461 
   461     check(nrmap.inverse()[0] == n0, "Wrong RangeIdMap::InverseMap");
   462     check(nrmap.inverse()[0] == n0, "Wrong RangeIdMap::InverseMap");
   462     check(armap.inverse()[0] == a0, "Wrong RangeIdMap::InverseMap");
   463     check(armap.inverse()[0] == a0, "Wrong RangeIdMap::InverseMap");
   463     
   464 
   464     gr.erase(n1);
   465     gr.erase(n1);
   465     
   466 
   466     if (nrmap[n0] == 1) nrmap.swap(n0, n2);
   467     if (nrmap[n0] == 1) nrmap.swap(n0, n2);
   467     nrmap.swap(n2, n0);
   468     nrmap.swap(n2, n0);
   468     if (armap[a1] == 1) armap.swap(a1, a3);
   469     if (armap[a1] == 1) armap.swap(a1, a3);
   469     armap.swap(a3, a1);
   470     armap.swap(a3, a1);
   470     
   471 
   471     check(nrmap.size() == 2 && armap.size() == 2,
   472     check(nrmap.size() == 2 && armap.size() == 2,
   472           "Wrong RangeIdMap::size()");
   473           "Wrong RangeIdMap::size()");
   473 
   474 
   474     check(nrmap[n0] == 1 && nrmap(1) == n0, "Wrong RangeIdMap");
   475     check(nrmap[n0] == 1 && nrmap(1) == n0, "Wrong RangeIdMap");
   475     check(nrmap[n2] == 0 && nrmap(0) == n2, "Wrong RangeIdMap");
   476     check(nrmap[n2] == 0 && nrmap(0) == n2, "Wrong RangeIdMap");
   476     
   477 
   477     check(armap[a1] == 1 && armap(1) == a1, "Wrong RangeIdMap");
   478     check(armap[a1] == 1 && armap(1) == a1, "Wrong RangeIdMap");
   478     check(armap[a3] == 0 && armap(0) == a3, "Wrong RangeIdMap");
   479     check(armap[a3] == 0 && armap(0) == a3, "Wrong RangeIdMap");
   479 
   480 
   480     check(nrmap.inverse()[0] == n2, "Wrong RangeIdMap::InverseMap");
   481     check(nrmap.inverse()[0] == n2, "Wrong RangeIdMap::InverseMap");
   481     check(armap.inverse()[0] == a3, "Wrong RangeIdMap::InverseMap");
   482     check(armap.inverse()[0] == a3, "Wrong RangeIdMap::InverseMap");
   482   }
   483   }
   483   
   484 
   484   // SourceMap, TargetMap, ForwardMap, BackwardMap, InDegMap, OutDegMap
   485   // SourceMap, TargetMap, ForwardMap, BackwardMap, InDegMap, OutDegMap
   485   {
   486   {
   486     typedef ListGraph Graph;
   487     typedef ListGraph Graph;
   487     GRAPH_TYPEDEFS(Graph);
   488     GRAPH_TYPEDEFS(Graph);
   488     
   489 
   489     checkConcept<ReadMap<Arc, Node>, SourceMap<Graph> >();
   490     checkConcept<ReadMap<Arc, Node>, SourceMap<Graph> >();
   490     checkConcept<ReadMap<Arc, Node>, TargetMap<Graph> >();
   491     checkConcept<ReadMap<Arc, Node>, TargetMap<Graph> >();
   491     checkConcept<ReadMap<Edge, Arc>, ForwardMap<Graph> >();
   492     checkConcept<ReadMap<Edge, Arc>, ForwardMap<Graph> >();
   492     checkConcept<ReadMap<Edge, Arc>, BackwardMap<Graph> >();
   493     checkConcept<ReadMap<Edge, Arc>, BackwardMap<Graph> >();
   493     checkConcept<ReadMap<Node, int>, InDegMap<Graph> >();
   494     checkConcept<ReadMap<Node, int>, InDegMap<Graph> >();
   495 
   496 
   496     Graph gr;
   497     Graph gr;
   497     Node n0 = gr.addNode();
   498     Node n0 = gr.addNode();
   498     Node n1 = gr.addNode();
   499     Node n1 = gr.addNode();
   499     Node n2 = gr.addNode();
   500     Node n2 = gr.addNode();
   500     
   501 
   501     gr.addEdge(n0,n1);
   502     gr.addEdge(n0,n1);
   502     gr.addEdge(n1,n2);
   503     gr.addEdge(n1,n2);
   503     gr.addEdge(n0,n2);
   504     gr.addEdge(n0,n2);
   504     gr.addEdge(n2,n1);
   505     gr.addEdge(n2,n1);
   505     gr.addEdge(n1,n2);
   506     gr.addEdge(n1,n2);
   506     gr.addEdge(n0,n1);
   507     gr.addEdge(n0,n1);
   507     
   508 
   508     for (EdgeIt e(gr); e != INVALID; ++e) {
   509     for (EdgeIt e(gr); e != INVALID; ++e) {
   509       check(forwardMap(gr)[e] == gr.direct(e, true), "Wrong ForwardMap");
   510       check(forwardMap(gr)[e] == gr.direct(e, true), "Wrong ForwardMap");
   510       check(backwardMap(gr)[e] == gr.direct(e, false), "Wrong BackwardMap");
   511       check(backwardMap(gr)[e] == gr.direct(e, false), "Wrong BackwardMap");
   511     }
   512     }
   512     
   513 
   513     check(mapCompare(gr,
   514     check(mapCompare(gr,
   514           sourceMap(orienter(gr, constMap<Edge, bool>(true))),
   515           sourceMap(orienter(gr, constMap<Edge, bool>(true))),
   515           targetMap(orienter(gr, constMap<Edge, bool>(false)))),
   516           targetMap(orienter(gr, constMap<Edge, bool>(false)))),
   516           "Wrong SourceMap or TargetMap");
   517           "Wrong SourceMap or TargetMap");
   517 
   518 
   518     typedef Orienter<Graph, const ConstMap<Edge, bool> > Digraph;
   519     typedef Orienter<Graph, const ConstMap<Edge, bool> > Digraph;
   519     Digraph dgr(gr, constMap<Edge, bool>(true));
   520     Digraph dgr(gr, constMap<Edge, bool>(true));
   520     OutDegMap<Digraph> odm(dgr);
   521     OutDegMap<Digraph> odm(dgr);
   521     InDegMap<Digraph> idm(dgr);
   522     InDegMap<Digraph> idm(dgr);
   522     
   523 
   523     check(odm[n0] == 3 && odm[n1] == 2 && odm[n2] == 1, "Wrong OutDegMap");
   524     check(odm[n0] == 3 && odm[n1] == 2 && odm[n2] == 1, "Wrong OutDegMap");
   524     check(idm[n0] == 0 && idm[n1] == 3 && idm[n2] == 3, "Wrong InDegMap");
   525     check(idm[n0] == 0 && idm[n1] == 3 && idm[n2] == 3, "Wrong InDegMap");
   525    
   526 
   526     gr.addEdge(n2, n0);
   527     gr.addEdge(n2, n0);
   527 
   528 
   528     check(odm[n0] == 3 && odm[n1] == 2 && odm[n2] == 2, "Wrong OutDegMap");
   529     check(odm[n0] == 3 && odm[n1] == 2 && odm[n2] == 2, "Wrong OutDegMap");
   529     check(idm[n0] == 1 && idm[n1] == 3 && idm[n2] == 3, "Wrong InDegMap");
   530     check(idm[n0] == 1 && idm[n1] == 3 && idm[n2] == 3, "Wrong InDegMap");
   530   }
   531   }
   531   
   532 
   532   // CrossRefMap
   533   // CrossRefMap
   533   {
   534   {
   534     typedef ListDigraph Graph;
   535     typedef ListDigraph Graph;
   535     DIGRAPH_TYPEDEFS(Graph);
   536     DIGRAPH_TYPEDEFS(Graph);
   536 
   537 
   538                  CrossRefMap<Graph, Node, int> >();
   539                  CrossRefMap<Graph, Node, int> >();
   539     checkConcept<ReadWriteMap<Node, bool>,
   540     checkConcept<ReadWriteMap<Node, bool>,
   540                  CrossRefMap<Graph, Node, bool> >();
   541                  CrossRefMap<Graph, Node, bool> >();
   541     checkConcept<ReadWriteMap<Node, double>,
   542     checkConcept<ReadWriteMap<Node, double>,
   542                  CrossRefMap<Graph, Node, double> >();
   543                  CrossRefMap<Graph, Node, double> >();
   543     
   544 
   544     Graph gr;
   545     Graph gr;
   545     typedef CrossRefMap<Graph, Node, char> CRMap;
   546     typedef CrossRefMap<Graph, Node, char> CRMap;
   546     CRMap map(gr);
   547     CRMap map(gr);
   547     
   548 
   548     Node n0 = gr.addNode();
   549     Node n0 = gr.addNode();
   549     Node n1 = gr.addNode();
   550     Node n1 = gr.addNode();
   550     Node n2 = gr.addNode();
   551     Node n2 = gr.addNode();
   551     
   552 
   552     map.set(n0, 'A');
   553     map.set(n0, 'A');
   553     map.set(n1, 'B');
   554     map.set(n1, 'B');
   554     map.set(n2, 'C');
   555     map.set(n2, 'C');
   555     
   556 
   556     check(map[n0] == 'A' && map('A') == n0 && map.inverse()['A'] == n0,
   557     check(map[n0] == 'A' && map('A') == n0 && map.inverse()['A'] == n0,
   557           "Wrong CrossRefMap");
   558           "Wrong CrossRefMap");
   558     check(map[n1] == 'B' && map('B') == n1 && map.inverse()['B'] == n1,
   559     check(map[n1] == 'B' && map('B') == n1 && map.inverse()['B'] == n1,
   559           "Wrong CrossRefMap");
   560           "Wrong CrossRefMap");
   560     check(map[n2] == 'C' && map('C') == n2 && map.inverse()['C'] == n2,
   561     check(map[n2] == 'C' && map('C') == n2 && map.inverse()['C'] == n2,
   561           "Wrong CrossRefMap");
   562           "Wrong CrossRefMap");
   562     check(map.count('A') == 1 && map.count('B') == 1 && map.count('C') == 1,
   563     check(map.count('A') == 1 && map.count('B') == 1 && map.count('C') == 1,
   563           "Wrong CrossRefMap::count()");
   564           "Wrong CrossRefMap::count()");
   564     
   565 
   565     CRMap::ValueIt it = map.beginValue();
   566     CRMap::ValueIt it = map.beginValue();
   566     check(*it++ == 'A' && *it++ == 'B' && *it++ == 'C' &&
   567     check(*it++ == 'A' && *it++ == 'B' && *it++ == 'C' &&
   567           it == map.endValue(), "Wrong value iterator");
   568           it == map.endValue(), "Wrong value iterator");
   568     
   569 
   569     map.set(n2, 'A');
   570     map.set(n2, 'A');
   570 
   571 
   571     check(map[n0] == 'A' && map[n1] == 'B' && map[n2] == 'A',
   572     check(map[n0] == 'A' && map[n1] == 'B' && map[n2] == 'A',
   572           "Wrong CrossRefMap");
   573           "Wrong CrossRefMap");
   573     check(map('A') == n0 && map.inverse()['A'] == n0, "Wrong CrossRefMap");
   574     check(map('A') == n0 && map.inverse()['A'] == n0, "Wrong CrossRefMap");
   601     typedef SmartDigraph Graph;
   602     typedef SmartDigraph Graph;
   602     DIGRAPH_TYPEDEFS(Graph);
   603     DIGRAPH_TYPEDEFS(Graph);
   603 
   604 
   604     checkConcept<ReadWriteMap<Node, int>,
   605     checkConcept<ReadWriteMap<Node, int>,
   605                  CrossRefMap<Graph, Node, int> >();
   606                  CrossRefMap<Graph, Node, int> >();
   606     
   607 
   607     Graph gr;
   608     Graph gr;
   608     typedef CrossRefMap<Graph, Node, char> CRMap;
   609     typedef CrossRefMap<Graph, Node, char> CRMap;
   609     typedef CRMap::ValueIterator ValueIt;
   610     typedef CRMap::ValueIterator ValueIt;
   610     CRMap map(gr);
   611     CRMap map(gr);
   611     
   612 
   612     Node n0 = gr.addNode();
   613     Node n0 = gr.addNode();
   613     Node n1 = gr.addNode();
   614     Node n1 = gr.addNode();
   614     Node n2 = gr.addNode();
   615     Node n2 = gr.addNode();
   615     
   616 
   616     map.set(n0, 'A');
   617     map.set(n0, 'A');
   617     map.set(n1, 'B');
   618     map.set(n1, 'B');
   618     map.set(n2, 'C');
   619     map.set(n2, 'C');
   619     map.set(n2, 'A');
   620     map.set(n2, 'A');
   620     map.set(n0, 'C');
   621     map.set(n0, 'C');
   627 
   628 
   628     ValueIt it = map.beginValue();
   629     ValueIt it = map.beginValue();
   629     check(*it++ == 'A' && *it++ == 'B' && *it++ == 'C' &&
   630     check(*it++ == 'A' && *it++ == 'B' && *it++ == 'C' &&
   630           it == map.endValue(), "Wrong value iterator");
   631           it == map.endValue(), "Wrong value iterator");
   631   }
   632   }
   632   
   633 
   633   // Iterable bool map
   634   // Iterable bool map
   634   {
   635   {
   635     typedef SmartGraph Graph;
   636     typedef SmartGraph Graph;
   636     typedef SmartGraph::Node Item;
   637     typedef SmartGraph::Node Item;
   637 
   638 
   815       ++n;
   816       ++n;
   816     }
   817     }
   817     check(n == num, "Wrong number");
   818     check(n == num, "Wrong number");
   818 
   819 
   819   }
   820   }
   820   
   821 
   821   // Graph map utilities:
   822   // Graph map utilities:
   822   // mapMin(), mapMax(), mapMinValue(), mapMaxValue()
   823   // mapMin(), mapMax(), mapMinValue(), mapMaxValue()
   823   // mapFind(), mapFindIf(), mapCount(), mapCountIf()
   824   // mapFind(), mapFindIf(), mapCount(), mapCountIf()
   824   // mapCopy(), mapCompare(), mapFill()
   825   // mapCopy(), mapCompare(), mapFill()
   825   {
   826   {
   827 
   828 
   828     SmartDigraph g;
   829     SmartDigraph g;
   829     Node n1 = g.addNode();
   830     Node n1 = g.addNode();
   830     Node n2 = g.addNode();
   831     Node n2 = g.addNode();
   831     Node n3 = g.addNode();
   832     Node n3 = g.addNode();
   832     
   833 
   833     SmartDigraph::NodeMap<int> map1(g);
   834     SmartDigraph::NodeMap<int> map1(g);
   834     SmartDigraph::ArcMap<char> map2(g);
   835     SmartDigraph::ArcMap<char> map2(g);
   835     ConstMap<Node, A> cmap1 = A();
   836     ConstMap<Node, A> cmap1 = A();
   836     ConstMap<Arc, C> cmap2 = C(0);
   837     ConstMap<Arc, C> cmap2 = C(0);
   837     
   838 
   838     map1[n1] = 10;
   839     map1[n1] = 10;
   839     map1[n2] = 5;
   840     map1[n2] = 5;
   840     map1[n3] = 12;
   841     map1[n3] = 12;
   841     
   842 
   842     // mapMin(), mapMax(), mapMinValue(), mapMaxValue()
   843     // mapMin(), mapMax(), mapMinValue(), mapMaxValue()
   843     check(mapMin(g, map1) == n2, "Wrong mapMin()");
   844     check(mapMin(g, map1) == n2, "Wrong mapMin()");
   844     check(mapMax(g, map1) == n3, "Wrong mapMax()");
   845     check(mapMax(g, map1) == n3, "Wrong mapMax()");
   845     check(mapMin(g, map1, std::greater<int>()) == n3, "Wrong mapMin()");
   846     check(mapMin(g, map1, std::greater<int>()) == n3, "Wrong mapMin()");
   846     check(mapMax(g, map1, std::greater<int>()) == n2, "Wrong mapMax()");
   847     check(mapMax(g, map1, std::greater<int>()) == n2, "Wrong mapMax()");
   855 
   856 
   856     Arc a1 = g.addArc(n1, n2);
   857     Arc a1 = g.addArc(n1, n2);
   857     Arc a2 = g.addArc(n1, n3);
   858     Arc a2 = g.addArc(n1, n3);
   858     Arc a3 = g.addArc(n2, n3);
   859     Arc a3 = g.addArc(n2, n3);
   859     Arc a4 = g.addArc(n3, n1);
   860     Arc a4 = g.addArc(n3, n1);
   860     
   861 
   861     map2[a1] = 'b';
   862     map2[a1] = 'b';
   862     map2[a2] = 'a';
   863     map2[a2] = 'a';
   863     map2[a3] = 'b';
   864     map2[a3] = 'b';
   864     map2[a4] = 'c';
   865     map2[a4] = 'c';
   865 
   866 
   922           "Wrong mapCountIf()");
   923           "Wrong mapCountIf()");
   923     check(mapCountIf(g, map2, Less<char>('c')) == 3,
   924     check(mapCountIf(g, map2, Less<char>('c')) == 3,
   924           "Wrong mapCountIf()");
   925           "Wrong mapCountIf()");
   925     check(mapCountIf(g, map2, Less<char>('a')) == 0,
   926     check(mapCountIf(g, map2, Less<char>('a')) == 0,
   926           "Wrong mapCountIf()");
   927           "Wrong mapCountIf()");
   927      
   928 
   928     // MapIt, ConstMapIt
   929     // MapIt, ConstMapIt
   929 /*
   930 /*
   930 These tests can be used after applying bugfix #330
   931 These tests can be used after applying bugfix #330
   931     typedef SmartDigraph::NodeMap<int>::MapIt MapIt;
   932     typedef SmartDigraph::NodeMap<int>::MapIt MapIt;
   932     typedef SmartDigraph::NodeMap<int>::ConstMapIt ConstMapIt;
   933     typedef SmartDigraph::NodeMap<int>::ConstMapIt ConstMapIt;
   933     check(*std::min_element(MapIt(map1), MapIt(INVALID)) == 5,
   934     check(*std::min_element(MapIt(map1), MapIt(INVALID)) == 5,
   934           "Wrong NodeMap<>::MapIt");
   935           "Wrong NodeMap<>::MapIt");
   935     check(*std::max_element(ConstMapIt(map1), ConstMapIt(INVALID)) == 12,
   936     check(*std::max_element(ConstMapIt(map1), ConstMapIt(INVALID)) == 12,
   936           "Wrong NodeMap<>::MapIt");
   937           "Wrong NodeMap<>::MapIt");
   937     
   938 
   938     int sum = 0;
   939     int sum = 0;
   939     std::for_each(MapIt(map1), MapIt(INVALID), Sum<int>(sum));
   940     std::for_each(MapIt(map1), MapIt(INVALID), Sum<int>(sum));
   940     check(sum == 27, "Wrong NodeMap<>::MapIt");
   941     check(sum == 27, "Wrong NodeMap<>::MapIt");
   941     std::for_each(ConstMapIt(map1), ConstMapIt(INVALID), Sum<int>(sum));
   942     std::for_each(ConstMapIt(map1), ConstMapIt(INVALID), Sum<int>(sum));
   942     check(sum == 54, "Wrong NodeMap<>::ConstMapIt");
   943     check(sum == 54, "Wrong NodeMap<>::ConstMapIt");
   949     check(mapCompare(g, map2, scaleMap(map2, 1)), "Wrong mapCompare()");
   950     check(mapCompare(g, map2, scaleMap(map2, 1)), "Wrong mapCompare()");
   950     check(!mapCompare(g, map1, shiftMap(map1, 1)), "Wrong mapCompare()");
   951     check(!mapCompare(g, map1, shiftMap(map1, 1)), "Wrong mapCompare()");
   951 
   952 
   952     SmartDigraph::NodeMap<int> map3(g, 0);
   953     SmartDigraph::NodeMap<int> map3(g, 0);
   953     SmartDigraph::ArcMap<char> map4(g, 'a');
   954     SmartDigraph::ArcMap<char> map4(g, 'a');
   954     
   955 
   955     check(!mapCompare(g, map1, map3), "Wrong mapCompare()");
   956     check(!mapCompare(g, map1, map3), "Wrong mapCompare()");
   956     check(!mapCompare(g, map2, map4), "Wrong mapCompare()");    
   957     check(!mapCompare(g, map2, map4), "Wrong mapCompare()");
   957     
   958 
   958     mapCopy(g, map1, map3);
   959     mapCopy(g, map1, map3);
   959     mapCopy(g, map2, map4);
   960     mapCopy(g, map2, map4);
   960 
   961 
   961     check(mapCompare(g, map1, map3), "Wrong mapCompare() or mapCopy()");
   962     check(mapCompare(g, map1, map3), "Wrong mapCompare() or mapCopy()");
   962     check(mapCompare(g, map2, map4), "Wrong mapCompare() or mapCopy()");    
   963     check(mapCompare(g, map2, map4), "Wrong mapCompare() or mapCopy()");
   963     
   964 
   964     Undirector<SmartDigraph> ug(g);
   965     Undirector<SmartDigraph> ug(g);
   965     Undirector<SmartDigraph>::EdgeMap<char> umap1(ug, 'x');
   966     Undirector<SmartDigraph>::EdgeMap<char> umap1(ug, 'x');
   966     Undirector<SmartDigraph>::ArcMap<double> umap2(ug, 3.14);
   967     Undirector<SmartDigraph>::ArcMap<double> umap2(ug, 3.14);
   967     
   968 
   968     check(!mapCompare(g, map2, umap1), "Wrong mapCompare() or mapCopy()");
   969     check(!mapCompare(g, map2, umap1), "Wrong mapCompare() or mapCopy()");
   969     check(!mapCompare(g, umap1, map2), "Wrong mapCompare() or mapCopy()");
   970     check(!mapCompare(g, umap1, map2), "Wrong mapCompare() or mapCopy()");
   970     check(!mapCompare(ug, map2, umap1), "Wrong mapCompare() or mapCopy()");
   971     check(!mapCompare(ug, map2, umap1), "Wrong mapCompare() or mapCopy()");
   971     check(!mapCompare(ug, umap1, map2), "Wrong mapCompare() or mapCopy()");
   972     check(!mapCompare(ug, umap1, map2), "Wrong mapCompare() or mapCopy()");
   972     
   973 
   973     mapCopy(g, map2, umap1);
   974     mapCopy(g, map2, umap1);
   974 
   975 
   975     check(mapCompare(g, map2, umap1), "Wrong mapCompare() or mapCopy()");
   976     check(mapCompare(g, map2, umap1), "Wrong mapCompare() or mapCopy()");
   976     check(mapCompare(g, umap1, map2), "Wrong mapCompare() or mapCopy()");
   977     check(mapCompare(g, umap1, map2), "Wrong mapCompare() or mapCopy()");
   977     check(mapCompare(ug, map2, umap1), "Wrong mapCompare() or mapCopy()");
   978     check(mapCompare(ug, map2, umap1), "Wrong mapCompare() or mapCopy()");
   978     check(mapCompare(ug, umap1, map2), "Wrong mapCompare() or mapCopy()");
   979     check(mapCompare(ug, umap1, map2), "Wrong mapCompare() or mapCopy()");
   979     
   980 
   980     mapCopy(g, map2, umap1);
   981     mapCopy(g, map2, umap1);
   981     mapCopy(g, umap1, map2);
   982     mapCopy(g, umap1, map2);
   982     mapCopy(ug, map2, umap1);
   983     mapCopy(ug, map2, umap1);
   983     mapCopy(ug, umap1, map2);
   984     mapCopy(ug, umap1, map2);
   984     
   985 
   985     check(!mapCompare(ug, umap1, umap2), "Wrong mapCompare() or mapCopy()");
   986     check(!mapCompare(ug, umap1, umap2), "Wrong mapCompare() or mapCopy()");
   986     mapCopy(ug, umap1, umap2);
   987     mapCopy(ug, umap1, umap2);
   987     check(mapCompare(ug, umap1, umap2), "Wrong mapCompare() or mapCopy()");
   988     check(mapCompare(ug, umap1, umap2), "Wrong mapCompare() or mapCopy()");
   988     
   989 
   989     check(!mapCompare(g, map1, constMap<Node>(2)), "Wrong mapCompare()");
   990     check(!mapCompare(g, map1, constMap<Node>(2)), "Wrong mapCompare()");
   990     mapFill(g, map1, 2);
   991     mapFill(g, map1, 2);
   991     check(mapCompare(g, constMap<Node>(2), map1), "Wrong mapFill()");
   992     check(mapCompare(g, constMap<Node>(2), map1), "Wrong mapFill()");
   992 
   993 
   993     check(!mapCompare(g, map2, constMap<Arc>('z')), "Wrong mapCompare()");
   994     check(!mapCompare(g, map2, constMap<Arc>('z')), "Wrong mapCompare()");
   994     mapCopy(g, constMap<Arc>('z'), map2);
   995     mapCopy(g, constMap<Arc>('z'), map2);
   995     check(mapCompare(g, constMap<Arc>('z'), map2), "Wrong mapCopy()");
   996     check(mapCompare(g, constMap<Arc>('z'), map2), "Wrong mapCopy()");
   996   }
   997   }
   997   
   998 
   998   return 0;
   999   return 0;
   999 }
  1000 }