184 check(!g.valid(g.nodeFromId(-1)), "Wrong validity check"); |
185 check(!g.valid(g.nodeFromId(-1)), "Wrong validity check"); |
185 check(!g.valid(g.edgeFromId(-1)), "Wrong validity check"); |
186 check(!g.valid(g.edgeFromId(-1)), "Wrong validity check"); |
186 check(!g.valid(g.arcFromId(-1)), "Wrong validity check"); |
187 check(!g.valid(g.arcFromId(-1)), "Wrong validity check"); |
187 } |
188 } |
188 |
189 |
189 void checkGridGraph(const GridGraph& g, int w, int h) { |
190 void checkGridGraph(int width, int height) { |
190 check(g.width() == w, "Wrong width"); |
191 typedef GridGraph Graph; |
191 check(g.height() == h, "Wrong height"); |
192 GRAPH_TYPEDEFS(Graph); |
192 |
193 Graph G(width, height); |
193 for (int i = 0; i < w; ++i) { |
194 |
194 for (int j = 0; j < h; ++j) { |
195 check(G.width() == width, "Wrong row number"); |
195 check(g.col(g(i, j)) == i, "Wrong col"); |
196 check(G.height() == height, "Wrong column number"); |
196 check(g.row(g(i, j)) == j, "Wrong row"); |
197 |
197 } |
198 for (int i = 0; i < width; ++i) { |
198 } |
199 for (int j = 0; j < height; ++j) { |
199 |
200 check(G.col(G(i, j)) == i, "Wrong column"); |
200 for (int i = 0; i < w; ++i) { |
201 check(G.row(G(i, j)) == j, "Wrong row"); |
201 for (int j = 0; j < h - 1; ++j) { |
202 check(G.pos(G(i, j)).x == i, "Wrong column"); |
202 check(g.source(g.down(g(i, j))) == g(i, j), "Wrong down"); |
203 check(G.pos(G(i, j)).y == j, "Wrong row"); |
203 check(g.target(g.down(g(i, j))) == g(i, j + 1), "Wrong down"); |
204 } |
204 } |
205 } |
205 check(g.down(g(i, h - 1)) == INVALID, "Wrong down"); |
206 |
206 } |
207 for (int j = 0; j < height; ++j) { |
207 |
208 for (int i = 0; i < width - 1; ++i) { |
208 for (int i = 0; i < w; ++i) { |
209 check(G.source(G.right(G(i, j))) == G(i, j), "Wrong right"); |
209 for (int j = 1; j < h; ++j) { |
210 check(G.target(G.right(G(i, j))) == G(i + 1, j), "Wrong right"); |
210 check(g.source(g.up(g(i, j))) == g(i, j), "Wrong up"); |
211 } |
211 check(g.target(g.up(g(i, j))) == g(i, j - 1), "Wrong up"); |
212 check(G.right(G(width - 1, j)) == INVALID, "Wrong right"); |
212 } |
213 } |
213 check(g.up(g(i, 0)) == INVALID, "Wrong up"); |
214 |
214 } |
215 for (int j = 0; j < height; ++j) { |
215 |
216 for (int i = 1; i < width; ++i) { |
216 for (int j = 0; j < h; ++j) { |
217 check(G.source(G.left(G(i, j))) == G(i, j), "Wrong left"); |
217 for (int i = 0; i < w - 1; ++i) { |
218 check(G.target(G.left(G(i, j))) == G(i - 1, j), "Wrong left"); |
218 check(g.source(g.right(g(i, j))) == g(i, j), "Wrong right"); |
219 } |
219 check(g.target(g.right(g(i, j))) == g(i + 1, j), "Wrong right"); |
220 check(G.left(G(0, j)) == INVALID, "Wrong left"); |
220 } |
221 } |
221 check(g.right(g(w - 1, j)) == INVALID, "Wrong right"); |
222 |
222 } |
223 for (int i = 0; i < width; ++i) { |
223 |
224 for (int j = 0; j < height - 1; ++j) { |
224 for (int j = 0; j < h; ++j) { |
225 check(G.source(G.up(G(i, j))) == G(i, j), "Wrong up"); |
225 for (int i = 1; i < w; ++i) { |
226 check(G.target(G.up(G(i, j))) == G(i, j + 1), "Wrong up"); |
226 check(g.source(g.left(g(i, j))) == g(i, j), "Wrong left"); |
227 } |
227 check(g.target(g.left(g(i, j))) == g(i - 1, j), "Wrong left"); |
228 check(G.up(G(i, height - 1)) == INVALID, "Wrong up"); |
228 } |
229 } |
229 check(g.left(g(0, j)) == INVALID, "Wrong left"); |
230 |
230 } |
231 for (int i = 0; i < width; ++i) { |
231 |
232 for (int j = 1; j < height; ++j) { |
232 checkGraphNodeList(g, w*h); |
233 check(G.source(G.down(G(i, j))) == G(i, j), "Wrong down"); |
233 checkGraphArcList(g, 2*(2*w*h-w-h)); |
234 check(G.target(G.down(G(i, j))) == G(i, j - 1), "Wrong down"); |
234 checkGraphEdgeList(g, 2*w*h-w-h); |
235 } |
235 |
236 check(G.down(G(i, 0)) == INVALID, "Wrong down"); |
236 checkGraphOutArcList(g, g(0,0), 2); |
237 } |
237 checkGraphOutArcList(g, g(0,1), 3); |
238 |
238 checkGraphOutArcList(g, g(w-2,h-2), 4); |
239 checkGraphNodeList(G, width * height); |
239 |
240 checkGraphEdgeList(G, width * (height - 1) + (width - 1) * height); |
240 checkGraphInArcList(g, g(0,0), 2); |
241 checkGraphArcList(G, 2 * (width * (height - 1) + (width - 1) * height)); |
241 checkGraphInArcList(g, g(0,1), 3); |
242 |
242 checkGraphInArcList(g, g(w-2,h-2), 4); |
243 for (NodeIt n(G); n != INVALID; ++n) { |
243 |
244 int nb = 4; |
244 checkGraphIncEdgeList(g, g(0,0), 2); |
245 if (G.col(n) == 0) --nb; |
245 checkGraphIncEdgeList(g, g(0,1), 3); |
246 if (G.col(n) == width - 1) --nb; |
246 checkGraphIncEdgeList(g, g(w-2,h-2), 4); |
247 if (G.row(n) == 0) --nb; |
247 |
248 if (G.row(n) == height - 1) --nb; |
248 checkGraphConArcList(g, 2*(2*w*h-w-h)); |
249 |
249 checkGraphConEdgeList(g, 2*w*h-w-h); |
250 checkGraphOutArcList(G, n, nb); |
250 |
251 checkGraphInArcList(G, n, nb); |
251 checkArcDirections(g); |
252 checkGraphIncEdgeList(G, n, nb); |
252 |
253 } |
253 checkNodeIds(g); |
254 |
254 checkArcIds(g); |
255 checkArcDirections(G); |
255 checkEdgeIds(g); |
256 |
256 checkGraphNodeMap(g); |
257 checkGraphConArcList(G, 2 * (width * (height - 1) + (width - 1) * height)); |
257 checkGraphArcMap(g); |
258 checkGraphConEdgeList(G, width * (height - 1) + (width - 1) * height); |
258 checkGraphEdgeMap(g); |
259 |
|
260 checkNodeIds(G); |
|
261 checkArcIds(G); |
|
262 checkEdgeIds(G); |
|
263 checkGraphNodeMap(G); |
|
264 checkGraphArcMap(G); |
|
265 checkGraphEdgeMap(G); |
|
266 |
259 } |
267 } |
260 |
268 |
261 void checkGraphs() { |
269 void checkGraphs() { |
262 { // Checking ListGraph |
270 { // Checking ListGraph |
263 checkGraph<ListGraph>(); |
271 checkGraph<ListGraph>(); |