test/graph_test.cc
changeset 346 ada5f74d1c9e
parent 228 b6732e0d38c5
child 347 160bf92c7cdc
equal deleted inserted replaced
6:1c3fb61c4e8f 7:29e0daf5891b
    18 
    18 
    19 #include <lemon/concepts/graph.h>
    19 #include <lemon/concepts/graph.h>
    20 #include <lemon/list_graph.h>
    20 #include <lemon/list_graph.h>
    21 #include <lemon/smart_graph.h>
    21 #include <lemon/smart_graph.h>
    22 // #include <lemon/full_graph.h>
    22 // #include <lemon/full_graph.h>
    23 // #include <lemon/grid_graph.h>
    23 #include <lemon/grid_graph.h>
    24 
    24 
    25 #include "test_tools.h"
    25 #include "test_tools.h"
    26 #include "graph_test.h"
    26 #include "graph_test.h"
    27 
    27 
    28 using namespace lemon;
    28 using namespace lemon;
   124     checkConcept<ExtendableGraphComponent<>, SmartGraph>();
   124     checkConcept<ExtendableGraphComponent<>, SmartGraph>();
   125     checkConcept<ClearableGraphComponent<>, SmartGraph>();
   125     checkConcept<ClearableGraphComponent<>, SmartGraph>();
   126   }
   126   }
   127 //  { // Checking FullGraph
   127 //  { // Checking FullGraph
   128 //    checkConcept<Graph, FullGraph>();
   128 //    checkConcept<Graph, FullGraph>();
   129 //    checkGraphIterators<FullGraph>();
       
   130 //  }
   129 //  }
   131 //  { // Checking GridGraph
   130   { // Checking GridGraph
   132 //    checkConcept<Graph, GridGraph>();
   131     checkConcept<Graph, GridGraph>();
   133 //    checkGraphIterators<GridGraph>();
   132   }
   134 //  }
       
   135 }
   133 }
   136 
   134 
   137 template <typename Graph>
   135 template <typename Graph>
   138 void checkGraphValidity() {
   136 void checkGraphValidity() {
   139   TEMPLATE_GRAPH_TYPEDEFS(Graph);
   137   TEMPLATE_GRAPH_TYPEDEFS(Graph);
   186   check(!g.valid(g.nodeFromId(-1)), "Wrong validity check");
   184   check(!g.valid(g.nodeFromId(-1)), "Wrong validity check");
   187   check(!g.valid(g.edgeFromId(-1)), "Wrong validity check");
   185   check(!g.valid(g.edgeFromId(-1)), "Wrong validity check");
   188   check(!g.valid(g.arcFromId(-1)), "Wrong validity check");
   186   check(!g.valid(g.arcFromId(-1)), "Wrong validity check");
   189 }
   187 }
   190 
   188 
   191 // void checkGridGraph(const GridGraph& g, int w, int h) {
   189 void checkGridGraph(const GridGraph& g, int w, int h) {
   192 //   check(g.width() == w, "Wrong width");
   190   check(g.width() == w, "Wrong width");
   193 //   check(g.height() == h, "Wrong height");
   191   check(g.height() == h, "Wrong height");
   194 
   192 
   195 //   for (int i = 0; i < w; ++i) {
   193   for (int i = 0; i < w; ++i) {
   196 //     for (int j = 0; j < h; ++j) {
   194     for (int j = 0; j < h; ++j) {
   197 //       check(g.col(g(i, j)) == i, "Wrong col");
   195       check(g.col(g(i, j)) == i, "Wrong col");
   198 //       check(g.row(g(i, j)) == j, "Wrong row");
   196       check(g.row(g(i, j)) == j, "Wrong row");
   199 //     }
   197     }
   200 //   }
   198   }
   201 
   199 
   202 //   for (int i = 0; i < w; ++i) {
   200   for (int i = 0; i < w; ++i) {
   203 //     for (int j = 0; j < h - 1; ++j) {
   201     for (int j = 0; j < h - 1; ++j) {
   204 //       check(g.source(g.down(g(i, j))) == g(i, j), "Wrong down");
   202       check(g.source(g.down(g(i, j))) == g(i, j), "Wrong down");
   205 //       check(g.target(g.down(g(i, j))) == g(i, j + 1), "Wrong down");
   203       check(g.target(g.down(g(i, j))) == g(i, j + 1), "Wrong down");
   206 //     }
   204     }
   207 //     check(g.down(g(i, h - 1)) == INVALID, "Wrong down");
   205     check(g.down(g(i, h - 1)) == INVALID, "Wrong down");
   208 //   }
   206   }
   209 
   207 
   210 //   for (int i = 0; i < w; ++i) {
   208   for (int i = 0; i < w; ++i) {
   211 //     for (int j = 1; j < h; ++j) {
   209     for (int j = 1; j < h; ++j) {
   212 //       check(g.source(g.up(g(i, j))) == g(i, j), "Wrong up");
   210       check(g.source(g.up(g(i, j))) == g(i, j), "Wrong up");
   213 //       check(g.target(g.up(g(i, j))) == g(i, j - 1), "Wrong up");
   211       check(g.target(g.up(g(i, j))) == g(i, j - 1), "Wrong up");
   214 //     }
   212     }
   215 //     check(g.up(g(i, 0)) == INVALID, "Wrong up");
   213     check(g.up(g(i, 0)) == INVALID, "Wrong up");
   216 //   }
   214   }
   217 
   215 
   218 //   for (int j = 0; j < h; ++j) {
   216   for (int j = 0; j < h; ++j) {
   219 //     for (int i = 0; i < w - 1; ++i) {
   217     for (int i = 0; i < w - 1; ++i) {
   220 //       check(g.source(g.right(g(i, j))) == g(i, j), "Wrong right");
   218       check(g.source(g.right(g(i, j))) == g(i, j), "Wrong right");
   221 //       check(g.target(g.right(g(i, j))) == g(i + 1, j), "Wrong right");
   219       check(g.target(g.right(g(i, j))) == g(i + 1, j), "Wrong right");
   222 //     }
   220     }
   223 //     check(g.right(g(w - 1, j)) == INVALID, "Wrong right");
   221     check(g.right(g(w - 1, j)) == INVALID, "Wrong right");
   224 //   }
   222   }
   225 
   223 
   226 //   for (int j = 0; j < h; ++j) {
   224   for (int j = 0; j < h; ++j) {
   227 //     for (int i = 1; i < w; ++i) {
   225     for (int i = 1; i < w; ++i) {
   228 //       check(g.source(g.left(g(i, j))) == g(i, j), "Wrong left");
   226       check(g.source(g.left(g(i, j))) == g(i, j), "Wrong left");
   229 //       check(g.target(g.left(g(i, j))) == g(i - 1, j), "Wrong left");
   227       check(g.target(g.left(g(i, j))) == g(i - 1, j), "Wrong left");
   230 //     }
   228     }
   231 //     check(g.left(g(0, j)) == INVALID, "Wrong left");
   229     check(g.left(g(0, j)) == INVALID, "Wrong left");
   232 //   }
   230   }
   233 // }
   231 
       
   232   checkGraphNodeList(g, w*h);
       
   233   checkGraphArcList(g, 2*(2*w*h-w-h));
       
   234   checkGraphEdgeList(g, 2*w*h-w-h);
       
   235 
       
   236   checkGraphOutArcList(g, g(0,0), 2);
       
   237   checkGraphOutArcList(g, g(0,1), 3);
       
   238   checkGraphOutArcList(g, g(w-2,h-2), 4);
       
   239 
       
   240   checkGraphInArcList(g, g(0,0), 2);
       
   241   checkGraphInArcList(g, g(0,1), 3);
       
   242   checkGraphInArcList(g, g(w-2,h-2), 4);
       
   243 
       
   244   checkGraphIncEdgeList(g, g(0,0), 2);
       
   245   checkGraphIncEdgeList(g, g(0,1), 3);
       
   246   checkGraphIncEdgeList(g, g(w-2,h-2), 4);
       
   247 
       
   248   checkGraphConArcList(g, 2*(2*w*h-w-h));
       
   249   checkGraphConEdgeList(g, 2*w*h-w-h);
       
   250 
       
   251   checkArcDirections(g);
       
   252 
       
   253   checkNodeIds(g);
       
   254   checkArcIds(g);
       
   255   checkEdgeIds(g);
       
   256   checkGraphNodeMap(g);
       
   257   checkGraphArcMap(g);
       
   258   checkGraphEdgeMap(g);
       
   259 }
   234 
   260 
   235 void checkGraphs() {
   261 void checkGraphs() {
   236   { // Checking ListGraph
   262   { // Checking ListGraph
   237     checkGraph<ListGraph>();
   263     checkGraph<ListGraph>();
   238     checkGraphValidityErase<ListGraph>();
   264     checkGraphValidityErase<ListGraph>();
   244 //   { // Checking FullGraph
   270 //   { // Checking FullGraph
   245 //     FullGraph g(5);
   271 //     FullGraph g(5);
   246 //     checkGraphNodeList(g, 5);
   272 //     checkGraphNodeList(g, 5);
   247 //     checkGraphEdgeList(g, 10);
   273 //     checkGraphEdgeList(g, 10);
   248 //   }
   274 //   }
   249 //   { // Checking GridGraph
   275   { // Checking GridGraph
   250 //     GridGraph g(5, 6);
   276     GridGraph g(5, 6);
   251 //     checkGraphNodeList(g, 30);
   277     checkGridGraph(g, 5, 6);
   252 //     checkGraphEdgeList(g, 49);
   278   }
   253 //     checkGridGraph(g, 5, 6);
       
   254 //   }
       
   255 }
   279 }
   256 
   280 
   257 int main() {
   281 int main() {
   258   checkConcepts();
   282   checkConcepts();
   259   checkGraphs();
   283   checkGraphs();