diff --git a/test/bfs_test.cc b/test/bfs_test.cc --- a/test/bfs_test.cc +++ b/test/bfs_test.cc @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -27,6 +28,28 @@ using namespace lemon; +char test_lgf[] = + "@nodes\n" + "label\n" + "0\n" + "1\n" + "2\n" + "3\n" + "4\n" + "5\n" + "@arcs\n" + " label\n" + "0 1 0\n" + "1 2 1\n" + "2 3 2\n" + "3 4 3\n" + "0 3 4\n" + "0 3 5\n" + "5 2 6\n" + "@attributes\n" + "source 0\n" + "target 4\n"; + void checkBfsCompile() { typedef concepts::Digraph Digraph; @@ -49,6 +72,7 @@ e = bfs_test.predArc(n); n = bfs_test.predNode(n); d = bfs_test.distMap(); + p = bfs_test.predMap(); // pn = bfs_test.predNodeMap(); b = bfs_test.reached(n); @@ -80,41 +104,45 @@ Digraph G; Node s, t; - PetStruct ps = addPetersen(G, 5); - s=ps.outer[2]; - t=ps.inner[0]; + std::istringstream input(test_lgf); + digraphReader(input, G). + node("source", s). + node("target", t). + run(); Bfs bfs_test(G); bfs_test.run(s); - check(bfs_test.dist(t)==3,"Bfs found a wrong path." << bfs_test.dist(t)); + check(bfs_test.dist(t)==2,"Bfs found a wrong path." << bfs_test.dist(t)); Path p = bfs_test.path(t); - check(p.length()==3,"path() found a wrong path."); + check(p.length()==2,"path() found a wrong path."); check(checkPath(G, p),"path() found a wrong path."); check(pathSource(G, p) == s,"path() found a wrong path."); check(pathTarget(G, p) == t,"path() found a wrong path."); - for(ArcIt e(G); e!=INVALID; ++e) { - Node u=G.source(e); - Node v=G.target(e); + for(ArcIt a(G); a!=INVALID; ++a) { + Node u=G.source(a); + Node v=G.target(a); check( !bfs_test.reached(u) || (bfs_test.dist(v) <= bfs_test.dist(u)+1), - "Wrong output."); + "Wrong output." << G.id(v) << ' ' << G.id(u)); } for(NodeIt v(G); v!=INVALID; ++v) { - check(bfs_test.reached(v),"Each node should be reached."); - if ( bfs_test.predArc(v)!=INVALID ) { - Arc e=bfs_test.predArc(v); - Node u=G.source(e); - check(u==bfs_test.predNode(v),"Wrong tree."); - check(bfs_test.dist(v) - bfs_test.dist(u) == 1, - "Wrong distance. Difference: " - << std::abs(bfs_test.dist(v) - bfs_test.dist(u) - - 1)); + if (bfs_test.reached(v)) { + check(v==s || bfs_test.predArc(v)!=INVALID, "Wrong tree."); + if (bfs_test.predArc(v)!=INVALID ) { + Arc a=bfs_test.predArc(v); + Node u=G.source(a); + check(u==bfs_test.predNode(v),"Wrong tree."); + check(bfs_test.dist(v) - bfs_test.dist(u) == 1, + "Wrong distance. Difference: " + << std::abs(bfs_test.dist(v) - bfs_test.dist(u) + - 1)); + } } } }