| [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 | |
|---|
| 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 | |
|---|
| [1568] | 43 | checkConcept<UndirGraph, UndirFullGraph>(); |
|---|
| 44 | |
|---|
| [1030] | 45 | checkConcept<UndirGraph, UndirGraph>(); |
|---|
| [1053] | 46 | } |
|---|
| 47 | |
|---|
| [1054] | 48 | template <typename Graph> |
|---|
| [1053] | 49 | void check_item_counts(Graph &g, int n, int e) { |
|---|
| 50 | check(countNodes(g)==n, "Wrong node number."); |
|---|
| 51 | check(countEdges(g)==2*e, "Wrong edge number."); |
|---|
| 52 | } |
|---|
| 53 | |
|---|
| [1054] | 54 | template <typename Graph> |
|---|
| [1053] | 55 | void print_items(Graph &g) { |
|---|
| [1054] | 56 | |
|---|
| 57 | typedef typename Graph::NodeIt NodeIt; |
|---|
| 58 | typedef typename Graph::UndirEdgeIt UEdgeIt; |
|---|
| 59 | typedef typename Graph::EdgeIt EdgeIt; |
|---|
| 60 | |
|---|
| [1367] | 61 | std::cout << "Nodes" << std::endl; |
|---|
| [1053] | 62 | int i=0; |
|---|
| 63 | for(NodeIt it(g); it!=INVALID; ++it, ++i) { |
|---|
| [1367] | 64 | std::cout << " " << i << ": " << g.id(it) << std::endl; |
|---|
| [1053] | 65 | } |
|---|
| 66 | |
|---|
| [1367] | 67 | std::cout << "UndirEdge" << std::endl; |
|---|
| [1053] | 68 | i=0; |
|---|
| 69 | for(UEdgeIt it(g); it!=INVALID; ++it, ++i) { |
|---|
| [1367] | 70 | std::cout << " " << i << ": " << g.id(it) |
|---|
| [1053] | 71 | << " (" << g.id(g.source(it)) << ", " << g.id(g.target(it)) |
|---|
| [1367] | 72 | << ")" << std::endl; |
|---|
| [1053] | 73 | } |
|---|
| 74 | |
|---|
| [1367] | 75 | std::cout << "Edge" << std::endl; |
|---|
| [1053] | 76 | i=0; |
|---|
| 77 | for(EdgeIt it(g); it!=INVALID; ++it, ++i) { |
|---|
| [1367] | 78 | std::cout << " " << i << ": " << g.id(it) |
|---|
| [1053] | 79 | << " (" << g.id(g.source(it)) << ", " << g.id(g.target(it)) |
|---|
| [1367] | 80 | << ")" << std::endl; |
|---|
| [1053] | 81 | } |
|---|
| 82 | |
|---|
| 83 | } |
|---|
| 84 | |
|---|
| [1054] | 85 | template <typename Graph> |
|---|
| 86 | void check_graph() { |
|---|
| [1053] | 87 | |
|---|
| [1054] | 88 | typedef typename Graph::Node Node; |
|---|
| 89 | typedef typename Graph::UndirEdge UEdge; |
|---|
| 90 | typedef typename Graph::Edge Edge; |
|---|
| 91 | typedef typename Graph::NodeIt NodeIt; |
|---|
| 92 | typedef typename Graph::UndirEdgeIt UEdgeIt; |
|---|
| 93 | typedef typename Graph::EdgeIt EdgeIt; |
|---|
| [1053] | 94 | |
|---|
| 95 | Graph g; |
|---|
| 96 | |
|---|
| 97 | check_item_counts(g,0,0); |
|---|
| 98 | |
|---|
| 99 | Node |
|---|
| 100 | n1 = g.addNode(), |
|---|
| 101 | n2 = g.addNode(), |
|---|
| 102 | n3 = g.addNode(); |
|---|
| 103 | |
|---|
| 104 | UEdge |
|---|
| 105 | e1 = g.addEdge(n1, n2), |
|---|
| 106 | e2 = g.addEdge(n2, n3); |
|---|
| 107 | |
|---|
| 108 | // print_items(g); |
|---|
| 109 | |
|---|
| 110 | check_item_counts(g,3,2); |
|---|
| [1030] | 111 | |
|---|
| [1054] | 112 | |
|---|
| 113 | } |
|---|
| 114 | |
|---|
| 115 | int main() { |
|---|
| 116 | check_concepts(); |
|---|
| 117 | |
|---|
| 118 | check_graph<UndirListGraph>(); |
|---|
| 119 | check_graph<UndirSmartGraph>(); |
|---|
| 120 | |
|---|
| [1568] | 121 | { |
|---|
| 122 | UndirFullGraph g(5); |
|---|
| 123 | check_item_counts(g, 5, 10); |
|---|
| 124 | } |
|---|
| 125 | |
|---|
| [962] | 126 | return 0; |
|---|
| 127 | } |
|---|