test/undir_graph_test.cc
author ladanyi
Thu, 11 Aug 2005 15:24:24 +0000
changeset 1626 e251336be488
parent 1435 8e85e6bbefdf
child 1680 4f8b9cee576b
permissions -rw-r--r--
Added copyright header and description.
klao@962
     1
// -*- C++ -*-
klao@962
     2
deba@1307
     3
#include <lemon/bits/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
deba@1568
    43
  checkConcept<UndirGraph, UndirFullGraph>();
deba@1568
    44
klao@1030
    45
  checkConcept<UndirGraph, UndirGraph>();
klao@1053
    46
}
klao@1053
    47
klao@1054
    48
template <typename Graph>
klao@1053
    49
void check_item_counts(Graph &g, int n, int e) {
klao@1053
    50
  check(countNodes(g)==n, "Wrong node number.");
klao@1053
    51
  check(countEdges(g)==2*e, "Wrong edge number.");
klao@1053
    52
}
klao@1053
    53
klao@1054
    54
template <typename Graph>
klao@1053
    55
void print_items(Graph &g) {
klao@1054
    56
klao@1054
    57
  typedef typename Graph::NodeIt NodeIt;
klao@1054
    58
  typedef typename Graph::UndirEdgeIt UEdgeIt;
klao@1054
    59
  typedef typename Graph::EdgeIt EdgeIt;
klao@1054
    60
alpar@1367
    61
  std::cout << "Nodes" << std::endl;
klao@1053
    62
  int i=0;
klao@1053
    63
  for(NodeIt it(g); it!=INVALID; ++it, ++i) {
alpar@1367
    64
    std::cout << "  " << i << ": " << g.id(it) << std::endl;
klao@1053
    65
  }
klao@1053
    66
alpar@1367
    67
  std::cout << "UndirEdge" << std::endl;
klao@1053
    68
  i=0;
klao@1053
    69
  for(UEdgeIt it(g); it!=INVALID; ++it, ++i) {
alpar@1367
    70
    std::cout << "  " << i << ": " << g.id(it) 
klao@1053
    71
	 << " (" << g.id(g.source(it)) << ", " << g.id(g.target(it)) 
alpar@1367
    72
	 << ")" << std::endl;
klao@1053
    73
  }
klao@1053
    74
alpar@1367
    75
  std::cout << "Edge" << std::endl;
klao@1053
    76
  i=0;
klao@1053
    77
  for(EdgeIt it(g); it!=INVALID; ++it, ++i) {
alpar@1367
    78
    std::cout << "  " << i << ": " << g.id(it)
klao@1053
    79
	 << " (" << g.id(g.source(it)) << ", " << g.id(g.target(it)) 
alpar@1367
    80
	 << ")" << std::endl;
klao@1053
    81
  }
klao@1053
    82
klao@1053
    83
}
klao@1053
    84
klao@1054
    85
template <typename Graph>
klao@1054
    86
void check_graph() {
klao@1053
    87
klao@1054
    88
  typedef typename Graph::Node Node;
klao@1054
    89
  typedef typename Graph::UndirEdge UEdge;
klao@1054
    90
  typedef typename Graph::Edge Edge;
klao@1054
    91
  typedef typename Graph::NodeIt NodeIt;
klao@1054
    92
  typedef typename Graph::UndirEdgeIt UEdgeIt;
klao@1054
    93
  typedef typename Graph::EdgeIt EdgeIt;
klao@1053
    94
klao@1053
    95
  Graph g;
klao@1053
    96
klao@1053
    97
  check_item_counts(g,0,0);
klao@1053
    98
klao@1053
    99
  Node
klao@1053
   100
    n1 = g.addNode(),
klao@1053
   101
    n2 = g.addNode(),
klao@1053
   102
    n3 = g.addNode();
klao@1053
   103
klao@1053
   104
  UEdge
klao@1053
   105
    e1 = g.addEdge(n1, n2),
klao@1053
   106
    e2 = g.addEdge(n2, n3);
klao@1053
   107
klao@1053
   108
  // print_items(g);
klao@1053
   109
klao@1053
   110
  check_item_counts(g,3,2);
klao@1030
   111
klao@1054
   112
klao@1054
   113
}
klao@1054
   114
klao@1054
   115
int main() {
klao@1054
   116
  check_concepts();
klao@1054
   117
klao@1054
   118
  check_graph<UndirListGraph>();
klao@1054
   119
  check_graph<UndirSmartGraph>();
klao@1054
   120
deba@1568
   121
  {
deba@1568
   122
    UndirFullGraph g(5);
deba@1568
   123
    check_item_counts(g, 5, 10);
deba@1568
   124
  }
deba@1568
   125
klao@962
   126
  return 0;
klao@962
   127
}