test/graph_test.cc
changeset 264 b6b9e7576af7
parent 209 765619b7cbb2
child 346 ada5f74d1c9e
child 365 37557a46e298
child 387 49d9a36b3b84
equal deleted inserted replaced
5:762788cbb734 6:1c3fb61c4e8f
    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 #include "graph_maps_test.h"
       
    28 
    27 
    29 using namespace lemon;
    28 using namespace lemon;
    30 using namespace lemon::concepts;
    29 using namespace lemon::concepts;
    31 
    30 
    32 void check_concepts() {
    31 template <class Graph>
       
    32 void checkGraph() {
       
    33   TEMPLATE_GRAPH_TYPEDEFS(Graph);
       
    34 
       
    35   Graph G;
       
    36   checkGraphNodeList(G, 0);
       
    37   checkGraphEdgeList(G, 0);
       
    38 
       
    39   Node
       
    40     n1 = G.addNode(),
       
    41     n2 = G.addNode(),
       
    42     n3 = G.addNode();
       
    43   checkGraphNodeList(G, 3);
       
    44   checkGraphEdgeList(G, 0);
       
    45 
       
    46   Edge e1 = G.addEdge(n1, n2);
       
    47   check((G.u(e1) == n1 && G.v(e1) == n2) || (G.u(e1) == n2 && G.v(e1) == n1),
       
    48         "Wrong edge");
       
    49   checkGraphNodeList(G, 3);
       
    50   checkGraphArcList(G, 2);
       
    51   checkGraphEdgeList(G, 1);
       
    52 
       
    53   checkGraphOutArcList(G, n1, 1);
       
    54   checkGraphOutArcList(G, n2, 1);
       
    55   checkGraphOutArcList(G, n3, 0);
       
    56 
       
    57   checkGraphInArcList(G, n1, 1);
       
    58   checkGraphInArcList(G, n2, 1);
       
    59   checkGraphInArcList(G, n3, 0);
       
    60 
       
    61   checkGraphIncEdgeList(G, n1, 1);
       
    62   checkGraphIncEdgeList(G, n2, 1);
       
    63   checkGraphIncEdgeList(G, n3, 0);
       
    64 
       
    65   checkGraphConArcList(G, 2);
       
    66   checkGraphConEdgeList(G, 1);
       
    67 
       
    68   Edge e2 = G.addEdge(n2, n1), e3 = G.addEdge(n2, n3);
       
    69   checkGraphNodeList(G, 3);
       
    70   checkGraphArcList(G, 6);
       
    71   checkGraphEdgeList(G, 3);
       
    72 
       
    73   checkGraphOutArcList(G, n1, 2);
       
    74   checkGraphOutArcList(G, n2, 3);
       
    75   checkGraphOutArcList(G, n3, 1);
       
    76 
       
    77   checkGraphInArcList(G, n1, 2);
       
    78   checkGraphInArcList(G, n2, 3);
       
    79   checkGraphInArcList(G, n3, 1);
       
    80 
       
    81   checkGraphIncEdgeList(G, n1, 2);
       
    82   checkGraphIncEdgeList(G, n2, 3);
       
    83   checkGraphIncEdgeList(G, n3, 1);
       
    84 
       
    85   checkGraphConArcList(G, 6);
       
    86   checkGraphConEdgeList(G, 3);
       
    87 
       
    88   checkArcDirections(G);
       
    89 
       
    90   checkNodeIds(G);
       
    91   checkArcIds(G);
       
    92   checkEdgeIds(G);
       
    93   checkGraphNodeMap(G);
       
    94   checkGraphArcMap(G);
       
    95   checkGraphEdgeMap(G);
       
    96 }
       
    97 
       
    98 void checkConcepts() {
    33   { // Checking graph components
    99   { // Checking graph components
    34     checkConcept<BaseGraphComponent, BaseGraphComponent >();
   100     checkConcept<BaseGraphComponent, BaseGraphComponent >();
    35 
   101 
    36     checkConcept<IDableGraphComponent<>,
   102     checkConcept<IDableGraphComponent<>,
    37       IDableGraphComponent<> >();
   103       IDableGraphComponent<> >();
    49     checkConcept<Graph, ListGraph>();
   115     checkConcept<Graph, ListGraph>();
    50     checkConcept<AlterableGraphComponent<>, ListGraph>();
   116     checkConcept<AlterableGraphComponent<>, ListGraph>();
    51     checkConcept<ExtendableGraphComponent<>, ListGraph>();
   117     checkConcept<ExtendableGraphComponent<>, ListGraph>();
    52     checkConcept<ClearableGraphComponent<>, ListGraph>();
   118     checkConcept<ClearableGraphComponent<>, ListGraph>();
    53     checkConcept<ErasableGraphComponent<>, ListGraph>();
   119     checkConcept<ErasableGraphComponent<>, ListGraph>();
    54     checkGraphIterators<ListGraph>();
       
    55   }
   120   }
    56   { // Checking SmartGraph
   121   { // Checking SmartGraph
    57     checkConcept<Graph, SmartGraph>();
   122     checkConcept<Graph, SmartGraph>();
    58     checkConcept<AlterableGraphComponent<>, SmartGraph>();
   123     checkConcept<AlterableGraphComponent<>, SmartGraph>();
    59     checkConcept<ExtendableGraphComponent<>, SmartGraph>();
   124     checkConcept<ExtendableGraphComponent<>, SmartGraph>();
    60     checkConcept<ClearableGraphComponent<>, SmartGraph>();
   125     checkConcept<ClearableGraphComponent<>, SmartGraph>();
    61     checkGraphIterators<SmartGraph>();
       
    62   }
   126   }
    63 //  { // Checking FullGraph
   127 //  { // Checking FullGraph
    64 //    checkConcept<Graph, FullGraph>();
   128 //    checkConcept<Graph, FullGraph>();
    65 //    checkGraphIterators<FullGraph>();
   129 //    checkGraphIterators<FullGraph>();
    66 //  }
   130 //  }
    69 //    checkGraphIterators<GridGraph>();
   133 //    checkGraphIterators<GridGraph>();
    70 //  }
   134 //  }
    71 }
   135 }
    72 
   136 
    73 template <typename Graph>
   137 template <typename Graph>
    74 void check_graph_validity() {
   138 void checkGraphValidity() {
    75   TEMPLATE_GRAPH_TYPEDEFS(Graph);
   139   TEMPLATE_GRAPH_TYPEDEFS(Graph);
    76   Graph g;
   140   Graph g;
    77 
   141 
    78   Node
   142   Node
    79     n1 = g.addNode(),
   143     n1 = g.addNode(),
    92   check(!g.valid(g.edgeFromId(-1)), "Wrong validity check");
   156   check(!g.valid(g.edgeFromId(-1)), "Wrong validity check");
    93   check(!g.valid(g.arcFromId(-1)), "Wrong validity check");
   157   check(!g.valid(g.arcFromId(-1)), "Wrong validity check");
    94 }
   158 }
    95 
   159 
    96 template <typename Graph>
   160 template <typename Graph>
    97 void check_graph_validity_erase() {
   161 void checkGraphValidityErase() {
    98   TEMPLATE_GRAPH_TYPEDEFS(Graph);
   162   TEMPLATE_GRAPH_TYPEDEFS(Graph);
    99   Graph g;
   163   Graph g;
   100 
   164 
   101   Node
   165   Node
   102     n1 = g.addNode(),
   166     n1 = g.addNode(),
   166 //     }
   230 //     }
   167 //     check(g.left(g(0, j)) == INVALID, "Wrong left");
   231 //     check(g.left(g(0, j)) == INVALID, "Wrong left");
   168 //   }
   232 //   }
   169 // }
   233 // }
   170 
   234 
   171 void check_graphs() {
   235 void checkGraphs() {
   172   { // Checking ListGraph
   236   { // Checking ListGraph
   173     checkGraph<ListGraph>();
   237     checkGraph<ListGraph>();
   174     checkGraphNodeMap<ListGraph>();
   238     checkGraphValidityErase<ListGraph>();
   175     checkGraphEdgeMap<ListGraph>();
       
   176 
       
   177     check_graph_validity_erase<ListGraph>();
       
   178   }
   239   }
   179   { // Checking SmartGraph
   240   { // Checking SmartGraph
   180     checkGraph<SmartGraph>();
   241     checkGraph<SmartGraph>();
   181     checkGraphNodeMap<SmartGraph>();
   242     checkGraphValidity<SmartGraph>();
   182     checkGraphEdgeMap<SmartGraph>();
       
   183 
       
   184     check_graph_validity<SmartGraph>();
       
   185   }
   243   }
   186 //   { // Checking FullGraph
   244 //   { // Checking FullGraph
   187 //     FullGraph g(5);
   245 //     FullGraph g(5);
   188 //     checkGraphNodeList(g, 5);
   246 //     checkGraphNodeList(g, 5);
   189 //     checkGraphEdgeList(g, 10);
   247 //     checkGraphEdgeList(g, 10);
   195 //     checkGridGraph(g, 5, 6);
   253 //     checkGridGraph(g, 5, 6);
   196 //   }
   254 //   }
   197 }
   255 }
   198 
   256 
   199 int main() {
   257 int main() {
   200   check_concepts();
   258   checkConcepts();
   201   check_graphs();
   259   checkGraphs();
   202   return 0;
   260   return 0;
   203 }
   261 }