COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/test/undir_graph_test.cc @ 1360:4338e4280f67

Last change on this file since 1360:4338e4280f67 was 1307:d4acebef7276, checked in by Balazs Dezso, 20 years ago

Stuffs moved into bits

File size: 2.7 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
[1053]59  cout << "Nodes" << endl;
60  int i=0;
61  for(NodeIt it(g); it!=INVALID; ++it, ++i) {
62    cout << "  " << i << ": " << g.id(it) << endl;
63  }
64
65  cout << "UndirEdge" << endl;
66  i=0;
67  for(UEdgeIt it(g); it!=INVALID; ++it, ++i) {
68    cout << "  " << i << ": " << g.id(it)
69         << " (" << g.id(g.source(it)) << ", " << g.id(g.target(it))
70         << ")" << endl;
71  }
72
73  cout << "Edge" << endl;
74  i=0;
75  for(EdgeIt it(g); it!=INVALID; ++it, ++i) {
76    cout << "  " << i << ": " << g.id(it)
77         << " (" << g.id(g.source(it)) << ", " << g.id(g.target(it))
78         << ")" << endl;
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.