COIN-OR::LEMON - Graph Library

Changeset 278:931190050520 in lemon-1.2 for test


Ignore:
Timestamp:
09/22/08 15:33:23 (11 years ago)
Author:
Peter Kovacs <kpeter@…>
Branch:
default
Phase:
public
Message:

Improve the function-type interface of bfs, dfs, and dijkstra (ticket #96)

Location:
test
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • test/bfs_test.cc

    r228 r278  
    6363  BType::DistMap d(G);
    6464  BType::PredMap p(G);
    65   //  BType::PredNodeMap pn(G);
    6665
    6766  BType bfs_test(G);
     
    7372  n  = bfs_test.predNode(n);
    7473  d  = bfs_test.distMap();
    75 
    7674  p  = bfs_test.predMap();
    77   //  pn = bfs_test.predNodeMap();
    7875  b  = bfs_test.reached(n);
    7976
     
    8986
    9087  Digraph g;
    91   bfs(g,Node()).run();
    92   bfs(g).source(Node()).run();
     88  bool b;
     89  bfs(g).run(Node());
     90  b=bfs(g).run(Node(),Node());
     91  bfs(g).run();
    9392  bfs(g)
    94     .predMap(concepts::WriteMap<Node,Arc>())
    95     .distMap(concepts::WriteMap<Node,VType>())
     93    .predMap(concepts::ReadWriteMap<Node,Arc>())
     94    .distMap(concepts::ReadWriteMap<Node,VType>())
    9695    .reachedMap(concepts::ReadWriteMap<Node,bool>())
    9796    .processedMap(concepts::WriteMap<Node,bool>())
    9897    .run(Node());
     98  b=bfs(g)
     99    .predMap(concepts::ReadWriteMap<Node,Arc>())
     100    .distMap(concepts::ReadWriteMap<Node,VType>())
     101    .reachedMap(concepts::ReadWriteMap<Node,bool>())
     102    .processedMap(concepts::WriteMap<Node,bool>())
     103    .path(concepts::Path<Digraph>())
     104    .dist(VType())
     105    .run(Node(),Node());
     106  bfs(g)
     107    .predMap(concepts::ReadWriteMap<Node,Arc>())
     108    .distMap(concepts::ReadWriteMap<Node,VType>())
     109    .reachedMap(concepts::ReadWriteMap<Node,bool>())
     110    .processedMap(concepts::WriteMap<Node,bool>())
     111    .run();
    99112}
    100113
     
    115128  bfs_test.run(s);
    116129
    117   check(bfs_test.dist(t)==2,"Bfs found a wrong path." << bfs_test.dist(t));
     130  check(bfs_test.dist(t)==2,"Bfs found a wrong path.");
    118131
    119132  Path<Digraph> p = bfs_test.path(t);
     
    129142    check( !bfs_test.reached(u) ||
    130143           (bfs_test.dist(v) <= bfs_test.dist(u)+1),
    131            "Wrong output." << G.id(v) << ' ' << G.id(u));
     144           "Wrong output. " << G.id(u) << "->" << G.id(v));
    132145  }
    133146
     
    141154        check(bfs_test.dist(v) - bfs_test.dist(u) == 1,
    142155              "Wrong distance. Difference: "
    143               << std::abs(bfs_test.dist(v) - bfs_test.dist(u)
    144                           - 1));
     156              << std::abs(bfs_test.dist(v) - bfs_test.dist(u) - 1));
    145157      }
    146158    }
     159  }
     160
     161  {
     162    NullMap<Node,Arc> myPredMap;
     163    bfs(G).predMap(myPredMap).run(s);
    147164  }
    148165}
  • test/dfs_test.cc

    r228 r278  
    2121#include <lemon/list_graph.h>
    2222#include <lemon/lgf_reader.h>
    23 
    2423#include <lemon/dfs.h>
    2524#include <lemon/path.h>
     
    8988
    9089  Digraph g;
    91   dfs(g,Node()).run();
    92   dfs(g).source(Node()).run();
     90  bool b;
     91  dfs(g).run(Node());
     92  b=dfs(g).run(Node(),Node());
     93  dfs(g).run();
    9394  dfs(g)
    94     .predMap(concepts::WriteMap<Node,Arc>())
    95     .distMap(concepts::WriteMap<Node,VType>())
     95    .predMap(concepts::ReadWriteMap<Node,Arc>())
     96    .distMap(concepts::ReadWriteMap<Node,VType>())
    9697    .reachedMap(concepts::ReadWriteMap<Node,bool>())
    9798    .processedMap(concepts::WriteMap<Node,bool>())
    9899    .run(Node());
     100  b=dfs(g)
     101    .predMap(concepts::ReadWriteMap<Node,Arc>())
     102    .distMap(concepts::ReadWriteMap<Node,VType>())
     103    .reachedMap(concepts::ReadWriteMap<Node,bool>())
     104    .processedMap(concepts::WriteMap<Node,bool>())
     105    .path(concepts::Path<Digraph>())
     106    .dist(VType())
     107    .run(Node(),Node());
     108  dfs(g)
     109    .predMap(concepts::ReadWriteMap<Node,Arc>())
     110    .distMap(concepts::ReadWriteMap<Node,VType>())
     111    .reachedMap(concepts::ReadWriteMap<Node,bool>())
     112    .processedMap(concepts::WriteMap<Node,bool>())
     113    .run();
    99114}
    100115
     
    130145        check(dfs_test.dist(v) - dfs_test.dist(u) == 1,
    131146              "Wrong distance. (" << dfs_test.dist(u) << "->"
    132               <<dfs_test.dist(v) << ')');
     147              << dfs_test.dist(v) << ")");
    133148      }
    134149    }
     150  }
     151
     152  {
     153    NullMap<Node,Arc> myPredMap;
     154    dfs(G).predMap(myPredMap).run(s);
    135155  }
    136156}
  • test/dijkstra_test.cc

    r228 r278  
    2121#include <lemon/list_graph.h>
    2222#include <lemon/lgf_reader.h>
    23 
    2423#include <lemon/dijkstra.h>
    2524#include <lemon/path.h>
     
    6564  DType::DistMap d(G);
    6665  DType::PredMap p(G);
    67   //  DType::PredNodeMap pn(G);
    6866  LengthMap length;
    6967
     
    7775  d  = dijkstra_test.distMap();
    7876  p  = dijkstra_test.predMap();
    79   //  pn = dijkstra_test.predNodeMap();
    8077  b  = dijkstra_test.reached(n);
    8178
     
    9289
    9390  Digraph g;
    94   dijkstra(g,LengthMap(),Node()).run();
    95   dijkstra(g,LengthMap()).source(Node()).run();
     91  bool b;
     92  dijkstra(g,LengthMap()).run(Node());
     93  b=dijkstra(g,LengthMap()).run(Node(),Node());
    9694  dijkstra(g,LengthMap())
    97     .predMap(concepts::WriteMap<Node,Arc>())
    98     .distMap(concepts::WriteMap<Node,VType>())
     95    .predMap(concepts::ReadWriteMap<Node,Arc>())
     96    .distMap(concepts::ReadWriteMap<Node,VType>())
     97    .processedMap(concepts::WriteMap<Node,bool>())
    9998    .run(Node());
     99  b=dijkstra(g,LengthMap())
     100    .predMap(concepts::ReadWriteMap<Node,Arc>())
     101    .distMap(concepts::ReadWriteMap<Node,VType>())
     102    .processedMap(concepts::WriteMap<Node,bool>())
     103    .path(concepts::Path<Digraph>())
     104    .dist(VType())
     105    .run(Node(),Node());
    100106}
    101107
     
    123129
    124130  Path<Digraph> p = dijkstra_test.path(t);
    125   check(p.length()==3,"getPath() found a wrong path.");
     131  check(p.length()==3,"path() found a wrong path.");
    126132  check(checkPath(G, p),"path() found a wrong path.");
    127133  check(pathSource(G, p) == s,"path() found a wrong path.");
     
    133139    check( !dijkstra_test.reached(u) ||
    134140           (dijkstra_test.dist(v) - dijkstra_test.dist(u) <= length[e]),
    135            "dist(target)-dist(source)-arc_length= " <<
     141           "Wrong output. dist(target)-dist(source)-arc_length=" <<
    136142           dijkstra_test.dist(v) - dijkstra_test.dist(u) - length[e]);
    137143  }
Note: See TracChangeset for help on using the changeset viewer.