COIN-OR::LEMON - Graph Library

source: lemon-0.x/test/undir_graph_test.cc @ 1435:8e85e6bbefdf

Last change on this file since 1435:8e85e6bbefdf was 1435:8e85e6bbefdf, checked in by Akos Ladanyi, 19 years ago

trunk/src/* move to trunk/

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