[962] | 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 | |
---|
[1053] | 9 | #include <lemon/graph_utils.h> |
---|
| 10 | |
---|
[962] | 11 | #include "test_tools.h" |
---|
| 12 | |
---|
| 13 | |
---|
| 14 | using namespace lemon; |
---|
| 15 | using namespace lemon::concept; |
---|
| 16 | |
---|
[1053] | 17 | void 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] | 46 | template <typename Graph> |
---|
[1053] | 47 | void 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] | 52 | template <typename Graph> |
---|
[1053] | 53 | void 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] | 83 | template <typename Graph> |
---|
| 84 | void 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 | |
---|
| 113 | int main() { |
---|
| 114 | check_concepts(); |
---|
| 115 | |
---|
| 116 | check_graph<UndirListGraph>(); |
---|
| 117 | check_graph<UndirSmartGraph>(); |
---|
| 118 | |
---|
[962] | 119 | return 0; |
---|
| 120 | } |
---|