diff -r ce9438c5a82d -r 4297098d9677 src/test/bfs_test.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/bfs_test.cc Mon Aug 30 12:01:47 2004 +0000 @@ -0,0 +1,89 @@ +#include "test_tools.h" +#include +#include + +using namespace hugo; + +const int PET_SIZE =5; + + +void check_Bfs_SmartGraph_Compile() +{ + typedef int VType; + typedef SmartGraph Graph; + + typedef Graph::Edge Edge; + typedef Graph::Node Node; + typedef Graph::EdgeIt EdgeIt; + typedef Graph::NodeIt NodeIt; + typedef Graph::EdgeMap LengthMap; + + typedef Bfs BType; + + Graph G; + Node n; + Edge e; + VType l; + bool b; + BType::DistMap d(G); + BType::PredMap p(G); + BType::PredNodeMap pn(G); + LengthMap cap(G); + + BType bfs_test(G); + + bfs_test.run(n); + + l = bfs_test.dist(n); + e = bfs_test.pred(n); + n = bfs_test.predNode(n); + d = bfs_test.distMap(); + p = bfs_test.predMap(); + pn = bfs_test.predNodeMap(); + b = bfs_test.reached(n); + +} + +int main() +{ + + typedef SmartGraph Graph; + + typedef Graph::Edge Edge; + typedef Graph::Node Node; + typedef Graph::EdgeIt EdgeIt; + typedef Graph::NodeIt NodeIt; + typedef Graph::EdgeMap LengthMap; + + Graph G; + Node s, t; + PetStruct ps = addPetersen(G,PET_SIZE); + + s=ps.outer[2]; + t=ps.inner[0]; + + Bfs bfs_test(G); + bfs_test.run(s); + + check(bfs_test.dist(t)==3,"Bfs found a wrong path. " << bfs_test.dist(t)); + + + for(EdgeIt e(G); e==INVALID; ++e) { + Node u=G.tail(e); + Node v=G.head(e); + check( !bfs_test.reached(u) || + (bfs_test.dist(v) > bfs_test.dist(u)+1), + "Wrong output."); + } + + ///\bug This works only for integer lengths + for(NodeIt v(G); v==INVALID; ++v) + if ( bfs_test.reached(v) ) { + Edge e=bfs_test.pred(v); + Node u=G.tail(e); + check(bfs_test.dist(v) - bfs_test.dist(u) == 1, + "Bad shortest path tree edge! Difference: " + << std::abs(bfs_test.dist(v) - bfs_test.dist(u) + - 1)); + } +}