src/test/graph_test.h
changeset 970 09f9abe22df2
parent 938 70e2886211d5
child 986 e997802b855c
equal deleted inserted replaced
8:c0f064ecdebd 9:b76a4740ca51
    19 
    19 
    20 #include "test_tools.h"
    20 #include "test_tools.h"
    21 
    21 
    22 //! \ingroup misc
    22 //! \ingroup misc
    23 //! \file
    23 //! \file
    24 //! \brief Some utility to  test graph classes.
    24 //! \brief Some utility and test cases to test graph classes.
    25 namespace lemon {
    25 namespace lemon {
    26 
    26 
    27   template<class Graph> void checkGraphNodeList(Graph &G, int nn)
    27   template<class Graph> void checkGraphNodeList(Graph &G, int nn)
    28     {
    28   {
    29       typename Graph::NodeIt n(G);
    29     typename Graph::NodeIt n(G);
    30       for(int i=0;i<nn;i++) {
    30     for(int i=0;i<nn;i++) {
    31 	check(n!=INVALID,"Wrong Node list linking.");
    31       check(n!=INVALID,"Wrong Node list linking.");
    32 	++n;
    32       ++n;
    33       }
       
    34       check(n==INVALID,"Wrong Node list linking.");
       
    35     }
    33     }
       
    34     check(n==INVALID,"Wrong Node list linking.");
       
    35   }
    36 
    36 
    37   template<class Graph> void checkGraphEdgeList(Graph &G, int nn)
    37   template<class Graph>
    38     {
    38   void checkGraphEdgeList(Graph &G, int nn)
    39       typedef typename Graph::EdgeIt EdgeIt;
    39   {
       
    40     typedef typename Graph::EdgeIt EdgeIt;
    40 
    41 
    41       EdgeIt e(G);
    42     EdgeIt e(G);
    42       for(int i=0;i<nn;i++) {
    43     for(int i=0;i<nn;i++) {
    43 	check(e!=INVALID,"Wrong Edge list linking.");
    44       check(e!=INVALID,"Wrong Edge list linking.");
    44 	++e;
    45       ++e;
    45       }
       
    46       check(e==INVALID,"Wrong Edge list linking.");
       
    47     }
    46     }
       
    47     check(e==INVALID,"Wrong Edge list linking.");
       
    48   }
    48 
    49 
    49   template<class Graph> void checkGraphOutEdgeList(Graph &G,
    50   template<class Graph> 
    50 						   typename Graph::Node n,
    51   void checkGraphOutEdgeList(Graph &G, typename Graph::Node n, int nn)
    51 						   int nn)
    52   {
    52     {
    53     typename Graph::OutEdgeIt e(G,n);
    53       typename Graph::OutEdgeIt e(G,n);
    54     for(int i=0;i<nn;i++) {
    54       for(int i=0;i<nn;i++) {
    55       check(e!=INVALID,"Wrong OutEdge list linking.");
    55 	check(e!=INVALID,"Wrong OutEdge list linking.");
    56       check(n==G.tail(e), "Wrong OutEdge list linking.");
    56 	check(n==G.tail(e), "Wrong OutEdge list linking.");
    57       ++e;
    57 	++e;
       
    58       }
       
    59       check(e==INVALID,"Wrong OutEdge list linking.");
       
    60     }
    58     }
       
    59     check(e==INVALID,"Wrong OutEdge list linking.");
       
    60   }
    61 
    61 
    62   template<class Graph> void checkGraphInEdgeList(Graph &G,
    62   template<class Graph> void 
    63 						  typename Graph::Node n,
    63   checkGraphInEdgeList(Graph &G, typename Graph::Node n, int nn)
    64 						  int nn)
    64   {
    65     {
    65     typename Graph::InEdgeIt e(G,n);
    66       typename Graph::InEdgeIt e(G,n);
    66     for(int i=0;i<nn;i++) {
    67       for(int i=0;i<nn;i++) {
    67       check(e!=INVALID,"Wrong InEdge list linking.");
    68 	check(e!=INVALID,"Wrong InEdge list linking.");
    68       check(n==G.head(e), "Wrong InEdge list linking.");
    69 	check(n==G.head(e), "Wrong InEdge list linking.");
    69       ++e;
    70 	++e;
       
    71       }
       
    72       check(e==INVALID,"Wrong InEdge list linking.");
       
    73     }
    70     }
       
    71     check(e==INVALID,"Wrong InEdge list linking.");
       
    72   }
       
    73 
       
    74   template <class Graph> 
       
    75   void checkGraph() {
       
    76     const int num = 5;
       
    77     Graph G;
       
    78     addPetersen(G, num);
       
    79     bidirGraph(G);
       
    80     checkBidirPetersen(G, num);
       
    81   }
    74 
    82 
    75   ///\file
    83   ///\file
    76   ///\todo Check head(), tail() as well;
    84   ///\todo Check head(), tail() as well;
    77 
    85 
    78   
    86