COIN-OR::LEMON - Graph Library

Changeset 998:7fdaa05a69a1 in lemon-main for test


Ignore:
Timestamp:
09/13/12 11:56:19 (12 years ago)
Author:
Alpar Juttner <alpar@…>
Branch:
default
Children:
999:00f8d9f9920d, 1183:cd72eae05bdf
Parents:
995:4bb9e72e1a41 (diff), 997:761fe0846f49 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Phase:
public
Message:

Merge #449 to branches >=1.2

Location:
test
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • test/CMakeLists.txt

    r964 r998  
    1414SET(TESTS
    1515  adaptors_test
     16  arc_look_up_test
    1617  bellman_ford_test
    1718  bfs_test
     
    8788    GET_FILENAME_COMPONENT(TARGET_PATH ${TARGET_LOC} PATH)
    8889    ADD_CUSTOM_COMMAND(TARGET lp_test POST_BUILD
    89       COMMAND ${CMAKE_COMMAND} -E copy ${CPLEX_BIN_DIR}/cplex91.dll ${TARGET_PATH}
     90      COMMAND ${CMAKE_COMMAND} -E copy ${CPLEX_BIN_DIR}/cplex.dll ${TARGET_PATH}
    9091    )
    9192  ENDIF()
     
    129130    GET_FILENAME_COMPONENT(TARGET_PATH ${TARGET_LOC} PATH)
    130131    ADD_CUSTOM_COMMAND(TARGET mip_test POST_BUILD
    131       COMMAND ${CMAKE_COMMAND} -E copy ${CPLEX_BIN_DIR}/cplex91.dll ${TARGET_PATH}
     132      COMMAND ${CMAKE_COMMAND} -E copy ${CPLEX_BIN_DIR}/cplex.dll ${TARGET_PATH}
    132133    )
    133134  ENDIF()
  • test/CMakeLists.txt

    r993 r998  
    1515  adaptors_test
    1616  arc_look_up_test
     17  bellman_ford_test
    1718  bfs_test
    1819  circulation_test
     
    2627  error_test
    2728  euler_test
     29  fractional_matching_test
    2830  gomory_hu_test
    2931  graph_copy_test
     
    3840  min_cost_arborescence_test
    3941  min_cost_flow_test
     42  min_mean_cycle_test
    4043  path_test
     44  planarity_test
    4145  preflow_test
    4246  radix_sort_test
  • test/adaptors_test.cc

    r995 r998  
    6666  Digraph::Arc a2 = digraph.addArc(n1, n3);
    6767  Digraph::Arc a3 = digraph.addArc(n2, n3);
     68  ignore_unused_variable_warning(a3);
    6869
    6970  // Check the adaptor
     
    100101  Adaptor::Arc a7 = adaptor.addArc(n1, n4);
    101102  Adaptor::Arc a8 = adaptor.addArc(n1, n2);
     103  ignore_unused_variable_warning(a6,a7,a8);
    102104
    103105  adaptor.erase(a1);
     
    759761  Digraph::Arc a2 = digraph.addArc(n1, n3);
    760762  Digraph::Arc a3 = digraph.addArc(n2, n3);
     763  ignore_unused_variable_warning(a1,a2,a3);
    761764
    762765  checkGraphNodeList(adaptor, 6);
  • test/adaptors_test.cc

    r997 r998  
    13751375
    13761376  GridGraph::EdgeMap<bool> dir_map(graph);
    1377   dir_map[graph.right(n1)] = graph.u(graph.right(n1)) == n1;
    1378   dir_map[graph.up(n1)] = graph.u(graph.up(n1)) != n1;
    1379   dir_map[graph.left(n4)] = graph.u(graph.left(n4)) != n4;
    1380   dir_map[graph.down(n4)] = graph.u(graph.down(n4)) != n4;
     1377  dir_map[graph.right(n1)] = graph.u(graph.right(n1)) != n1;
     1378  dir_map[graph.up(n1)] = graph.u(graph.up(n1)) == n1;
     1379  dir_map[graph.left(n4)] = graph.u(graph.left(n4)) == n4;
     1380  dir_map[graph.down(n4)] = graph.u(graph.down(n4)) == n4;
    13811381
    13821382  // Apply several adaptors on the grid graph
    1383   typedef SplitNodes< ReverseDigraph< const Orienter<
    1384             const GridGraph, GridGraph::EdgeMap<bool> > > >
    1385     RevSplitGridGraph;
    1386   typedef ReverseDigraph<const RevSplitGridGraph> SplitGridGraph;
     1383  typedef Orienter< const GridGraph, GridGraph::EdgeMap<bool> >
     1384    OrientedGridGraph;
     1385  typedef SplitNodes<OrientedGridGraph> SplitGridGraph;
    13871386  typedef Undirector<const SplitGridGraph> USplitGridGraph;
    1388   typedef Undirector<const USplitGridGraph> UUSplitGridGraph;
    1389   checkConcept<concepts::Digraph, RevSplitGridGraph>();
    13901387  checkConcept<concepts::Digraph, SplitGridGraph>();
    13911388  checkConcept<concepts::Graph, USplitGridGraph>();
    1392   checkConcept<concepts::Graph, UUSplitGridGraph>();
    1393 
    1394   RevSplitGridGraph rev_adaptor =
    1395     splitNodes(reverseDigraph(orienter(graph, dir_map)));
    1396   SplitGridGraph adaptor = reverseDigraph(rev_adaptor);
     1389
     1390  OrientedGridGraph oadaptor = orienter(graph, dir_map);
     1391  SplitGridGraph adaptor = splitNodes(oadaptor);
    13971392  USplitGridGraph uadaptor = undirector(adaptor);
    1398   UUSplitGridGraph uuadaptor = undirector(uadaptor);
    13991393
    14001394  // Check adaptor
     
    14031397  checkGraphConArcList(adaptor, 8);
    14041398
    1405   checkGraphOutArcList(adaptor, rev_adaptor.inNode(n1), 1);
    1406   checkGraphOutArcList(adaptor, rev_adaptor.outNode(n1), 1);
    1407   checkGraphOutArcList(adaptor, rev_adaptor.inNode(n2), 2);
    1408   checkGraphOutArcList(adaptor, rev_adaptor.outNode(n2), 1);
    1409   checkGraphOutArcList(adaptor, rev_adaptor.inNode(n3), 1);
    1410   checkGraphOutArcList(adaptor, rev_adaptor.outNode(n3), 1);
    1411   checkGraphOutArcList(adaptor, rev_adaptor.inNode(n4), 0);
    1412   checkGraphOutArcList(adaptor, rev_adaptor.outNode(n4), 1);
    1413 
    1414   checkGraphInArcList(adaptor, rev_adaptor.inNode(n1), 1);
    1415   checkGraphInArcList(adaptor, rev_adaptor.outNode(n1), 1);
    1416   checkGraphInArcList(adaptor, rev_adaptor.inNode(n2), 1);
    1417   checkGraphInArcList(adaptor, rev_adaptor.outNode(n2), 0);
    1418   checkGraphInArcList(adaptor, rev_adaptor.inNode(n3), 1);
    1419   checkGraphInArcList(adaptor, rev_adaptor.outNode(n3), 1);
    1420   checkGraphInArcList(adaptor, rev_adaptor.inNode(n4), 1);
    1421   checkGraphInArcList(adaptor, rev_adaptor.outNode(n4), 2);
     1399  checkGraphOutArcList(adaptor, adaptor.inNode(n1), 1);
     1400  checkGraphOutArcList(adaptor, adaptor.outNode(n1), 1);
     1401  checkGraphOutArcList(adaptor, adaptor.inNode(n2), 1);
     1402  checkGraphOutArcList(adaptor, adaptor.outNode(n2), 0);
     1403  checkGraphOutArcList(adaptor, adaptor.inNode(n3), 1);
     1404  checkGraphOutArcList(adaptor, adaptor.outNode(n3), 1);
     1405  checkGraphOutArcList(adaptor, adaptor.inNode(n4), 1);
     1406  checkGraphOutArcList(adaptor, adaptor.outNode(n4), 2);
     1407
     1408  checkGraphInArcList(adaptor, adaptor.inNode(n1), 1);
     1409  checkGraphInArcList(adaptor, adaptor.outNode(n1), 1);
     1410  checkGraphInArcList(adaptor, adaptor.inNode(n2), 2);
     1411  checkGraphInArcList(adaptor, adaptor.outNode(n2), 1);
     1412  checkGraphInArcList(adaptor, adaptor.inNode(n3), 1);
     1413  checkGraphInArcList(adaptor, adaptor.outNode(n3), 1);
     1414  checkGraphInArcList(adaptor, adaptor.inNode(n4), 0);
     1415  checkGraphInArcList(adaptor, adaptor.outNode(n4), 1);
    14221416
    14231417  checkNodeIds(adaptor);
     
    14421436  checkGraphArcMap(uadaptor);
    14431437
    1444   checkGraphIncEdgeArcLists(uadaptor, rev_adaptor.inNode(n1), 2);
    1445   checkGraphIncEdgeArcLists(uadaptor, rev_adaptor.outNode(n1), 2);
    1446   checkGraphIncEdgeArcLists(uadaptor, rev_adaptor.inNode(n2), 3);
    1447   checkGraphIncEdgeArcLists(uadaptor, rev_adaptor.outNode(n2), 1);
    1448   checkGraphIncEdgeArcLists(uadaptor, rev_adaptor.inNode(n3), 2);
    1449   checkGraphIncEdgeArcLists(uadaptor, rev_adaptor.outNode(n3), 2);
    1450   checkGraphIncEdgeArcLists(uadaptor, rev_adaptor.inNode(n4), 1);
    1451   checkGraphIncEdgeArcLists(uadaptor, rev_adaptor.outNode(n4), 3);
    1452 
    1453   // Check uuadaptor
    1454   checkGraphNodeList(uuadaptor, 8);
    1455   checkGraphEdgeList(uuadaptor, 16);
    1456   checkGraphArcList(uuadaptor, 32);
    1457   checkGraphConEdgeList(uuadaptor, 16);
    1458   checkGraphConArcList(uuadaptor, 32);
    1459 
    1460   checkNodeIds(uuadaptor);
    1461   checkEdgeIds(uuadaptor);
    1462   checkArcIds(uuadaptor);
    1463 
    1464   checkGraphNodeMap(uuadaptor);
    1465   checkGraphEdgeMap(uuadaptor);
    1466   checkGraphArcMap(uuadaptor);
     1438  checkGraphIncEdgeArcLists(uadaptor, adaptor.inNode(n1), 2);
     1439  checkGraphIncEdgeArcLists(uadaptor, adaptor.outNode(n1), 2);
     1440  checkGraphIncEdgeArcLists(uadaptor, adaptor.inNode(n2), 3);
     1441  checkGraphIncEdgeArcLists(uadaptor, adaptor.outNode(n2), 1);
     1442  checkGraphIncEdgeArcLists(uadaptor, adaptor.inNode(n3), 2);
     1443  checkGraphIncEdgeArcLists(uadaptor, adaptor.outNode(n3), 2);
     1444  checkGraphIncEdgeArcLists(uadaptor, adaptor.inNode(n4), 1);
     1445  checkGraphIncEdgeArcLists(uadaptor, adaptor.outNode(n4), 3);
    14671446}
    14681447
  • test/connectivity_test.cc

    r877 r998  
    6969    Graph g(d);
    7070    Digraph::Node n = d.addNode();
     71    ignore_unused_variable_warning(n);
    7172
    7273    check(stronglyConnected(d), "This digraph is strongly connected");
     
    246247    Digraph::Node watch = d.addNode();
    247248    Digraph::Node pants = d.addNode();
     249    ignore_unused_variable_warning(watch);
    248250
    249251    d.addArc(socks, shoe);
  • test/connectivity_test.cc

    r997 r998  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2009
     5 * Copyright (C) 2003-2010
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    3030  typedef ListDigraph Digraph;
    3131  typedef Undirector<Digraph> Graph;
    32  
    33   {
    34     Digraph d;
    35     Digraph::NodeMap<int> order(d);
    36     Graph g(d);
    37    
     32
     33  {
     34    Digraph d;
     35    Digraph::NodeMap<int> order(d);
     36    Graph g(d);
     37
    3838    check(stronglyConnected(d), "The empty digraph is strongly connected");
    3939    check(countStronglyConnectedComponents(d) == 0,
     
    4949    check(countBiEdgeConnectedComponents(g) == 0,
    5050          "The empty graph has 0 bi-edge-connected component");
    51          
     51
    5252    check(dag(d), "The empty digraph is DAG.");
    5353    check(checkedTopologicalSort(d, order), "The empty digraph is DAG.");
     
    8484    check(countBiEdgeConnectedComponents(g) == 1,
    8585          "This graph has 1 bi-edge-connected component");
    86          
     86
    8787    check(dag(d), "This digraph is DAG.");
    8888    check(checkedTopologicalSort(d, order), "This digraph is DAG.");
     
    103103    Digraph::NodeMap<int> order(d);
    104104    Graph g(d);
    105    
     105
    106106    Digraph::Node n1 = d.addNode();
    107107    Digraph::Node n2 = d.addNode();
     
    110110    Digraph::Node n5 = d.addNode();
    111111    Digraph::Node n6 = d.addNode();
    112    
     112
    113113    d.addArc(n1, n3);
    114114    d.addArc(n3, n2);
     
    138138    check(!parallelFree(g), "This graph is not parallel-free.");
    139139    check(!simpleGraph(g), "This graph is not simple.");
    140    
     140
    141141    d.addArc(n3, n3);
    142    
     142
    143143    check(!loopFree(d), "This digraph is not loop-free.");
    144144    check(!loopFree(g), "This graph is not loop-free.");
    145145    check(!simpleGraph(d), "This digraph is not simple.");
    146    
     146
    147147    d.addArc(n3, n2);
    148    
     148
    149149    check(!parallelFree(d), "This digraph is not parallel-free.");
    150150  }
    151  
     151
    152152  {
    153153    Digraph d;
    154154    Digraph::ArcMap<bool> cutarcs(d, false);
    155155    Graph g(d);
    156    
     156
    157157    Digraph::Node n1 = d.addNode();
    158158    Digraph::Node n2 = d.addNode();
     
    174174    d.addArc(n6, n7);
    175175    d.addArc(n7, n6);
    176    
     176
    177177    check(!stronglyConnected(d), "This digraph is not strongly connected");
    178178    check(countStronglyConnectedComponents(d) == 3,
     
    237237    Digraph d;
    238238    Digraph::NodeMap<int> order(d);
    239    
     239
    240240    Digraph::Node belt = d.addNode();
    241241    Digraph::Node trousers = d.addNode();
     
    258258    d.addArc(shirt, necktie);
    259259    d.addArc(necktie, coat);
    260    
     260
    261261    check(dag(d), "This digraph is DAG.");
    262262    topologicalSort(d, order);
     
    270270    ListGraph g;
    271271    ListGraph::NodeMap<bool> map(g);
    272    
     272
    273273    ListGraph::Node n1 = g.addNode();
    274274    ListGraph::Node n2 = g.addNode();
     
    286286    g.addEdge(n4, n7);
    287287    g.addEdge(n5, n7);
    288    
     288
    289289    check(bipartite(g), "This graph is bipartite");
    290290    check(bipartitePartitions(g, map), "This graph is bipartite");
    291    
     291
    292292    check(map[n1] == map[n2] && map[n1] == map[n6] && map[n1] == map[n7],
    293293          "Wrong bipartitePartitions()");
  • test/digraph_test.cc

    r877 r998  
    6565      a3 = G.addArc(n2, n3),
    6666      a4 = G.addArc(n2, n3);
     67  ignore_unused_variable_warning(a2,a3,a4);
    6768
    6869  checkGraphNodeList(G, 3);
     
    9394  Arc a1 = G.addArc(n1, n2), a2 = G.addArc(n2, n1),
    9495      a3 = G.addArc(n2, n3), a4 = G.addArc(n2, n3);
     96  ignore_unused_variable_warning(a1,a2,a3,a4);
    9597
    9698  Node n4 = G.split(n2);
     
    126128      a3 = G.addArc(n4, n3), a4 = G.addArc(n4, n3),
    127129      a5 = G.addArc(n2, n4);
     130  ignore_unused_variable_warning(a1,a2,a3,a5);
    128131
    129132  checkGraphNodeList(G, 4);
     
    205208      a3 = G.addArc(n4, n3), a4 = G.addArc(n3, n1),
    206209      a5 = G.addArc(n2, n4);
     210  ignore_unused_variable_warning(a2,a3,a4,a5);
    207211
    208212  // Check arc deletion
     
    252256  Arc a1 = G.addArc(n1, n2), a2 = G.addArc(n2, n1),
    253257      a3 = G.addArc(n2, n3), a4 = G.addArc(n2, n3);
     258  ignore_unused_variable_warning(a1,a2,a3,a4);
    254259
    255260  typename Digraph::Snapshot snapshot(G);
     
    352357    e1 = g.addArc(n1, n2),
    353358    e2 = g.addArc(n2, n3);
     359  ignore_unused_variable_warning(e2);
    354360
    355361  check(g.valid(n1), "Wrong validity check");
  • test/digraph_test.cc

    r997 r998  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2009
     5 * Copyright (C) 2003-2010
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    2020#include <lemon/list_graph.h>
    2121#include <lemon/smart_graph.h>
     22#include <lemon/static_graph.h>
    2223#include <lemon/full_graph.h>
    2324
     
    3536  checkGraphNodeList(G, 0);
    3637  checkGraphArcList(G, 0);
     38
     39  G.reserveNode(3);
     40  G.reserveArc(4);
    3741
    3842  Node
     
    289293
    290294  snapshot.restore();
     295  snapshot.save(G);
     296
     297  checkGraphNodeList(G, 4);
     298  checkGraphArcList(G, 4);
     299
     300  G.addArc(G.addNode(), G.addNode());
     301
     302  snapshot.restore();
    291303
    292304  checkGraphNodeList(G, 4);
     
    323335    checkConcept<ClearableDigraphComponent<>, SmartDigraph>();
    324336  }
     337  { // Checking StaticDigraph
     338    checkConcept<Digraph, StaticDigraph>();
     339    checkConcept<ClearableDigraphComponent<>, StaticDigraph>();
     340  }
    325341  { // Checking FullDigraph
    326342    checkConcept<Digraph, FullDigraph>();
     
    379395}
    380396
     397void checkStaticDigraph() {
     398  SmartDigraph g;
     399  SmartDigraph::NodeMap<StaticDigraph::Node> nref(g);
     400  SmartDigraph::ArcMap<StaticDigraph::Arc> aref(g);
     401
     402  StaticDigraph G;
     403
     404  checkGraphNodeList(G, 0);
     405  checkGraphArcList(G, 0);
     406
     407  G.build(g, nref, aref);
     408
     409  checkGraphNodeList(G, 0);
     410  checkGraphArcList(G, 0);
     411
     412  SmartDigraph::Node
     413    n1 = g.addNode(),
     414    n2 = g.addNode(),
     415    n3 = g.addNode();
     416
     417  G.build(g, nref, aref);
     418
     419  checkGraphNodeList(G, 3);
     420  checkGraphArcList(G, 0);
     421
     422  SmartDigraph::Arc a1 = g.addArc(n1, n2);
     423
     424  G.build(g, nref, aref);
     425
     426  check(G.source(aref[a1]) == nref[n1] && G.target(aref[a1]) == nref[n2],
     427        "Wrong arc or wrong references");
     428  checkGraphNodeList(G, 3);
     429  checkGraphArcList(G, 1);
     430
     431  checkGraphOutArcList(G, nref[n1], 1);
     432  checkGraphOutArcList(G, nref[n2], 0);
     433  checkGraphOutArcList(G, nref[n3], 0);
     434
     435  checkGraphInArcList(G, nref[n1], 0);
     436  checkGraphInArcList(G, nref[n2], 1);
     437  checkGraphInArcList(G, nref[n3], 0);
     438
     439  checkGraphConArcList(G, 1);
     440
     441  SmartDigraph::Arc
     442    a2 = g.addArc(n2, n1),
     443    a3 = g.addArc(n2, n3),
     444    a4 = g.addArc(n2, n3);
     445
     446  digraphCopy(g, G).nodeRef(nref).run();
     447
     448  checkGraphNodeList(G, 3);
     449  checkGraphArcList(G, 4);
     450
     451  checkGraphOutArcList(G, nref[n1], 1);
     452  checkGraphOutArcList(G, nref[n2], 3);
     453  checkGraphOutArcList(G, nref[n3], 0);
     454
     455  checkGraphInArcList(G, nref[n1], 1);
     456  checkGraphInArcList(G, nref[n2], 1);
     457  checkGraphInArcList(G, nref[n3], 2);
     458
     459  checkGraphConArcList(G, 4);
     460
     461  std::vector<std::pair<int,int> > arcs;
     462  arcs.push_back(std::make_pair(0,1));
     463  arcs.push_back(std::make_pair(0,2));
     464  arcs.push_back(std::make_pair(1,3));
     465  arcs.push_back(std::make_pair(1,2));
     466  arcs.push_back(std::make_pair(3,0));
     467  arcs.push_back(std::make_pair(3,3));
     468  arcs.push_back(std::make_pair(4,2));
     469  arcs.push_back(std::make_pair(4,3));
     470  arcs.push_back(std::make_pair(4,1));
     471
     472  G.build(6, arcs.begin(), arcs.end());
     473
     474  checkGraphNodeList(G, 6);
     475  checkGraphArcList(G, 9);
     476
     477  checkGraphOutArcList(G, G.node(0), 2);
     478  checkGraphOutArcList(G, G.node(1), 2);
     479  checkGraphOutArcList(G, G.node(2), 0);
     480  checkGraphOutArcList(G, G.node(3), 2);
     481  checkGraphOutArcList(G, G.node(4), 3);
     482  checkGraphOutArcList(G, G.node(5), 0);
     483
     484  checkGraphInArcList(G, G.node(0), 1);
     485  checkGraphInArcList(G, G.node(1), 2);
     486  checkGraphInArcList(G, G.node(2), 3);
     487  checkGraphInArcList(G, G.node(3), 3);
     488  checkGraphInArcList(G, G.node(4), 0);
     489  checkGraphInArcList(G, G.node(5), 0);
     490
     491  checkGraphConArcList(G, 9);
     492
     493  checkNodeIds(G);
     494  checkArcIds(G);
     495  checkGraphNodeMap(G);
     496  checkGraphArcMap(G);
     497
     498  int n = G.nodeNum();
     499  int m = G.arcNum();
     500  check(G.index(G.node(n-1)) == n-1, "Wrong index.");
     501  check(G.index(G.arc(m-1)) == m-1, "Wrong index.");
     502}
     503
    381504void checkFullDigraph(int num) {
    382505  typedef FullDigraph Digraph;
    383506  DIGRAPH_TYPEDEFS(Digraph);
     507
    384508  Digraph G(num);
     509  check(G.nodeNum() == num && G.arcNum() == num * num, "Wrong size");
     510
     511  G.resize(num);
     512  check(G.nodeNum() == num && G.arcNum() == num * num, "Wrong size");
    385513
    386514  checkGraphNodeList(G, num);
     
    426554    checkDigraphValidity<SmartDigraph>();
    427555  }
     556  { // Checking StaticDigraph
     557    checkStaticDigraph();
     558  }
    428559  { // Checking FullDigraph
    429560    checkFullDigraph(8);
  • test/edge_set_test.cc

    r877 r998  
    4545
    4646  Digraph::Arc ga1 = digraph.addArc(n1, n2);
     47  ignore_unused_variable_warning(ga1);
    4748
    4849  ArcSet arc_set(digraph);
    4950
    5051  Digraph::Arc ga2 = digraph.addArc(n2, n1);
     52  ignore_unused_variable_warning(ga2);
    5153
    5254  checkGraphNodeList(arc_set, 2);
     
    7678    a3 = arc_set.addArc(n2, n3),
    7779    a4 = arc_set.addArc(n2, n3);
     80  ignore_unused_variable_warning(a2,a3,a4);
     81
    7882  checkGraphNodeList(arc_set, 3);
    7983  checkGraphArcList(arc_set, 4);
     
    111115
    112116  Digraph::Arc ga1 = digraph.addArc(n1, n2);
     117  ignore_unused_variable_warning(ga1);
    113118
    114119  ArcSet arc_set(digraph);
    115120
    116121  Digraph::Arc ga2 = digraph.addArc(n2, n1);
     122  ignore_unused_variable_warning(ga2);
    117123
    118124  checkGraphNodeList(arc_set, 2);
     
    142148    a3 = arc_set.addArc(n2, n3),
    143149    a4 = arc_set.addArc(n2, n3);
     150  ignore_unused_variable_warning(a2,a3,a4);
     151
    144152  checkGraphNodeList(arc_set, 3);
    145153  checkGraphArcList(arc_set, 4);
     
    191199
    192200  Digraph::Arc ga1 = digraph.addArc(n1, n2);
     201  ignore_unused_variable_warning(ga1);
    193202
    194203  EdgeSet edge_set(digraph);
    195204
    196205  Digraph::Arc ga2 = digraph.addArc(n2, n1);
     206  ignore_unused_variable_warning(ga2);
    197207
    198208  checkGraphNodeList(edge_set, 2);
     
    231241    e3 = edge_set.addEdge(n2, n3),
    232242    e4 = edge_set.addEdge(n2, n3);
     243  ignore_unused_variable_warning(e2,e3,e4);
     244
    233245  checkGraphNodeList(edge_set, 3);
    234246  checkGraphEdgeList(edge_set, 4);
     
    275287
    276288  Digraph::Arc ga1 = digraph.addArc(n1, n2);
     289  ignore_unused_variable_warning(ga1);
    277290
    278291  EdgeSet edge_set(digraph);
    279292
    280293  Digraph::Arc ga2 = digraph.addArc(n2, n1);
     294  ignore_unused_variable_warning(ga2);
    281295
    282296  checkGraphNodeList(edge_set, 2);
     
    315329    e3 = edge_set.addEdge(n2, n3),
    316330    e4 = edge_set.addEdge(n2, n3);
     331  ignore_unused_variable_warning(e2,e3,e4);
     332
    317333  checkGraphNodeList(edge_set, 3);
    318334  checkGraphEdgeList(edge_set, 4);
  • test/edge_set_test.cc

    r997 r998  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2008
     5 * Copyright (C) 2003-2010
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
  • test/euler_test.cc

    r877 r998  
    102102    Graph g(d);
    103103    Digraph::Node n = d.addNode();
    104 
     104    ignore_unused_variable_warning(n);
     105 
    105106    checkDiEulerIt(d);
    106107    checkDiEulerIt(g);
     
    190191    Digraph::Node n4 = d.addNode();
    191192    Digraph::Node n5 = d.addNode();
     193    ignore_unused_variable_warning(n0,n4,n5);
    192194
    193195    d.addArc(n1, n2);
  • test/euler_test.cc

    r997 r998  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2009
     5 * Copyright (C) 2003-2010
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    8686  typedef ListDigraph Digraph;
    8787  typedef Undirector<Digraph> Graph;
    88  
    89   {
    90     Digraph d;
    91     Graph g(d);
    92    
     88
     89  {
     90    Digraph d;
     91    Graph g(d);
     92
    9393    checkDiEulerIt(d);
    9494    checkDiEulerIt(g);
     
    130130    Digraph::Node n2 = d.addNode();
    131131    Digraph::Node n3 = d.addNode();
    132    
     132
    133133    d.addArc(n1, n2);
    134134    d.addArc(n2, n1);
     
    155155    Digraph::Node n5 = d.addNode();
    156156    Digraph::Node n6 = d.addNode();
    157    
     157
    158158    d.addArc(n1, n2);
    159159    d.addArc(n2, n4);
     
    214214    Digraph::Node n2 = d.addNode();
    215215    Digraph::Node n3 = d.addNode();
    216    
     216
    217217    d.addArc(n1, n2);
    218218    d.addArc(n2, n3);
  • test/graph_test.cc

    r877 r998  
    6767  Edge e2 = G.addEdge(n2, n1),
    6868       e3 = G.addEdge(n2, n3);
     69  ignore_unused_variable_warning(e2,e3);
    6970
    7071  checkGraphNodeList(G, 3);
     
    99100       e3 = G.addEdge(n2, n3), e4 = G.addEdge(n1, n4),
    100101       e5 = G.addEdge(n4, n3);
     102  ignore_unused_variable_warning(e1,e3,e4,e5);
    101103
    102104  checkGraphNodeList(G, 4);
     
    178180       e3 = G.addEdge(n2, n3), e4 = G.addEdge(n1, n4),
    179181       e5 = G.addEdge(n4, n3);
     182  ignore_unused_variable_warning(e1,e3,e4,e5);
    180183
    181184  // Check edge deletion
     
    218221  Edge e1 = G.addEdge(n1, n2), e2 = G.addEdge(n2, n1),
    219222       e3 = G.addEdge(n2, n3);
     223  ignore_unused_variable_warning(e1,e2,e3);
    220224
    221225  checkGraphNodeList(G, 3);
     
    382386    e1 = g.addEdge(n1, n2),
    383387    e2 = g.addEdge(n2, n3);
     388  ignore_unused_variable_warning(e2);
    384389
    385390  check(g.valid(n1), "Wrong validity check");
     
    520525
    521526  Node n = G.nodeFromId(dim);
     527  ignore_unused_variable_warning(n);
    522528
    523529  for (NodeIt n(G); n != INVALID; ++n) {
  • test/graph_test.cc

    r997 r998  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2009
     5 * Copyright (C) 2003-2010
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    3939  checkGraphArcList(G, 0);
    4040
     41  G.reserveNode(3);
     42  G.reserveEdge(3);
     43
    4144  Node
    4245    n1 = G.addNode(),
     
    261264
    262265  snapshot.restore();
     266  snapshot.save(G);
    263267
    264268  checkGraphNodeList(G, 4);
    265269  checkGraphEdgeList(G, 3);
    266270  checkGraphArcList(G, 6);
     271
     272  G.addEdge(G.addNode(), G.addNode());
     273
     274  snapshot.restore();
     275
     276  checkGraphNodeList(G, 4);
     277  checkGraphEdgeList(G, 3);
     278  checkGraphArcList(G, 6);
    267279}
    268280
     
    272284
    273285  Graph G(num);
     286  check(G.nodeNum() == num && G.edgeNum() == num * (num - 1) / 2,
     287        "Wrong size");
     288
     289  G.resize(num);
     290  check(G.nodeNum() == num && G.edgeNum() == num * (num - 1) / 2,
     291        "Wrong size");
     292
    274293  checkGraphNodeList(G, num);
    275294  checkGraphEdgeList(G, num * (num - 1) / 2);
     
    417436  check(G.height() == height, "Wrong row number");
    418437
     438  G.resize(width, height);
     439  check(G.width() == width, "Wrong column number");
     440  check(G.height() == height, "Wrong row number");
     441
    419442  for (int i = 0; i < width; ++i) {
    420443    for (int j = 0; j < height; ++j) {
     
    492515
    493516  HypercubeGraph G(dim);
     517  check(G.dimension() == dim, "Wrong dimension");
     518
     519  G.resize(dim);
     520  check(G.dimension() == dim, "Wrong dimension");
     521
    494522  checkGraphNodeList(G, 1 << dim);
    495523  checkGraphEdgeList(G, dim * (1 << (dim-1)));
  • test/maps_test.cc

    r942 r998  
    104104    NullMap<A,B> map1;
    105105    NullMap<A,B> map2 = map1;
     106    ignore_unused_variable_warning(map2);
    106107    map1 = nullMap<A,B>();
    107108  }
     
    114115    ConstMap<A,B> map2 = B();
    115116    ConstMap<A,B> map3 = map1;
     117    ignore_unused_variable_warning(map2,map3);
     118
    116119    map1 = constMap<A>(B());
    117120    map1 = constMap<A,B>();
     
    119122    ConstMap<A,C> map4(C(1));
    120123    ConstMap<A,C> map5 = map4;
     124    ignore_unused_variable_warning(map5);
     125
    121126    map4 = constMap<A>(C(2));
    122127    map4.setAll(C(3));
     
    139144    IdentityMap<A> map1;
    140145    IdentityMap<A> map2 = map1;
     146    ignore_unused_variable_warning(map2);
     147
    141148    map1 = identityMap<A>();
    142149
     
    198205    checkConcept<ReadMap<B,double>, CompMap>();
    199206    CompMap map1 = CompMap(DoubleMap(),ReadMap<B,A>());
     207    ignore_unused_variable_warning(map1);
    200208    CompMap map2 = composeMap(DoubleMap(), ReadMap<B,A>());
     209    ignore_unused_variable_warning(map2);
    201210
    202211    SparseMap<double, bool> m1(false); m1[3.14] = true;
     
    211220    checkConcept<ReadMap<A,double>, CombMap>();
    212221    CombMap map1 = CombMap(DoubleMap(), DoubleMap());
     222    ignore_unused_variable_warning(map1);
    213223    CombMap map2 = combineMap(DoubleMap(), DoubleMap(), std::plus<double>());
     224    ignore_unused_variable_warning(map2);
    214225
    215226    check(combineMap(constMap<B,int,2>(), identityMap<B>(), &binc)[B()] == 3,
     
    223234    FunctorToMap<F> map1;
    224235    FunctorToMap<F> map2 = FunctorToMap<F>(F());
     236    ignore_unused_variable_warning(map2);
     237
    225238    B b = functorToMap(F())[A()];
     239    ignore_unused_variable_warning(b);
    226240
    227241    checkConcept<ReadMap<A,B>, MapToFunctor<ReadMap<A,B> > >();
    228242    MapToFunctor<ReadMap<A,B> > map =
    229243      MapToFunctor<ReadMap<A,B> >(ReadMap<A,B>());
     244    ignore_unused_variable_warning(map);
    230245
    231246    check(functorToMap(&func)[A()] == 3,
     
    245260      ConvertMap<ReadMap<double, int>, double> >();
    246261    ConvertMap<RangeMap<bool>, int> map1(rangeMap(1, true));
     262    ignore_unused_variable_warning(map1);
    247263    ConvertMap<RangeMap<bool>, int> map2 = convertMap<int>(rangeMap(2, false));
     264    ignore_unused_variable_warning(map2);
     265
    248266  }
    249267
  • test/maps_test.cc

    r997 r998  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2009
     5 * Copyright (C) 2003-2010
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    2424#include <lemon/maps.h>
    2525#include <lemon/list_graph.h>
     26#include <lemon/smart_graph.h>
     27#include <lemon/adaptors.h>
     28#include <lemon/dfs.h>
     29#include <algorithm>
    2630
    2731#include "test_tools.h"
     
    3539
    3640class C {
    37   int x;
     41  int _x;
    3842public:
    39   C(int _x) : x(_x) {}
     43  C(int x) : _x(x) {}
     44  int get() const { return _x; }
     45};
     46inline bool operator<(C c1, C c2) { return c1.get() < c2.get(); }
     47inline bool operator==(C c1, C c2) { return c1.get() == c2.get(); }
     48
     49C createC(int x) { return C(x); }
     50
     51template <typename T>
     52class Less {
     53  T _t;
     54public:
     55  Less(T t): _t(t) {}
     56  bool operator()(const T& t) const { return t < _t; }
    4057};
    4158
     
    5370
    5471int binc(int a, B) { return a+1; }
     72
     73template <typename T>
     74class Sum {
     75  T& _sum;
     76public:
     77  Sum(T& sum) : _sum(sum) {}
     78  void operator()(const T& t) { _sum += t; }
     79};
    5580
    5681typedef ReadMap<A, double> DoubleMap;
     
    349374  {
    350375    typedef std::vector<int> vec;
     376    checkConcept<WriteMap<int, bool>, LoggerBoolMap<vec::iterator> >();
     377    checkConcept<WriteMap<int, bool>,
     378                 LoggerBoolMap<std::back_insert_iterator<vec> > >();
     379
    351380    vec v1;
    352381    vec v2(10);
     
    368397          it != map2.end(); ++it )
    369398      check(v1[i++] == *it, "Something is wrong with LoggerBoolMap");
    370   }
    371  
    372   // CrossRefMap
    373   {
     399
    374400    typedef ListDigraph Graph;
    375401    DIGRAPH_TYPEDEFS(Graph);
     402    Graph gr;
     403
     404    Node n0 = gr.addNode();
     405    Node n1 = gr.addNode();
     406    Node n2 = gr.addNode();
     407    Node n3 = gr.addNode();
     408
     409    gr.addArc(n3, n0);
     410    gr.addArc(n3, n2);
     411    gr.addArc(n0, n2);
     412    gr.addArc(n2, n1);
     413    gr.addArc(n0, n1);
     414
     415    {
     416      std::vector<Node> v;
     417      dfs(gr).processedMap(loggerBoolMap(std::back_inserter(v))).run();
     418
     419      check(v.size()==4 && v[0]==n1 && v[1]==n2 && v[2]==n0 && v[3]==n3,
     420            "Something is wrong with LoggerBoolMap");
     421    }
     422    {
     423      std::vector<Node> v(countNodes(gr));
     424      dfs(gr).processedMap(loggerBoolMap(v.begin())).run();
     425
     426      check(v.size()==4 && v[0]==n1 && v[1]==n2 && v[2]==n0 && v[3]==n3,
     427            "Something is wrong with LoggerBoolMap");
     428    }
     429  }
     430
     431  // IdMap, RangeIdMap
     432  {
     433    typedef ListDigraph Graph;
     434    DIGRAPH_TYPEDEFS(Graph);
     435
     436    checkConcept<ReadMap<Node, int>, IdMap<Graph, Node> >();
     437    checkConcept<ReadMap<Arc, int>, IdMap<Graph, Arc> >();
     438    checkConcept<ReadMap<Node, int>, RangeIdMap<Graph, Node> >();
     439    checkConcept<ReadMap<Arc, int>, RangeIdMap<Graph, Arc> >();
     440
     441    Graph gr;
     442    IdMap<Graph, Node> nmap(gr);
     443    IdMap<Graph, Arc> amap(gr);
     444    RangeIdMap<Graph, Node> nrmap(gr);
     445    RangeIdMap<Graph, Arc> armap(gr);
     446
     447    Node n0 = gr.addNode();
     448    Node n1 = gr.addNode();
     449    Node n2 = gr.addNode();
     450
     451    Arc a0 = gr.addArc(n0, n1);
     452    Arc a1 = gr.addArc(n0, n2);
     453    Arc a2 = gr.addArc(n2, n1);
     454    Arc a3 = gr.addArc(n2, n0);
     455
     456    check(nmap[n0] == gr.id(n0) && nmap(gr.id(n0)) == n0, "Wrong IdMap");
     457    check(nmap[n1] == gr.id(n1) && nmap(gr.id(n1)) == n1, "Wrong IdMap");
     458    check(nmap[n2] == gr.id(n2) && nmap(gr.id(n2)) == n2, "Wrong IdMap");
     459
     460    check(amap[a0] == gr.id(a0) && amap(gr.id(a0)) == a0, "Wrong IdMap");
     461    check(amap[a1] == gr.id(a1) && amap(gr.id(a1)) == a1, "Wrong IdMap");
     462    check(amap[a2] == gr.id(a2) && amap(gr.id(a2)) == a2, "Wrong IdMap");
     463    check(amap[a3] == gr.id(a3) && amap(gr.id(a3)) == a3, "Wrong IdMap");
     464
     465    check(nmap.inverse()[gr.id(n0)] == n0, "Wrong IdMap::InverseMap");
     466    check(amap.inverse()[gr.id(a0)] == a0, "Wrong IdMap::InverseMap");
     467
     468    check(nrmap.size() == 3 && armap.size() == 4,
     469          "Wrong RangeIdMap::size()");
     470
     471    check(nrmap[n0] == 0 && nrmap(0) == n0, "Wrong RangeIdMap");
     472    check(nrmap[n1] == 1 && nrmap(1) == n1, "Wrong RangeIdMap");
     473    check(nrmap[n2] == 2 && nrmap(2) == n2, "Wrong RangeIdMap");
     474
     475    check(armap[a0] == 0 && armap(0) == a0, "Wrong RangeIdMap");
     476    check(armap[a1] == 1 && armap(1) == a1, "Wrong RangeIdMap");
     477    check(armap[a2] == 2 && armap(2) == a2, "Wrong RangeIdMap");
     478    check(armap[a3] == 3 && armap(3) == a3, "Wrong RangeIdMap");
     479
     480    check(nrmap.inverse()[0] == n0, "Wrong RangeIdMap::InverseMap");
     481    check(armap.inverse()[0] == a0, "Wrong RangeIdMap::InverseMap");
     482
     483    gr.erase(n1);
     484
     485    if (nrmap[n0] == 1) nrmap.swap(n0, n2);
     486    nrmap.swap(n2, n0);
     487    if (armap[a1] == 1) armap.swap(a1, a3);
     488    armap.swap(a3, a1);
     489
     490    check(nrmap.size() == 2 && armap.size() == 2,
     491          "Wrong RangeIdMap::size()");
     492
     493    check(nrmap[n0] == 1 && nrmap(1) == n0, "Wrong RangeIdMap");
     494    check(nrmap[n2] == 0 && nrmap(0) == n2, "Wrong RangeIdMap");
     495
     496    check(armap[a1] == 1 && armap(1) == a1, "Wrong RangeIdMap");
     497    check(armap[a3] == 0 && armap(0) == a3, "Wrong RangeIdMap");
     498
     499    check(nrmap.inverse()[0] == n2, "Wrong RangeIdMap::InverseMap");
     500    check(armap.inverse()[0] == a3, "Wrong RangeIdMap::InverseMap");
     501  }
     502
     503  // SourceMap, TargetMap, ForwardMap, BackwardMap, InDegMap, OutDegMap
     504  {
     505    typedef ListGraph Graph;
     506    GRAPH_TYPEDEFS(Graph);
     507
     508    checkConcept<ReadMap<Arc, Node>, SourceMap<Graph> >();
     509    checkConcept<ReadMap<Arc, Node>, TargetMap<Graph> >();
     510    checkConcept<ReadMap<Edge, Arc>, ForwardMap<Graph> >();
     511    checkConcept<ReadMap<Edge, Arc>, BackwardMap<Graph> >();
     512    checkConcept<ReadMap<Node, int>, InDegMap<Graph> >();
     513    checkConcept<ReadMap<Node, int>, OutDegMap<Graph> >();
     514
     515    Graph gr;
     516    Node n0 = gr.addNode();
     517    Node n1 = gr.addNode();
     518    Node n2 = gr.addNode();
     519
     520    gr.addEdge(n0,n1);
     521    gr.addEdge(n1,n2);
     522    gr.addEdge(n0,n2);
     523    gr.addEdge(n2,n1);
     524    gr.addEdge(n1,n2);
     525    gr.addEdge(n0,n1);
     526
     527    for (EdgeIt e(gr); e != INVALID; ++e) {
     528      check(forwardMap(gr)[e] == gr.direct(e, true), "Wrong ForwardMap");
     529      check(backwardMap(gr)[e] == gr.direct(e, false), "Wrong BackwardMap");
     530    }
     531
     532    check(mapCompare(gr,
     533          sourceMap(orienter(gr, constMap<Edge, bool>(true))),
     534          targetMap(orienter(gr, constMap<Edge, bool>(false)))),
     535          "Wrong SourceMap or TargetMap");
     536
     537    typedef Orienter<Graph, const ConstMap<Edge, bool> > Digraph;
     538    Digraph dgr(gr, constMap<Edge, bool>(true));
     539    OutDegMap<Digraph> odm(dgr);
     540    InDegMap<Digraph> idm(dgr);
     541
     542    check(odm[n0] == 3 && odm[n1] == 2 && odm[n2] == 1, "Wrong OutDegMap");
     543    check(idm[n0] == 0 && idm[n1] == 3 && idm[n2] == 3, "Wrong InDegMap");
     544
     545    gr.addEdge(n2, n0);
     546
     547    check(odm[n0] == 3 && odm[n1] == 2 && odm[n2] == 2, "Wrong OutDegMap");
     548    check(idm[n0] == 1 && idm[n1] == 3 && idm[n2] == 3, "Wrong InDegMap");
     549  }
     550
     551  // CrossRefMap
     552  {
     553    typedef ListDigraph Graph;
     554    DIGRAPH_TYPEDEFS(Graph);
    376555
    377556    checkConcept<ReadWriteMap<Node, int>,
    378557                 CrossRefMap<Graph, Node, int> >();
    379    
     558    checkConcept<ReadWriteMap<Node, bool>,
     559                 CrossRefMap<Graph, Node, bool> >();
     560    checkConcept<ReadWriteMap<Node, double>,
     561                 CrossRefMap<Graph, Node, double> >();
     562
     563    Graph gr;
     564    typedef CrossRefMap<Graph, Node, char> CRMap;
     565    CRMap map(gr);
     566
     567    Node n0 = gr.addNode();
     568    Node n1 = gr.addNode();
     569    Node n2 = gr.addNode();
     570
     571    map.set(n0, 'A');
     572    map.set(n1, 'B');
     573    map.set(n2, 'C');
     574
     575    check(map[n0] == 'A' && map('A') == n0 && map.inverse()['A'] == n0,
     576          "Wrong CrossRefMap");
     577    check(map[n1] == 'B' && map('B') == n1 && map.inverse()['B'] == n1,
     578          "Wrong CrossRefMap");
     579    check(map[n2] == 'C' && map('C') == n2 && map.inverse()['C'] == n2,
     580          "Wrong CrossRefMap");
     581    check(map.count('A') == 1 && map.count('B') == 1 && map.count('C') == 1,
     582          "Wrong CrossRefMap::count()");
     583
     584    CRMap::ValueIt it = map.beginValue();
     585    check(*it++ == 'A' && *it++ == 'B' && *it++ == 'C' &&
     586          it == map.endValue(), "Wrong value iterator");
     587
     588    map.set(n2, 'A');
     589
     590    check(map[n0] == 'A' && map[n1] == 'B' && map[n2] == 'A',
     591          "Wrong CrossRefMap");
     592    check(map('A') == n0 && map.inverse()['A'] == n0, "Wrong CrossRefMap");
     593    check(map('B') == n1 && map.inverse()['B'] == n1, "Wrong CrossRefMap");
     594    check(map('C') == INVALID && map.inverse()['C'] == INVALID,
     595          "Wrong CrossRefMap");
     596    check(map.count('A') == 2 && map.count('B') == 1 && map.count('C') == 0,
     597          "Wrong CrossRefMap::count()");
     598
     599    it = map.beginValue();
     600    check(*it++ == 'A' && *it++ == 'A' && *it++ == 'B' &&
     601          it == map.endValue(), "Wrong value iterator");
     602
     603    map.set(n0, 'C');
     604
     605    check(map[n0] == 'C' && map[n1] == 'B' && map[n2] == 'A',
     606          "Wrong CrossRefMap");
     607    check(map('A') == n2 && map.inverse()['A'] == n2, "Wrong CrossRefMap");
     608    check(map('B') == n1 && map.inverse()['B'] == n1, "Wrong CrossRefMap");
     609    check(map('C') == n0 && map.inverse()['C'] == n0, "Wrong CrossRefMap");
     610    check(map.count('A') == 1 && map.count('B') == 1 && map.count('C') == 1,
     611          "Wrong CrossRefMap::count()");
     612
     613    it = map.beginValue();
     614    check(*it++ == 'A' && *it++ == 'B' && *it++ == 'C' &&
     615          it == map.endValue(), "Wrong value iterator");
     616  }
     617
     618  // CrossRefMap
     619  {
     620    typedef SmartDigraph Graph;
     621    DIGRAPH_TYPEDEFS(Graph);
     622
     623    checkConcept<ReadWriteMap<Node, int>,
     624                 CrossRefMap<Graph, Node, int> >();
     625
    380626    Graph gr;
    381627    typedef CrossRefMap<Graph, Node, char> CRMap;
    382628    typedef CRMap::ValueIterator ValueIt;
    383629    CRMap map(gr);
    384    
     630
    385631    Node n0 = gr.addNode();
    386632    Node n1 = gr.addNode();
    387633    Node n2 = gr.addNode();
    388    
     634
    389635    map.set(n0, 'A');
    390636    map.set(n1, 'B');
     
    404650  }
    405651
     652  // Iterable bool map
     653  {
     654    typedef SmartGraph Graph;
     655    typedef SmartGraph::Node Item;
     656
     657    typedef IterableBoolMap<SmartGraph, SmartGraph::Node> Ibm;
     658    checkConcept<ReferenceMap<Item, bool, bool&, const bool&>, Ibm>();
     659
     660    const int num = 10;
     661    Graph g;
     662    Ibm map0(g, true);
     663    std::vector<Item> items;
     664    for (int i = 0; i < num; ++i) {
     665      items.push_back(g.addNode());
     666    }
     667
     668    Ibm map1(g, true);
     669    int n = 0;
     670    for (Ibm::TrueIt it(map1); it != INVALID; ++it) {
     671      check(map1[static_cast<Item>(it)], "Wrong TrueIt");
     672      ++n;
     673    }
     674    check(n == num, "Wrong number");
     675
     676    n = 0;
     677    for (Ibm::ItemIt it(map1, true); it != INVALID; ++it) {
     678        check(map1[static_cast<Item>(it)], "Wrong ItemIt for true");
     679        ++n;
     680    }
     681    check(n == num, "Wrong number");
     682    check(Ibm::FalseIt(map1) == INVALID, "Wrong FalseIt");
     683    check(Ibm::ItemIt(map1, false) == INVALID, "Wrong ItemIt for false");
     684
     685    map1[items[5]] = true;
     686
     687    n = 0;
     688    for (Ibm::ItemIt it(map1, true); it != INVALID; ++it) {
     689        check(map1[static_cast<Item>(it)], "Wrong ItemIt for true");
     690        ++n;
     691    }
     692    check(n == num, "Wrong number");
     693
     694    map1[items[num / 2]] = false;
     695    check(map1[items[num / 2]] == false, "Wrong map value");
     696
     697    n = 0;
     698    for (Ibm::TrueIt it(map1); it != INVALID; ++it) {
     699        check(map1[static_cast<Item>(it)], "Wrong TrueIt for true");
     700        ++n;
     701    }
     702    check(n == num - 1, "Wrong number");
     703
     704    n = 0;
     705    for (Ibm::FalseIt it(map1); it != INVALID; ++it) {
     706        check(!map1[static_cast<Item>(it)], "Wrong FalseIt for true");
     707        ++n;
     708    }
     709    check(n == 1, "Wrong number");
     710
     711    map1[items[0]] = false;
     712    check(map1[items[0]] == false, "Wrong map value");
     713
     714    map1[items[num - 1]] = false;
     715    check(map1[items[num - 1]] == false, "Wrong map value");
     716
     717    n = 0;
     718    for (Ibm::TrueIt it(map1); it != INVALID; ++it) {
     719        check(map1[static_cast<Item>(it)], "Wrong TrueIt for true");
     720        ++n;
     721    }
     722    check(n == num - 3, "Wrong number");
     723    check(map1.trueNum() == num - 3, "Wrong number");
     724
     725    n = 0;
     726    for (Ibm::FalseIt it(map1); it != INVALID; ++it) {
     727        check(!map1[static_cast<Item>(it)], "Wrong FalseIt for true");
     728        ++n;
     729    }
     730    check(n == 3, "Wrong number");
     731    check(map1.falseNum() == 3, "Wrong number");
     732  }
     733
     734  // Iterable int map
     735  {
     736    typedef SmartGraph Graph;
     737    typedef SmartGraph::Node Item;
     738    typedef IterableIntMap<SmartGraph, SmartGraph::Node> Iim;
     739
     740    checkConcept<ReferenceMap<Item, int, int&, const int&>, Iim>();
     741
     742    const int num = 10;
     743    Graph g;
     744    Iim map0(g, 0);
     745    std::vector<Item> items;
     746    for (int i = 0; i < num; ++i) {
     747      items.push_back(g.addNode());
     748    }
     749
     750    Iim map1(g);
     751    check(map1.size() == 0, "Wrong size");
     752
     753    for (int i = 0; i < num; ++i) {
     754      map1[items[i]] = i;
     755    }
     756    check(map1.size() == num, "Wrong size");
     757
     758    for (int i = 0; i < num; ++i) {
     759      Iim::ItemIt it(map1, i);
     760      check(static_cast<Item>(it) == items[i], "Wrong value");
     761      ++it;
     762      check(static_cast<Item>(it) == INVALID, "Wrong value");
     763    }
     764
     765    for (int i = 0; i < num; ++i) {
     766      map1[items[i]] = i % 2;
     767    }
     768    check(map1.size() == 2, "Wrong size");
     769
     770    int n = 0;
     771    for (Iim::ItemIt it(map1, 0); it != INVALID; ++it) {
     772      check(map1[static_cast<Item>(it)] == 0, "Wrong value");
     773      ++n;
     774    }
     775    check(n == (num + 1) / 2, "Wrong number");
     776
     777    for (Iim::ItemIt it(map1, 1); it != INVALID; ++it) {
     778      check(map1[static_cast<Item>(it)] == 1, "Wrong value");
     779      ++n;
     780    }
     781    check(n == num, "Wrong number");
     782
     783  }
     784
     785  // Iterable value map
     786  {
     787    typedef SmartGraph Graph;
     788    typedef SmartGraph::Node Item;
     789    typedef IterableValueMap<SmartGraph, SmartGraph::Node, double> Ivm;
     790
     791    checkConcept<ReadWriteMap<Item, double>, Ivm>();
     792
     793    const int num = 10;
     794    Graph g;
     795    Ivm map0(g, 0.0);
     796    std::vector<Item> items;
     797    for (int i = 0; i < num; ++i) {
     798      items.push_back(g.addNode());
     799    }
     800
     801    Ivm map1(g, 0.0);
     802    check(distance(map1.beginValue(), map1.endValue()) == 1, "Wrong size");
     803    check(*map1.beginValue() == 0.0, "Wrong value");
     804
     805    for (int i = 0; i < num; ++i) {
     806      map1.set(items[i], static_cast<double>(i));
     807    }
     808    check(distance(map1.beginValue(), map1.endValue()) == num, "Wrong size");
     809
     810    for (int i = 0; i < num; ++i) {
     811      Ivm::ItemIt it(map1, static_cast<double>(i));
     812      check(static_cast<Item>(it) == items[i], "Wrong value");
     813      ++it;
     814      check(static_cast<Item>(it) == INVALID, "Wrong value");
     815    }
     816
     817    for (Ivm::ValueIt vit = map1.beginValue();
     818         vit != map1.endValue(); ++vit) {
     819      check(map1[static_cast<Item>(Ivm::ItemIt(map1, *vit))] == *vit,
     820            "Wrong ValueIt");
     821    }
     822
     823    for (int i = 0; i < num; ++i) {
     824      map1.set(items[i], static_cast<double>(i % 2));
     825    }
     826    check(distance(map1.beginValue(), map1.endValue()) == 2, "Wrong size");
     827
     828    int n = 0;
     829    for (Ivm::ItemIt it(map1, 0.0); it != INVALID; ++it) {
     830      check(map1[static_cast<Item>(it)] == 0.0, "Wrong value");
     831      ++n;
     832    }
     833    check(n == (num + 1) / 2, "Wrong number");
     834
     835    for (Ivm::ItemIt it(map1, 1.0); it != INVALID; ++it) {
     836      check(map1[static_cast<Item>(it)] == 1.0, "Wrong value");
     837      ++n;
     838    }
     839    check(n == num, "Wrong number");
     840
     841  }
     842
     843  // Graph map utilities:
     844  // mapMin(), mapMax(), mapMinValue(), mapMaxValue()
     845  // mapFind(), mapFindIf(), mapCount(), mapCountIf()
     846  // mapCopy(), mapCompare(), mapFill()
     847  {
     848    DIGRAPH_TYPEDEFS(SmartDigraph);
     849
     850    SmartDigraph g;
     851    Node n1 = g.addNode();
     852    Node n2 = g.addNode();
     853    Node n3 = g.addNode();
     854
     855    SmartDigraph::NodeMap<int> map1(g);
     856    SmartDigraph::ArcMap<char> map2(g);
     857    ConstMap<Node, A> cmap1 = A();
     858    ConstMap<Arc, C> cmap2 = C(0);
     859
     860    map1[n1] = 10;
     861    map1[n2] = 5;
     862    map1[n3] = 12;
     863
     864    // mapMin(), mapMax(), mapMinValue(), mapMaxValue()
     865    check(mapMin(g, map1) == n2, "Wrong mapMin()");
     866    check(mapMax(g, map1) == n3, "Wrong mapMax()");
     867    check(mapMin(g, map1, std::greater<int>()) == n3, "Wrong mapMin()");
     868    check(mapMax(g, map1, std::greater<int>()) == n2, "Wrong mapMax()");
     869    check(mapMinValue(g, map1) == 5, "Wrong mapMinValue()");
     870    check(mapMaxValue(g, map1) == 12, "Wrong mapMaxValue()");
     871
     872    check(mapMin(g, map2) == INVALID, "Wrong mapMin()");
     873    check(mapMax(g, map2) == INVALID, "Wrong mapMax()");
     874
     875    check(mapMin(g, cmap1) != INVALID, "Wrong mapMin()");
     876    check(mapMax(g, cmap2) == INVALID, "Wrong mapMax()");
     877
     878    Arc a1 = g.addArc(n1, n2);
     879    Arc a2 = g.addArc(n1, n3);
     880    Arc a3 = g.addArc(n2, n3);
     881    Arc a4 = g.addArc(n3, n1);
     882
     883    map2[a1] = 'b';
     884    map2[a2] = 'a';
     885    map2[a3] = 'b';
     886    map2[a4] = 'c';
     887
     888    // mapMin(), mapMax(), mapMinValue(), mapMaxValue()
     889    check(mapMin(g, map2) == a2, "Wrong mapMin()");
     890    check(mapMax(g, map2) == a4, "Wrong mapMax()");
     891    check(mapMin(g, map2, std::greater<int>()) == a4, "Wrong mapMin()");
     892    check(mapMax(g, map2, std::greater<int>()) == a2, "Wrong mapMax()");
     893    check(mapMinValue(g, map2, std::greater<int>()) == 'c',
     894          "Wrong mapMinValue()");
     895    check(mapMaxValue(g, map2, std::greater<int>()) == 'a',
     896          "Wrong mapMaxValue()");
     897
     898    check(mapMin(g, cmap1) != INVALID, "Wrong mapMin()");
     899    check(mapMax(g, cmap2) != INVALID, "Wrong mapMax()");
     900    check(mapMaxValue(g, cmap2) == C(0), "Wrong mapMaxValue()");
     901
     902    check(mapMin(g, composeMap(functorToMap(&createC), map2)) == a2,
     903          "Wrong mapMin()");
     904    check(mapMax(g, composeMap(functorToMap(&createC), map2)) == a4,
     905          "Wrong mapMax()");
     906    check(mapMinValue(g, composeMap(functorToMap(&createC), map2)) == C('a'),
     907          "Wrong mapMinValue()");
     908    check(mapMaxValue(g, composeMap(functorToMap(&createC), map2)) == C('c'),
     909          "Wrong mapMaxValue()");
     910
     911    // mapFind(), mapFindIf()
     912    check(mapFind(g, map1, 5) == n2, "Wrong mapFind()");
     913    check(mapFind(g, map1, 6) == INVALID, "Wrong mapFind()");
     914    check(mapFind(g, map2, 'a') == a2, "Wrong mapFind()");
     915    check(mapFind(g, map2, 'e') == INVALID, "Wrong mapFind()");
     916    check(mapFind(g, cmap2, C(0)) == ArcIt(g), "Wrong mapFind()");
     917    check(mapFind(g, cmap2, C(1)) == INVALID, "Wrong mapFind()");
     918
     919    check(mapFindIf(g, map1, Less<int>(7)) == n2,
     920          "Wrong mapFindIf()");
     921    check(mapFindIf(g, map1, Less<int>(5)) == INVALID,
     922          "Wrong mapFindIf()");
     923    check(mapFindIf(g, map2, Less<char>('d')) == ArcIt(g),
     924          "Wrong mapFindIf()");
     925    check(mapFindIf(g, map2, Less<char>('a')) == INVALID,
     926          "Wrong mapFindIf()");
     927
     928    // mapCount(), mapCountIf()
     929    check(mapCount(g, map1, 5) == 1, "Wrong mapCount()");
     930    check(mapCount(g, map1, 6) == 0, "Wrong mapCount()");
     931    check(mapCount(g, map2, 'a') == 1, "Wrong mapCount()");
     932    check(mapCount(g, map2, 'b') == 2, "Wrong mapCount()");
     933    check(mapCount(g, map2, 'e') == 0, "Wrong mapCount()");
     934    check(mapCount(g, cmap2, C(0)) == 4, "Wrong mapCount()");
     935    check(mapCount(g, cmap2, C(1)) == 0, "Wrong mapCount()");
     936
     937    check(mapCountIf(g, map1, Less<int>(11)) == 2,
     938          "Wrong mapCountIf()");
     939    check(mapCountIf(g, map1, Less<int>(13)) == 3,
     940          "Wrong mapCountIf()");
     941    check(mapCountIf(g, map1, Less<int>(5)) == 0,
     942          "Wrong mapCountIf()");
     943    check(mapCountIf(g, map2, Less<char>('d')) == 4,
     944          "Wrong mapCountIf()");
     945    check(mapCountIf(g, map2, Less<char>('c')) == 3,
     946          "Wrong mapCountIf()");
     947    check(mapCountIf(g, map2, Less<char>('a')) == 0,
     948          "Wrong mapCountIf()");
     949
     950    // MapIt, ConstMapIt
     951/*
     952These tests can be used after applying bugfix #330
     953    typedef SmartDigraph::NodeMap<int>::MapIt MapIt;
     954    typedef SmartDigraph::NodeMap<int>::ConstMapIt ConstMapIt;
     955    check(*std::min_element(MapIt(map1), MapIt(INVALID)) == 5,
     956          "Wrong NodeMap<>::MapIt");
     957    check(*std::max_element(ConstMapIt(map1), ConstMapIt(INVALID)) == 12,
     958          "Wrong NodeMap<>::MapIt");
     959
     960    int sum = 0;
     961    std::for_each(MapIt(map1), MapIt(INVALID), Sum<int>(sum));
     962    check(sum == 27, "Wrong NodeMap<>::MapIt");
     963    std::for_each(ConstMapIt(map1), ConstMapIt(INVALID), Sum<int>(sum));
     964    check(sum == 54, "Wrong NodeMap<>::ConstMapIt");
     965*/
     966
     967    // mapCopy(), mapCompare(), mapFill()
     968    check(mapCompare(g, map1, map1), "Wrong mapCompare()");
     969    check(mapCompare(g, cmap2, cmap2), "Wrong mapCompare()");
     970    check(mapCompare(g, map1, shiftMap(map1, 0)), "Wrong mapCompare()");
     971    check(mapCompare(g, map2, scaleMap(map2, 1)), "Wrong mapCompare()");
     972    check(!mapCompare(g, map1, shiftMap(map1, 1)), "Wrong mapCompare()");
     973
     974    SmartDigraph::NodeMap<int> map3(g, 0);
     975    SmartDigraph::ArcMap<char> map4(g, 'a');
     976
     977    check(!mapCompare(g, map1, map3), "Wrong mapCompare()");
     978    check(!mapCompare(g, map2, map4), "Wrong mapCompare()");
     979
     980    mapCopy(g, map1, map3);
     981    mapCopy(g, map2, map4);
     982
     983    check(mapCompare(g, map1, map3), "Wrong mapCompare() or mapCopy()");
     984    check(mapCompare(g, map2, map4), "Wrong mapCompare() or mapCopy()");
     985
     986    Undirector<SmartDigraph> ug(g);
     987    Undirector<SmartDigraph>::EdgeMap<char> umap1(ug, 'x');
     988    Undirector<SmartDigraph>::ArcMap<double> umap2(ug, 3.14);
     989
     990    check(!mapCompare(g, map2, umap1), "Wrong mapCompare() or mapCopy()");
     991    check(!mapCompare(g, umap1, map2), "Wrong mapCompare() or mapCopy()");
     992    check(!mapCompare(ug, map2, umap1), "Wrong mapCompare() or mapCopy()");
     993    check(!mapCompare(ug, umap1, map2), "Wrong mapCompare() or mapCopy()");
     994
     995    mapCopy(g, map2, umap1);
     996
     997    check(mapCompare(g, map2, umap1), "Wrong mapCompare() or mapCopy()");
     998    check(mapCompare(g, umap1, map2), "Wrong mapCompare() or mapCopy()");
     999    check(mapCompare(ug, map2, umap1), "Wrong mapCompare() or mapCopy()");
     1000    check(mapCompare(ug, umap1, map2), "Wrong mapCompare() or mapCopy()");
     1001
     1002    mapCopy(g, map2, umap1);
     1003    mapCopy(g, umap1, map2);
     1004    mapCopy(ug, map2, umap1);
     1005    mapCopy(ug, umap1, map2);
     1006
     1007    check(!mapCompare(ug, umap1, umap2), "Wrong mapCompare() or mapCopy()");
     1008    mapCopy(ug, umap1, umap2);
     1009    check(mapCompare(ug, umap1, umap2), "Wrong mapCompare() or mapCopy()");
     1010
     1011    check(!mapCompare(g, map1, constMap<Node>(2)), "Wrong mapCompare()");
     1012    mapFill(g, map1, 2);
     1013    check(mapCompare(g, constMap<Node>(2), map1), "Wrong mapFill()");
     1014
     1015    check(!mapCompare(g, map2, constMap<Arc>('z')), "Wrong mapCompare()");
     1016    mapCopy(g, constMap<Arc>('z'), map2);
     1017    check(mapCompare(g, constMap<Arc>('z'), map2), "Wrong mapCopy()");
     1018  }
     1019
    4061020  return 0;
    4071021}
Note: See TracChangeset for help on using the changeset viewer.