1 | // -*- C++ -*- |
---|
2 | |
---|
3 | #include <lemon/undir_graph_extender.h> |
---|
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 | |
---|
9 | #include <lemon/graph_utils.h> |
---|
10 | |
---|
11 | #include "test_tools.h" |
---|
12 | |
---|
13 | |
---|
14 | using namespace lemon; |
---|
15 | using namespace lemon::concept; |
---|
16 | |
---|
17 | void check_concepts() { |
---|
18 | typedef UndirGraphExtender<ListGraphBase> UndirListGraphBase; |
---|
19 | |
---|
20 | typedef IterableUndirGraphExtender< |
---|
21 | AlterableUndirGraphExtender<UndirListGraphBase> > IterableUndirListGraph; |
---|
22 | |
---|
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>(); |
---|
36 | |
---|
37 | checkConcept<UndirGraph, UndirListGraph>(); |
---|
38 | checkConcept<ErasableUndirGraph, UndirListGraph>(); |
---|
39 | |
---|
40 | checkConcept<UndirGraph, UndirSmartGraph>(); |
---|
41 | checkConcept<ExtendableUndirGraph, UndirSmartGraph>(); |
---|
42 | |
---|
43 | checkConcept<UndirGraph, UndirGraph>(); |
---|
44 | } |
---|
45 | |
---|
46 | typedef UndirListGraph Graph; |
---|
47 | typedef Graph::Node Node; |
---|
48 | typedef Graph::UndirEdge UEdge; |
---|
49 | typedef Graph::Edge Edge; |
---|
50 | typedef Graph::NodeIt NodeIt; |
---|
51 | typedef Graph::UndirEdgeIt UEdgeIt; |
---|
52 | typedef Graph::EdgeIt EdgeIt; |
---|
53 | |
---|
54 | void check_item_counts(Graph &g, int n, int e) { |
---|
55 | check(countNodes(g)==n, "Wrong node number."); |
---|
56 | check(countEdges(g)==2*e, "Wrong edge number."); |
---|
57 | } |
---|
58 | |
---|
59 | void print_items(Graph &g) { |
---|
60 | cout << "Nodes" << endl; |
---|
61 | int i=0; |
---|
62 | for(NodeIt it(g); it!=INVALID; ++it, ++i) { |
---|
63 | cout << " " << i << ": " << g.id(it) << endl; |
---|
64 | } |
---|
65 | |
---|
66 | cout << "UndirEdge" << endl; |
---|
67 | i=0; |
---|
68 | for(UEdgeIt it(g); it!=INVALID; ++it, ++i) { |
---|
69 | cout << " " << i << ": " << g.id(it) |
---|
70 | << " (" << g.id(g.source(it)) << ", " << g.id(g.target(it)) |
---|
71 | << ")" << endl; |
---|
72 | } |
---|
73 | |
---|
74 | cout << "Edge" << endl; |
---|
75 | i=0; |
---|
76 | for(EdgeIt it(g); it!=INVALID; ++it, ++i) { |
---|
77 | cout << " " << i << ": " << g.id(it) |
---|
78 | << " (" << g.id(g.source(it)) << ", " << g.id(g.target(it)) |
---|
79 | << ")" << endl; |
---|
80 | } |
---|
81 | |
---|
82 | } |
---|
83 | |
---|
84 | int main() { |
---|
85 | check_concepts(); |
---|
86 | |
---|
87 | |
---|
88 | Graph g; |
---|
89 | |
---|
90 | check_item_counts(g,0,0); |
---|
91 | |
---|
92 | Node |
---|
93 | n1 = g.addNode(), |
---|
94 | n2 = g.addNode(), |
---|
95 | n3 = g.addNode(); |
---|
96 | |
---|
97 | UEdge |
---|
98 | e1 = g.addEdge(n1, n2), |
---|
99 | e2 = g.addEdge(n2, n3); |
---|
100 | |
---|
101 | // print_items(g); |
---|
102 | |
---|
103 | check_item_counts(g,3,2); |
---|
104 | |
---|
105 | return 0; |
---|
106 | } |
---|