[946] | 1 | /* -*- C++ -*- |
---|
| 2 | * src/test/graph_test.cc - Part of LEMON, a generic C++ optimization library |
---|
| 3 | * |
---|
[1164] | 4 | * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
---|
[1359] | 5 | * (Egervary Research Group on Combinatorial Optimization, EGRES). |
---|
[946] | 6 | * |
---|
| 7 | * Permission to use, modify and distribute this software is granted |
---|
| 8 | * provided that this copyright notice appears in all copies. For |
---|
| 9 | * precise terms see the accompanying LICENSE file. |
---|
| 10 | * |
---|
| 11 | * This software is provided "AS IS" with no warranty of any kind, |
---|
| 12 | * express or implied, and with no claim as to its suitability for any |
---|
| 13 | * purpose. |
---|
| 14 | * |
---|
| 15 | */ |
---|
| 16 | |
---|
| 17 | #include<iostream> |
---|
| 18 | #include<lemon/smart_graph.h> |
---|
[959] | 19 | #include<lemon/concept/graph.h> |
---|
| 20 | #include<lemon/concept/maps.h> |
---|
[946] | 21 | #include<lemon/list_graph_base.h> |
---|
| 22 | #include<lemon/full_graph.h> |
---|
| 23 | |
---|
| 24 | #include"test_tools.h" |
---|
| 25 | #include"graph_test.h" |
---|
| 26 | |
---|
| 27 | /** |
---|
| 28 | \file |
---|
| 29 | This test makes consistency checks of list graph structures. |
---|
| 30 | |
---|
[986] | 31 | G.addNode(), G.addEdge(), G.source(), G.target() |
---|
[946] | 32 | |
---|
| 33 | \todo Checks for empty graphs and isolated points. |
---|
| 34 | conversion. |
---|
| 35 | */ |
---|
| 36 | |
---|
| 37 | using namespace lemon; |
---|
| 38 | |
---|
| 39 | template<class Graph> void bidirPetersen(Graph &G) |
---|
| 40 | { |
---|
| 41 | typedef typename Graph::Edge Edge; |
---|
| 42 | typedef typename Graph::EdgeIt EdgeIt; |
---|
| 43 | |
---|
| 44 | checkGraphEdgeList(G,15); |
---|
| 45 | |
---|
| 46 | std::vector<Edge> ee; |
---|
| 47 | |
---|
| 48 | for(EdgeIt e(G);e!=INVALID;++e) ee.push_back(e); |
---|
| 49 | |
---|
| 50 | for(typename std::vector<Edge>::iterator p=ee.begin();p!=ee.end();p++) |
---|
[986] | 51 | G.addEdge(G.target(*p),G.source(*p)); |
---|
[946] | 52 | } |
---|
| 53 | |
---|
| 54 | template<class Graph> void checkPetersen(Graph &G) |
---|
| 55 | { |
---|
| 56 | typedef typename Graph::Node Node; |
---|
| 57 | |
---|
| 58 | typedef typename Graph::EdgeIt EdgeIt; |
---|
| 59 | typedef typename Graph::NodeIt NodeIt; |
---|
| 60 | |
---|
| 61 | checkGraphNodeList(G,10); |
---|
| 62 | checkGraphEdgeList(G,30); |
---|
| 63 | |
---|
| 64 | for(NodeIt n(G);n!=INVALID;++n) { |
---|
| 65 | checkGraphInEdgeList(G,n,3); |
---|
| 66 | checkGraphOutEdgeList(G,n,3); |
---|
| 67 | } |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | //Compile Graph |
---|
[959] | 71 | template void lemon::concept::checkCompileStaticGraph<concept::StaticGraph> |
---|
| 72 | (concept::StaticGraph &); |
---|
[946] | 73 | |
---|
| 74 | template |
---|
[959] | 75 | void lemon::concept::checkCompileExtendableGraph<concept::ExtendableGraph> |
---|
| 76 | (concept::ExtendableGraph &); |
---|
[946] | 77 | |
---|
| 78 | template |
---|
[959] | 79 | void lemon::concept::checkCompileErasableGraph<concept::ErasableGraph> |
---|
| 80 | (concept::ErasableGraph &); |
---|
[946] | 81 | |
---|
| 82 | //Compile SmartGraph |
---|
| 83 | template |
---|
[959] | 84 | void lemon::concept::checkCompileExtendableGraph<SmartGraph>(SmartGraph &); |
---|
[946] | 85 | template |
---|
[959] | 86 | void lemon::concept::checkCompileGraphFindEdge<SmartGraph>(SmartGraph &); |
---|
[946] | 87 | |
---|
| 88 | //Compile SymSmartGraph |
---|
| 89 | //template void hugo::checkCompileGraph<SymSmartGraph>(SymSmartGraph &); |
---|
| 90 | //template void hugo::checkCompileGraphFindEdge<SymSmartGraph>(SymSmartGraph &); |
---|
| 91 | |
---|
| 92 | //Compile ListGraph |
---|
| 93 | template |
---|
[959] | 94 | void lemon::concept::checkCompileExtendableGraph<ListGraph>(ListGraph &); |
---|
[946] | 95 | template |
---|
[959] | 96 | void lemon::concept::checkCompileErasableGraph<ListGraph>(ListGraph &); |
---|
[946] | 97 | template |
---|
[959] | 98 | void lemon::concept::checkCompileGraphFindEdge<ListGraph>(ListGraph &); |
---|
[946] | 99 | |
---|
| 100 | |
---|
| 101 | //Compile SymListGraph |
---|
| 102 | //template void hugo::checkCompileGraph<SymListGraph>(SymListGraph &); |
---|
| 103 | //template void hugo::checkCompileErasableGraph<SymListGraph>(SymListGraph &); |
---|
| 104 | //template void hugo::checkCompileGraphFindEdge<SymListGraph>(SymListGraph &); |
---|
| 105 | |
---|
| 106 | //Compile FullGraph |
---|
[959] | 107 | template void lemon::concept::checkCompileStaticGraph<FullGraph>(FullGraph &); |
---|
[946] | 108 | template |
---|
[959] | 109 | void lemon::concept::checkCompileGraphFindEdge<FullGraph>(FullGraph &); |
---|
[946] | 110 | |
---|
| 111 | |
---|
| 112 | int main() |
---|
| 113 | { |
---|
| 114 | { |
---|
| 115 | SmartGraph G; |
---|
| 116 | addPetersen(G); |
---|
| 117 | bidirPetersen(G); |
---|
| 118 | checkPetersen(G); |
---|
| 119 | } |
---|
| 120 | { |
---|
| 121 | ListGraph G; |
---|
| 122 | addPetersen(G); |
---|
| 123 | bidirPetersen(G); |
---|
| 124 | checkPetersen(G); |
---|
| 125 | } |
---|
| 126 | { |
---|
| 127 | // SymSmartGraph G; |
---|
| 128 | // addPetersen(G); |
---|
| 129 | // checkPetersen(G); |
---|
| 130 | } |
---|
| 131 | { |
---|
| 132 | // SymListGraph G; |
---|
| 133 | // addPetersen(G); |
---|
| 134 | // checkPetersen(G); |
---|
| 135 | } |
---|
| 136 | |
---|
| 137 | ///\file |
---|
| 138 | ///\todo map tests. |
---|
| 139 | ///\todo copy constr tests. |
---|
| 140 | |
---|
| 141 | |
---|
| 142 | // Some map tests. |
---|
| 143 | // FIXME: These shouldn't be here. |
---|
[959] | 144 | using namespace concept; |
---|
[946] | 145 | function_requires< ReadMapConcept< ReadMap<int,int> > >(); |
---|
| 146 | function_requires< WriteMapConcept< WriteMap<int,int> > >(); |
---|
| 147 | function_requires< ReadWriteMapConcept< ReadWriteMap<int,int> > >(); |
---|
| 148 | function_requires< ReferenceMapConcept< ReferenceMap<int,int> > >(); |
---|
| 149 | |
---|
| 150 | |
---|
| 151 | std::cout << __FILE__ ": All tests passed.\n"; |
---|
| 152 | |
---|
| 153 | return 0; |
---|
| 154 | } |
---|