src/test/undir_graph_test.cc
author deba
Mon, 07 Feb 2005 11:28:37 +0000
changeset 1136 8d066154b66a
parent 1053 90f8696360b2
child 1307 d4acebef7276
permissions -rw-r--r--
Graph documentation
klao@962
     1
// -*- C++ -*-
klao@962
     2
klao@962
     3
#include <lemon/undir_graph_extender.h>
klao@962
     4
#include <lemon/concept/undir_graph.h>
klao@962
     5
#include <lemon/list_graph.h>
klao@962
     6
#include <lemon/smart_graph.h>
klao@962
     7
#include <lemon/full_graph.h>
klao@962
     8
klao@1053
     9
#include <lemon/graph_utils.h>
klao@1053
    10
klao@962
    11
#include "test_tools.h"
klao@962
    12
klao@962
    13
klao@962
    14
using namespace lemon;
klao@962
    15
using namespace lemon::concept;
klao@962
    16
klao@1053
    17
void check_concepts() {
klao@962
    18
  typedef UndirGraphExtender<ListGraphBase> UndirListGraphBase;
klao@962
    19
klao@962
    20
  typedef IterableUndirGraphExtender<
klao@962
    21
    AlterableUndirGraphExtender<UndirListGraphBase> > IterableUndirListGraph;
klao@962
    22
klao@1022
    23
  typedef MappableUndirGraphExtender<IterableUndirListGraph>
klao@1022
    24
    MappableUndirListGraph;
klao@1022
    25
klao@1022
    26
  typedef ErasableUndirGraphExtender<
klao@1022
    27
    ClearableUndirGraphExtender<
klao@1022
    28
    ExtendableUndirGraphExtender<MappableUndirListGraph> > > Graph;
klao@1022
    29
klao@1022
    30
  checkConcept<BaseIterableUndirGraphConcept, Graph>();
klao@1022
    31
  checkConcept<IterableUndirGraphConcept, Graph>();
klao@1022
    32
  checkConcept<MappableUndirGraphConcept, Graph>();
klao@1022
    33
klao@1022
    34
  checkConcept<UndirGraph, Graph>();
klao@1022
    35
  checkConcept<ErasableUndirGraph, Graph>();
klao@962
    36
klao@1034
    37
  checkConcept<UndirGraph, UndirListGraph>();
klao@1034
    38
  checkConcept<ErasableUndirGraph, UndirListGraph>();
klao@1034
    39
klao@1034
    40
  checkConcept<UndirGraph, UndirSmartGraph>();
klao@1034
    41
  checkConcept<ExtendableUndirGraph, UndirSmartGraph>();
klao@1034
    42
klao@1030
    43
  checkConcept<UndirGraph, UndirGraph>();
klao@1053
    44
}
klao@1053
    45
klao@1054
    46
template <typename Graph>
klao@1053
    47
void check_item_counts(Graph &g, int n, int e) {
klao@1053
    48
  check(countNodes(g)==n, "Wrong node number.");
klao@1053
    49
  check(countEdges(g)==2*e, "Wrong edge number.");
klao@1053
    50
}
klao@1053
    51
klao@1054
    52
template <typename Graph>
klao@1053
    53
void print_items(Graph &g) {
klao@1054
    54
klao@1054
    55
  typedef typename Graph::NodeIt NodeIt;
klao@1054
    56
  typedef typename Graph::UndirEdgeIt UEdgeIt;
klao@1054
    57
  typedef typename Graph::EdgeIt EdgeIt;
klao@1054
    58
klao@1053
    59
  cout << "Nodes" << endl;
klao@1053
    60
  int i=0;
klao@1053
    61
  for(NodeIt it(g); it!=INVALID; ++it, ++i) {
klao@1053
    62
    cout << "  " << i << ": " << g.id(it) << endl;
klao@1053
    63
  }
klao@1053
    64
klao@1053
    65
  cout << "UndirEdge" << endl;
klao@1053
    66
  i=0;
klao@1053
    67
  for(UEdgeIt it(g); it!=INVALID; ++it, ++i) {
klao@1053
    68
    cout << "  " << i << ": " << g.id(it) 
klao@1053
    69
	 << " (" << g.id(g.source(it)) << ", " << g.id(g.target(it)) 
klao@1053
    70
	 << ")" << endl;
klao@1053
    71
  }
klao@1053
    72
klao@1053
    73
  cout << "Edge" << endl;
klao@1053
    74
  i=0;
klao@1053
    75
  for(EdgeIt it(g); it!=INVALID; ++it, ++i) {
klao@1053
    76
    cout << "  " << i << ": " << g.id(it)
klao@1053
    77
	 << " (" << g.id(g.source(it)) << ", " << g.id(g.target(it)) 
klao@1053
    78
	 << ")" << endl;
klao@1053
    79
  }
klao@1053
    80
klao@1053
    81
}
klao@1053
    82
klao@1054
    83
template <typename Graph>
klao@1054
    84
void check_graph() {
klao@1053
    85
klao@1054
    86
  typedef typename Graph::Node Node;
klao@1054
    87
  typedef typename Graph::UndirEdge UEdge;
klao@1054
    88
  typedef typename Graph::Edge Edge;
klao@1054
    89
  typedef typename Graph::NodeIt NodeIt;
klao@1054
    90
  typedef typename Graph::UndirEdgeIt UEdgeIt;
klao@1054
    91
  typedef typename Graph::EdgeIt EdgeIt;
klao@1053
    92
klao@1053
    93
  Graph g;
klao@1053
    94
klao@1053
    95
  check_item_counts(g,0,0);
klao@1053
    96
klao@1053
    97
  Node
klao@1053
    98
    n1 = g.addNode(),
klao@1053
    99
    n2 = g.addNode(),
klao@1053
   100
    n3 = g.addNode();
klao@1053
   101
klao@1053
   102
  UEdge
klao@1053
   103
    e1 = g.addEdge(n1, n2),
klao@1053
   104
    e2 = g.addEdge(n2, n3);
klao@1053
   105
klao@1053
   106
  // print_items(g);
klao@1053
   107
klao@1053
   108
  check_item_counts(g,3,2);
klao@1030
   109
klao@1054
   110
klao@1054
   111
}
klao@1054
   112
klao@1054
   113
int main() {
klao@1054
   114
  check_concepts();
klao@1054
   115
klao@1054
   116
  check_graph<UndirListGraph>();
klao@1054
   117
  check_graph<UndirSmartGraph>();
klao@1054
   118
klao@962
   119
  return 0;
klao@962
   120
}