alpar@906: /* -*- C++ -*-
ladanyi@1435:  * test/graph_test.h - Part of LEMON, a generic C++ optimization library
alpar@906:  *
alpar@1875:  * Copyright (C) 2006 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
alpar@1359:  * (Egervary Research Group on Combinatorial Optimization, EGRES).
alpar@906:  *
alpar@906:  * Permission to use, modify and distribute this software is granted
alpar@906:  * provided that this copyright notice appears in all copies. For
alpar@906:  * precise terms see the accompanying LICENSE file.
alpar@906:  *
alpar@906:  * This software is provided "AS IS" with no warranty of any kind,
alpar@906:  * express or implied, and with no claim as to its suitability for any
alpar@906:  * purpose.
alpar@906:  *
alpar@906:  */
alpar@921: #ifndef LEMON_TEST_GRAPH_TEST_H
alpar@921: #define LEMON_TEST_GRAPH_TEST_H
alpar@800: 
deba@1728: #include <lemon/graph_utils.h>
alpar@800: #include "test_tools.h"
alpar@800: 
alpar@800: //! \ingroup misc
alpar@800: //! \file
klao@946: //! \brief Some utility and test cases to test graph classes.
alpar@921: namespace lemon {
alpar@800: 
deba@891:   template<class Graph> void checkGraphNodeList(Graph &G, int nn)
klao@946:   {
klao@946:     typename Graph::NodeIt n(G);
klao@946:     for(int i=0;i<nn;i++) {
klao@946:       check(n!=INVALID,"Wrong Node list linking.");
klao@946:       ++n;
deba@891:     }
klao@946:     check(n==INVALID,"Wrong Node list linking.");
klao@946:   }
alpar@800: 
klao@946:   template<class Graph>
klao@946:   void checkGraphEdgeList(Graph &G, int nn)
klao@946:   {
klao@946:     typedef typename Graph::EdgeIt EdgeIt;
alpar@800: 
klao@946:     EdgeIt e(G);
klao@946:     for(int i=0;i<nn;i++) {
klao@946:       check(e!=INVALID,"Wrong Edge list linking.");
klao@946:       ++e;
deba@891:     }
klao@946:     check(e==INVALID,"Wrong Edge list linking.");
klao@946:   }
alpar@800: 
klao@946:   template<class Graph> 
klao@946:   void checkGraphOutEdgeList(Graph &G, typename Graph::Node n, int nn)
klao@946:   {
klao@946:     typename Graph::OutEdgeIt e(G,n);
klao@946:     for(int i=0;i<nn;i++) {
klao@946:       check(e!=INVALID,"Wrong OutEdge list linking.");
alpar@986:       check(n==G.source(e), "Wrong OutEdge list linking.");
klao@946:       ++e;
deba@891:     }
klao@946:     check(e==INVALID,"Wrong OutEdge list linking.");
klao@946:   }
alpar@800: 
klao@946:   template<class Graph> void 
klao@946:   checkGraphInEdgeList(Graph &G, typename Graph::Node n, int nn)
klao@946:   {
klao@946:     typename Graph::InEdgeIt e(G,n);
klao@946:     for(int i=0;i<nn;i++) {
klao@946:       check(e!=INVALID,"Wrong InEdge list linking.");
alpar@986:       check(n==G.target(e), "Wrong InEdge list linking.");
klao@946:       ++e;
deba@891:     }
klao@946:     check(e==INVALID,"Wrong InEdge list linking.");
klao@946:   }
klao@946: 
klao@946:   template <class Graph> 
klao@946:   void checkGraph() {
klao@946:     const int num = 5;
klao@946:     Graph G;
klao@946:     addPetersen(G, num);
klao@946:     bidirGraph(G);
klao@946:     checkBidirPetersen(G, num);
klao@946:   }
alpar@800: 
deba@1728:   template <class Graph> 
deba@1728:   void checkGraphIterators(const Graph& graph) {
deba@1728:     typedef typename Graph::Node Node;
deba@1728:     typedef typename Graph::NodeIt NodeIt;
deba@1728:     typedef typename Graph::Edge Edge;
deba@1728:     typedef typename Graph::EdgeIt EdgeIt;
deba@1728:     typedef typename Graph::InEdgeIt InEdgeIt;
deba@1728:     typedef typename Graph::OutEdgeIt OutEdgeIt;
deba@1728:     typedef ConEdgeIt<Graph> ConEdgeIt;
deba@1728:     
deba@1728:     for (NodeIt it(graph); it != INVALID; ++it) {}
deba@1728:   }
deba@1728: 
deba@891:   ///\file
alpar@986:   ///\todo Check target(), source() as well;
alpar@800: 
alpar@800:   
alpar@921: } //namespace lemon
alpar@800: 
alpar@800: 
alpar@800: #endif