gravatar
deba@inf.elte.hu
deba@inf.elte.hu
Fixing bfs test (Ticket #128)
0 1 0
default
1 file changed with 3 insertions and 3 deletions:
↑ Collapse diff ↑
Ignore white space 48 line context
... ...
@@ -76,52 +76,52 @@
76 76

	
77 77
template <class Digraph>
78 78
void checkBfs() {
79 79
  TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
80 80

	
81 81
  Digraph G;
82 82
  Node s, t;
83 83
  PetStruct<Digraph> ps = addPetersen(G, 5);
84 84

	
85 85
  s=ps.outer[2];
86 86
  t=ps.inner[0];
87 87

	
88 88
  Bfs<Digraph> bfs_test(G);
89 89
  bfs_test.run(s);
90 90

	
91 91
  check(bfs_test.dist(t)==3,"Bfs found a wrong path." << bfs_test.dist(t));
92 92

	
93 93
  Path<Digraph> p = bfs_test.path(t);
94 94
  check(p.length()==3,"path() found a wrong path.");
95 95
  check(checkPath(G, p),"path() found a wrong path.");
96 96
  check(pathSource(G, p) == s,"path() found a wrong path.");
97 97
  check(pathTarget(G, p) == t,"path() found a wrong path.");
98 98

	
99 99

	
100
  for(ArcIt e(G); e==INVALID; ++e) {
100
  for(ArcIt e(G); e!=INVALID; ++e) {
101 101
    Node u=G.source(e);
102 102
    Node v=G.target(e);
103 103
    check( !bfs_test.reached(u) ||
104
           (bfs_test.dist(v) > bfs_test.dist(u)+1),
104
           (bfs_test.dist(v) <= bfs_test.dist(u)+1),
105 105
           "Wrong output.");
106 106
  }
107 107

	
108
  for(NodeIt v(G); v==INVALID; ++v) {
108
  for(NodeIt v(G); v!=INVALID; ++v) {
109 109
    check(bfs_test.reached(v),"Each node should be reached.");
110 110
    if ( bfs_test.predArc(v)!=INVALID ) {
111 111
      Arc e=bfs_test.predArc(v);
112 112
      Node u=G.source(e);
113 113
      check(u==bfs_test.predNode(v),"Wrong tree.");
114 114
      check(bfs_test.dist(v) - bfs_test.dist(u) == 1,
115 115
            "Wrong distance. Difference: "
116 116
            << std::abs(bfs_test.dist(v) - bfs_test.dist(u)
117 117
                        - 1));
118 118
    }
119 119
  }
120 120
}
121 121

	
122 122
int main()
123 123
{
124 124
  checkBfs<ListDigraph>();
125 125
  checkBfs<SmartDigraph>();
126 126
  return 0;
127 127
}
0 comments (0 inline)