test/graph_test.cc
changeset 337 560e4b6d020d
parent 335 160bf92c7cdc
child 356 99f1bdf8f7db
     1.1 --- a/test/graph_test.cc	Wed Oct 22 14:41:18 2008 +0100
     1.2 +++ b/test/graph_test.cc	Wed Oct 22 22:14:00 2008 +0100
     1.3 @@ -20,7 +20,7 @@
     1.4  #include <lemon/list_graph.h>
     1.5  #include <lemon/smart_graph.h>
     1.6  // #include <lemon/full_graph.h>
     1.7 -// #include <lemon/grid_graph.h>
     1.8 +#include <lemon/grid_graph.h>
     1.9  
    1.10  #include "test_tools.h"
    1.11  #include "graph_test.h"
    1.12 @@ -128,10 +128,9 @@
    1.13  //    checkConcept<Graph, FullGraph>();
    1.14  //    checkGraphIterators<FullGraph>();
    1.15  //  }
    1.16 -//  { // Checking GridGraph
    1.17 -//    checkConcept<Graph, GridGraph>();
    1.18 -//    checkGraphIterators<GridGraph>();
    1.19 -//  }
    1.20 +  { // Checking GridGraph
    1.21 +    checkConcept<Graph, GridGraph>();
    1.22 +  }
    1.23  }
    1.24  
    1.25  template <typename Graph>
    1.26 @@ -188,49 +187,84 @@
    1.27    check(!g.valid(g.arcFromId(-1)), "Wrong validity check");
    1.28  }
    1.29  
    1.30 -// void checkGridGraph(const GridGraph& g, int w, int h) {
    1.31 -//   check(g.width() == w, "Wrong width");
    1.32 -//   check(g.height() == h, "Wrong height");
    1.33 +void checkGridGraph(int width, int height) {
    1.34 +  typedef GridGraph Graph;
    1.35 +  GRAPH_TYPEDEFS(Graph);
    1.36 +  Graph G(width, height);
    1.37  
    1.38 -//   for (int i = 0; i < w; ++i) {
    1.39 -//     for (int j = 0; j < h; ++j) {
    1.40 -//       check(g.col(g(i, j)) == i, "Wrong col");
    1.41 -//       check(g.row(g(i, j)) == j, "Wrong row");
    1.42 -//     }
    1.43 -//   }
    1.44 +  check(G.width() == width, "Wrong column number");
    1.45 +  check(G.height() == height, "Wrong row number");
    1.46  
    1.47 -//   for (int i = 0; i < w; ++i) {
    1.48 -//     for (int j = 0; j < h - 1; ++j) {
    1.49 -//       check(g.source(g.down(g(i, j))) == g(i, j), "Wrong down");
    1.50 -//       check(g.target(g.down(g(i, j))) == g(i, j + 1), "Wrong down");
    1.51 -//     }
    1.52 -//     check(g.down(g(i, h - 1)) == INVALID, "Wrong down");
    1.53 -//   }
    1.54 +  for (int i = 0; i < width; ++i) {
    1.55 +    for (int j = 0; j < height; ++j) {
    1.56 +      check(G.col(G(i, j)) == i, "Wrong column");
    1.57 +      check(G.row(G(i, j)) == j, "Wrong row");
    1.58 +      check(G.pos(G(i, j)).x == i, "Wrong column");
    1.59 +      check(G.pos(G(i, j)).y == j, "Wrong row");
    1.60 +    }
    1.61 +  }
    1.62  
    1.63 -//   for (int i = 0; i < w; ++i) {
    1.64 -//     for (int j = 1; j < h; ++j) {
    1.65 -//       check(g.source(g.up(g(i, j))) == g(i, j), "Wrong up");
    1.66 -//       check(g.target(g.up(g(i, j))) == g(i, j - 1), "Wrong up");
    1.67 -//     }
    1.68 -//     check(g.up(g(i, 0)) == INVALID, "Wrong up");
    1.69 -//   }
    1.70 +  for (int j = 0; j < height; ++j) {
    1.71 +    for (int i = 0; i < width - 1; ++i) {
    1.72 +      check(G.source(G.right(G(i, j))) == G(i, j), "Wrong right");
    1.73 +      check(G.target(G.right(G(i, j))) == G(i + 1, j), "Wrong right");
    1.74 +    }
    1.75 +    check(G.right(G(width - 1, j)) == INVALID, "Wrong right");
    1.76 +  }
    1.77  
    1.78 -//   for (int j = 0; j < h; ++j) {
    1.79 -//     for (int i = 0; i < w - 1; ++i) {
    1.80 -//       check(g.source(g.right(g(i, j))) == g(i, j), "Wrong right");
    1.81 -//       check(g.target(g.right(g(i, j))) == g(i + 1, j), "Wrong right");
    1.82 -//     }
    1.83 -//     check(g.right(g(w - 1, j)) == INVALID, "Wrong right");
    1.84 -//   }
    1.85 +  for (int j = 0; j < height; ++j) {
    1.86 +    for (int i = 1; i < width; ++i) {
    1.87 +      check(G.source(G.left(G(i, j))) == G(i, j), "Wrong left");
    1.88 +      check(G.target(G.left(G(i, j))) == G(i - 1, j), "Wrong left");
    1.89 +    }
    1.90 +    check(G.left(G(0, j)) == INVALID, "Wrong left");
    1.91 +  }
    1.92  
    1.93 -//   for (int j = 0; j < h; ++j) {
    1.94 -//     for (int i = 1; i < w; ++i) {
    1.95 -//       check(g.source(g.left(g(i, j))) == g(i, j), "Wrong left");
    1.96 -//       check(g.target(g.left(g(i, j))) == g(i - 1, j), "Wrong left");
    1.97 -//     }
    1.98 -//     check(g.left(g(0, j)) == INVALID, "Wrong left");
    1.99 -//   }
   1.100 -// }
   1.101 +  for (int i = 0; i < width; ++i) {
   1.102 +    for (int j = 0; j < height - 1; ++j) {
   1.103 +      check(G.source(G.up(G(i, j))) == G(i, j), "Wrong up");
   1.104 +      check(G.target(G.up(G(i, j))) == G(i, j + 1), "Wrong up");
   1.105 +    }
   1.106 +    check(G.up(G(i, height - 1)) == INVALID, "Wrong up");
   1.107 +  }
   1.108 +
   1.109 +  for (int i = 0; i < width; ++i) {
   1.110 +    for (int j = 1; j < height; ++j) {
   1.111 +      check(G.source(G.down(G(i, j))) == G(i, j), "Wrong down");
   1.112 +      check(G.target(G.down(G(i, j))) == G(i, j - 1), "Wrong down");
   1.113 +    }
   1.114 +    check(G.down(G(i, 0)) == INVALID, "Wrong down");
   1.115 +  }
   1.116 +
   1.117 +  checkGraphNodeList(G, width * height);
   1.118 +  checkGraphEdgeList(G, width * (height - 1) + (width - 1) * height);
   1.119 +  checkGraphArcList(G, 2 * (width * (height - 1) + (width - 1) * height));
   1.120 +
   1.121 +  for (NodeIt n(G); n != INVALID; ++n) {
   1.122 +    int nb = 4;
   1.123 +    if (G.col(n) == 0) --nb;
   1.124 +    if (G.col(n) == width - 1) --nb;
   1.125 +    if (G.row(n) == 0) --nb;
   1.126 +    if (G.row(n) == height - 1) --nb;
   1.127 +
   1.128 +    checkGraphOutArcList(G, n, nb);
   1.129 +    checkGraphInArcList(G, n, nb);
   1.130 +    checkGraphIncEdgeList(G, n, nb);
   1.131 +  }
   1.132 +
   1.133 +  checkArcDirections(G);
   1.134 +
   1.135 +  checkGraphConArcList(G, 2 * (width * (height - 1) + (width - 1) * height));
   1.136 +  checkGraphConEdgeList(G, width * (height - 1) + (width - 1) * height);
   1.137 +
   1.138 +  checkNodeIds(G);
   1.139 +  checkArcIds(G);
   1.140 +  checkEdgeIds(G);
   1.141 +  checkGraphNodeMap(G);
   1.142 +  checkGraphArcMap(G);
   1.143 +  checkGraphEdgeMap(G);
   1.144 +
   1.145 +}
   1.146  
   1.147  void checkGraphs() {
   1.148    { // Checking ListGraph
   1.149 @@ -246,12 +280,13 @@
   1.150  //     checkGraphNodeList(g, 5);
   1.151  //     checkGraphEdgeList(g, 10);
   1.152  //   }
   1.153 -//   { // Checking GridGraph
   1.154 -//     GridGraph g(5, 6);
   1.155 -//     checkGraphNodeList(g, 30);
   1.156 -//     checkGraphEdgeList(g, 49);
   1.157 -//     checkGridGraph(g, 5, 6);
   1.158 -//   }
   1.159 +  { // Checking GridGraph
   1.160 +    checkGridGraph(5, 8);
   1.161 +    checkGridGraph(8, 5);
   1.162 +    checkGridGraph(5, 5);
   1.163 +    checkGridGraph(0, 0);
   1.164 +    checkGridGraph(1, 1);
   1.165 +  }
   1.166  }
   1.167  
   1.168  int main() {