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