test/graph_test.h
author deba
Wed, 01 Mar 2006 10:17:25 +0000
changeset 1990 15fb7a4ea6be
parent 1875 98698b69a902
child 2391 14a343be7a5a
permissions -rw-r--r--
Some classes assumed that the GraphMaps should be inherited
from an ObserverBase. These classes parents replaced with
DefaultMap which cause that the graph maps should not be
inherited from the ObserverBase.
alpar@906
     1
/* -*- C++ -*-
alpar@906
     2
 *
alpar@1956
     3
 * This file is a part of LEMON, a generic C++ optimization library
alpar@1956
     4
 *
alpar@1956
     5
 * Copyright (C) 2003-2006
alpar@1956
     6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
alpar@1359
     7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
alpar@906
     8
 *
alpar@906
     9
 * Permission to use, modify and distribute this software is granted
alpar@906
    10
 * provided that this copyright notice appears in all copies. For
alpar@906
    11
 * precise terms see the accompanying LICENSE file.
alpar@906
    12
 *
alpar@906
    13
 * This software is provided "AS IS" with no warranty of any kind,
alpar@906
    14
 * express or implied, and with no claim as to its suitability for any
alpar@906
    15
 * purpose.
alpar@906
    16
 *
alpar@906
    17
 */
alpar@1956
    18
alpar@921
    19
#ifndef LEMON_TEST_GRAPH_TEST_H
alpar@921
    20
#define LEMON_TEST_GRAPH_TEST_H
alpar@800
    21
deba@1728
    22
#include <lemon/graph_utils.h>
alpar@800
    23
#include "test_tools.h"
alpar@800
    24
alpar@800
    25
//! \ingroup misc
alpar@800
    26
//! \file
klao@946
    27
//! \brief Some utility and test cases to test graph classes.
alpar@921
    28
namespace lemon {
alpar@800
    29
deba@891
    30
  template<class Graph> void checkGraphNodeList(Graph &G, int nn)
klao@946
    31
  {
klao@946
    32
    typename Graph::NodeIt n(G);
klao@946
    33
    for(int i=0;i<nn;i++) {
klao@946
    34
      check(n!=INVALID,"Wrong Node list linking.");
klao@946
    35
      ++n;
deba@891
    36
    }
klao@946
    37
    check(n==INVALID,"Wrong Node list linking.");
klao@946
    38
  }
alpar@800
    39
klao@946
    40
  template<class Graph>
klao@946
    41
  void checkGraphEdgeList(Graph &G, int nn)
klao@946
    42
  {
klao@946
    43
    typedef typename Graph::EdgeIt EdgeIt;
alpar@800
    44
klao@946
    45
    EdgeIt e(G);
klao@946
    46
    for(int i=0;i<nn;i++) {
klao@946
    47
      check(e!=INVALID,"Wrong Edge list linking.");
klao@946
    48
      ++e;
deba@891
    49
    }
klao@946
    50
    check(e==INVALID,"Wrong Edge list linking.");
klao@946
    51
  }
alpar@800
    52
klao@946
    53
  template<class Graph> 
klao@946
    54
  void checkGraphOutEdgeList(Graph &G, typename Graph::Node n, int nn)
klao@946
    55
  {
klao@946
    56
    typename Graph::OutEdgeIt e(G,n);
klao@946
    57
    for(int i=0;i<nn;i++) {
klao@946
    58
      check(e!=INVALID,"Wrong OutEdge list linking.");
alpar@986
    59
      check(n==G.source(e), "Wrong OutEdge list linking.");
klao@946
    60
      ++e;
deba@891
    61
    }
klao@946
    62
    check(e==INVALID,"Wrong OutEdge list linking.");
klao@946
    63
  }
alpar@800
    64
klao@946
    65
  template<class Graph> void 
klao@946
    66
  checkGraphInEdgeList(Graph &G, typename Graph::Node n, int nn)
klao@946
    67
  {
klao@946
    68
    typename Graph::InEdgeIt e(G,n);
klao@946
    69
    for(int i=0;i<nn;i++) {
klao@946
    70
      check(e!=INVALID,"Wrong InEdge list linking.");
alpar@986
    71
      check(n==G.target(e), "Wrong InEdge list linking.");
klao@946
    72
      ++e;
deba@891
    73
    }
klao@946
    74
    check(e==INVALID,"Wrong InEdge list linking.");
klao@946
    75
  }
klao@946
    76
klao@946
    77
  template <class Graph> 
klao@946
    78
  void checkGraph() {
klao@946
    79
    const int num = 5;
klao@946
    80
    Graph G;
klao@946
    81
    addPetersen(G, num);
klao@946
    82
    bidirGraph(G);
klao@946
    83
    checkBidirPetersen(G, num);
klao@946
    84
  }
alpar@800
    85
deba@1728
    86
  template <class Graph> 
deba@1728
    87
  void checkGraphIterators(const Graph& graph) {
deba@1728
    88
    typedef typename Graph::Node Node;
deba@1728
    89
    typedef typename Graph::NodeIt NodeIt;
deba@1728
    90
    typedef typename Graph::Edge Edge;
deba@1728
    91
    typedef typename Graph::EdgeIt EdgeIt;
deba@1728
    92
    typedef typename Graph::InEdgeIt InEdgeIt;
deba@1728
    93
    typedef typename Graph::OutEdgeIt OutEdgeIt;
deba@1728
    94
    typedef ConEdgeIt<Graph> ConEdgeIt;
deba@1728
    95
    
deba@1728
    96
    for (NodeIt it(graph); it != INVALID; ++it) {}
deba@1728
    97
  }
deba@1728
    98
deba@891
    99
  ///\file
alpar@986
   100
  ///\todo Check target(), source() as well;
alpar@800
   101
alpar@800
   102
  
alpar@921
   103
} //namespace lemon
alpar@800
   104
alpar@800
   105
alpar@800
   106
#endif