Changeset 891:74589d20dbc3 in lemon-0.x for src/test
- Timestamp:
- 09/21/04 00:57:48 (20 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1199
- Location:
- src/test
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/test/graph_test.h
r856 r891 1 // -*- c++ -*- 1 2 #ifndef HUGO_TEST_GRAPH_TEST_H 2 3 #define HUGO_TEST_GRAPH_TEST_H … … 10 11 namespace hugo { 11 12 12 13 template<class Graph> void checkCompileStaticGraph(Graph &G) 14 { 15 typedef typename Graph::Node Node; 16 typedef typename Graph::NodeIt NodeIt; 17 typedef typename Graph::Edge Edge; 18 typedef typename Graph::EdgeIt EdgeIt; 19 typedef typename Graph::InEdgeIt InEdgeIt; 20 typedef typename Graph::OutEdgeIt OutEdgeIt; 13 struct DummyType { 14 int value; 15 DummyType() {} 16 DummyType(int p) : value(p) {} 17 DummyType& operator=(int p) { value = p; return *this;} 18 }; 19 20 21 template<class Graph> void checkCompileStaticGraph(Graph &G) 22 { 23 typedef typename Graph::Node Node; 24 typedef typename Graph::NodeIt NodeIt; 25 typedef typename Graph::Edge Edge; 26 typedef typename Graph::EdgeIt EdgeIt; 27 typedef typename Graph::InEdgeIt InEdgeIt; 28 typedef typename Graph::OutEdgeIt OutEdgeIt; 21 29 22 { 23 Node i; Node j(i); Node k(INVALID); 24 i=j; 25 bool b; b=true; 26 b=(i==INVALID); b=(i!=INVALID); 27 b=(i==j); b=(i!=j); b=(i<j); 28 } 29 { 30 NodeIt i; NodeIt j(i); NodeIt k(INVALID); NodeIt l(G); 31 i=j; 32 j=G.first(i); 33 j=++i; 34 bool b; b=true; 35 b=(i==INVALID); b=(i!=INVALID); 36 Node n(i); 37 n=i; 38 b=(i==j); b=(i!=j); b=(i<j); 39 //Node ->NodeIt conversion 40 NodeIt ni(G,n); 41 } 42 { 43 Edge i; Edge j(i); Edge k(INVALID); 44 i=j; 45 bool b; b=true; 46 b=(i==INVALID); b=(i!=INVALID); 47 b=(i==j); b=(i!=j); b=(i<j); 48 } 49 { 50 EdgeIt i; EdgeIt j(i); EdgeIt k(INVALID); EdgeIt l(G); 51 i=j; 52 j=G.first(i); 53 j=++i; 54 bool b; b=true; 55 b=(i==INVALID); b=(i!=INVALID); 56 Edge e(i); 57 e=i; 58 b=(i==j); b=(i!=j); b=(i<j); 59 //Edge ->EdgeIt conversion 60 EdgeIt ei(G,e); 61 } 62 { 63 Node n; 64 InEdgeIt i; InEdgeIt j(i); InEdgeIt k(INVALID); InEdgeIt l(G,n); 65 i=j; 66 j=G.first(i,n); 67 j=++i; 68 bool b; b=true; 69 b=(i==INVALID); b=(i!=INVALID); 70 Edge e(i); 71 e=i; 72 b=(i==j); b=(i!=j); b=(i<j); 73 //Edge ->InEdgeIt conversion 74 InEdgeIt ei(G,e); 75 } 76 { 77 Node n; 78 OutEdgeIt i; OutEdgeIt j(i); OutEdgeIt k(INVALID); OutEdgeIt l(G,n); 79 i=j; 80 j=G.first(i,n); 81 j=++i; 82 bool b; b=true; 83 b=(i==INVALID); b=(i!=INVALID); 84 Edge e(i); 85 e=i; 86 b=(i==j); b=(i!=j); b=(i<j); 87 //Edge ->OutEdgeIt conversion 88 OutEdgeIt ei(G,e); 89 } 90 { 91 Node n,m; 92 n=m=INVALID; 93 Edge e; 94 e=INVALID; 95 n=G.tail(e); 96 n=G.head(e); 97 } 98 // id tests 99 { Node n; int i=G.id(n); i=i; } 100 { Edge e; int i=G.id(e); i=i; } 101 //NodeMap tests 102 { 103 Node k; 104 typename Graph::template NodeMap<int> m(G); 105 //Const map 106 typename Graph::template NodeMap<int> const &cm = m; 107 //Inicialize with default value 108 typename Graph::template NodeMap<int> mdef(G,12); 109 //Copy 110 typename Graph::template NodeMap<int> mm(cm); 111 //Copy from another type 112 typename Graph::template NodeMap<double> dm(cm); 113 int v; 114 v=m[k]; m[k]=v; m.set(k,v); 115 v=cm[k]; 30 { 31 Node i; Node j(i); Node k(INVALID); 32 i=j; 33 bool b; b=true; 34 b=(i==INVALID); b=(i!=INVALID); 35 b=(i==j); b=(i!=j); b=(i<j); 36 } 37 { 38 NodeIt i; NodeIt j(i); NodeIt k(INVALID); NodeIt l(G); 39 i=j; 40 j=G.first(i); 41 j=++i; 42 bool b; b=true; 43 b=(i==INVALID); b=(i!=INVALID); 44 Node n(i); 45 n=i; 46 b=(i==j); b=(i!=j); b=(i<j); 47 //Node ->NodeIt conversion 48 NodeIt ni(G,n); 49 } 50 { 51 Edge i; Edge j(i); Edge k(INVALID); 52 i=j; 53 bool b; b=true; 54 b=(i==INVALID); b=(i!=INVALID); 55 b=(i==j); b=(i!=j); b=(i<j); 56 } 57 { 58 EdgeIt i; EdgeIt j(i); EdgeIt k(INVALID); EdgeIt l(G); 59 i=j; 60 j=G.first(i); 61 j=++i; 62 bool b; b=true; 63 b=(i==INVALID); b=(i!=INVALID); 64 Edge e(i); 65 e=i; 66 b=(i==j); b=(i!=j); b=(i<j); 67 //Edge ->EdgeIt conversion 68 EdgeIt ei(G,e); 69 } 70 { 71 Node n; 72 InEdgeIt i; InEdgeIt j(i); InEdgeIt k(INVALID); InEdgeIt l(G,n); 73 i=j; 74 j=G.first(i,n); 75 j=++i; 76 bool b; b=true; 77 b=(i==INVALID); b=(i!=INVALID); 78 Edge e(i); 79 e=i; 80 b=(i==j); b=(i!=j); b=(i<j); 81 //Edge ->InEdgeIt conversion 82 InEdgeIt ei(G,e); 83 } 84 { 85 Node n; 86 OutEdgeIt i; OutEdgeIt j(i); OutEdgeIt k(INVALID); OutEdgeIt l(G,n); 87 i=j; 88 j=G.first(i,n); 89 j=++i; 90 bool b; b=true; 91 b=(i==INVALID); b=(i!=INVALID); 92 Edge e(i); 93 e=i; 94 b=(i==j); b=(i!=j); b=(i<j); 95 //Edge ->OutEdgeIt conversion 96 OutEdgeIt ei(G,e); 97 } 98 { 99 Node n,m; 100 n=m=INVALID; 101 Edge e; 102 e=INVALID; 103 n=G.tail(e); 104 n=G.head(e); 105 } 106 // id tests 107 { Node n; int i=G.id(n); i=i; } 108 { Edge e; int i=G.id(e); i=i; } 109 //NodeMap tests 110 { 111 Node k; 112 typename Graph::template NodeMap<int> m(G); 113 //Const map 114 typename Graph::template NodeMap<int> const &cm = m; 115 //Inicialize with default value 116 typename Graph::template NodeMap<int> mdef(G,12); 117 //Copy 118 typename Graph::template NodeMap<int> mm(cm); 119 //Copy from another type 120 typename Graph::template NodeMap<double> dm(cm); 121 //Copy to more complex type 122 typename Graph::template NodeMap<DummyType> em(cm); 123 int v; 124 v=m[k]; m[k]=v; m.set(k,v); 125 v=cm[k]; 116 126 117 m=cm; 118 dm=cm; //Copy from another type 119 { 120 //Check the typedef's 121 typename Graph::template NodeMap<int>::ValueType val; 122 val=1; 123 typename Graph::template NodeMap<int>::KeyType key; 124 key = typename Graph::NodeIt(G); 125 } 126 } 127 { //bool NodeMap 128 Node k; 129 typename Graph::template NodeMap<bool> m(G); 130 typename Graph::template NodeMap<bool> const &cm = m; //Const map 131 //Inicialize with default value 132 typename Graph::template NodeMap<bool> mdef(G,12); 133 typename Graph::template NodeMap<bool> mm(cm); //Copy 134 typename Graph::template NodeMap<int> dm(cm); //Copy from another type 135 bool v; 136 v=m[k]; m[k]=v; m.set(k,v); 137 v=cm[k]; 127 m=cm; 128 dm=cm; //Copy from another type 129 em=cm; //Copy to more complex type 130 { 131 //Check the typedef's 132 typename Graph::template NodeMap<int>::ValueType val; 133 val=1; 134 typename Graph::template NodeMap<int>::KeyType key; 135 key = typename Graph::NodeIt(G); 136 } 137 } 138 { //bool NodeMap 139 Node k; 140 typename Graph::template NodeMap<bool> m(G); 141 typename Graph::template NodeMap<bool> const &cm = m; //Const map 142 //Inicialize with default value 143 typename Graph::template NodeMap<bool> mdef(G,12); 144 typename Graph::template NodeMap<bool> mm(cm); //Copy 145 typename Graph::template NodeMap<int> dm(cm); //Copy from another type 146 bool v; 147 v=m[k]; m[k]=v; m.set(k,v); 148 v=cm[k]; 138 149 139 140 141 142 143 144 145 146 147 148 149 150 }151 //EdgeMap tests152 {153 154 155 156 157 158 159 160 161 162 150 m=cm; 151 dm=cm; //Copy from another type 152 m=dm; //Copy to another type 153 154 { 155 //Check the typedef's 156 typename Graph::template NodeMap<bool>::ValueType val; 157 val=true; 158 typename Graph::template NodeMap<bool>::KeyType key; 159 key= typename Graph::NodeIt(G); 160 } 161 } 162 //EdgeMap tests 163 { 164 Edge k; 165 typename Graph::template EdgeMap<int> m(G); 166 typename Graph::template EdgeMap<int> const &cm = m; //Const map 167 //Inicialize with default value 168 typename Graph::template EdgeMap<int> mdef(G,12); 169 typename Graph::template EdgeMap<int> mm(cm); //Copy 170 typename Graph::template EdgeMap<double> dm(cm); //Copy from another type 171 int v; 172 v=m[k]; m[k]=v; m.set(k,v); 173 v=cm[k]; 163 174 164 165 166 167 168 169 170 171 172 173 }174 { //bool EdgeMap175 176 177 178 179 180 181 182 183 184 175 m=cm; 176 dm=cm; //Copy from another type 177 { 178 //Check the typedef's 179 typename Graph::template EdgeMap<int>::ValueType val; 180 val=1; 181 typename Graph::template EdgeMap<int>::KeyType key; 182 key= typename Graph::EdgeIt(G); 183 } 184 } 185 { //bool EdgeMap 186 Edge k; 187 typename Graph::template EdgeMap<bool> m(G); 188 typename Graph::template EdgeMap<bool> const &cm = m; //Const map 189 //Inicialize with default value 190 typename Graph::template EdgeMap<bool> mdef(G,12); 191 typename Graph::template EdgeMap<bool> mm(cm); //Copy 192 typename Graph::template EdgeMap<int> dm(cm); //Copy from another type 193 bool v; 194 v=m[k]; m[k]=v; m.set(k,v); 195 v=cm[k]; 185 196 186 187 188 189 190 191 192 193 194 195 196 }197 }198 199 template<class Graph> void checkCompileGraph(Graph &G)200 {201 checkCompileStaticGraph(G);202 203 typedef typename Graph::Node Node;204 typedef typename Graph::NodeIt NodeIt;205 typedef typename Graph::Edge Edge;206 typedef typename Graph::EdgeIt EdgeIt;207 typedef typename Graph::InEdgeIt InEdgeIt;208 typedef typename Graph::OutEdgeIt OutEdgeIt;197 m=cm; 198 dm=cm; //Copy from another type 199 m=dm; //Copy to another type 200 { 201 //Check the typedef's 202 typename Graph::template EdgeMap<bool>::ValueType val; 203 val=true; 204 typename Graph::template EdgeMap<bool>::KeyType key; 205 key= typename Graph::EdgeIt(G); 206 } 207 } 208 } 209 210 template<class Graph> void checkCompileGraph(Graph &G) 211 { 212 checkCompileStaticGraph(G); 213 214 typedef typename Graph::Node Node; 215 typedef typename Graph::NodeIt NodeIt; 216 typedef typename Graph::Edge Edge; 217 typedef typename Graph::EdgeIt EdgeIt; 218 typedef typename Graph::InEdgeIt InEdgeIt; 219 typedef typename Graph::OutEdgeIt OutEdgeIt; 209 220 210 Node n,m;211 n=G.addNode();212 m=G.addNode();213 Edge e;214 e=G.addEdge(n,m);221 Node n,m; 222 n=G.addNode(); 223 m=G.addNode(); 224 Edge e; 225 e=G.addEdge(n,m); 215 226 216 // G.clear();217 }218 219 template<class Graph> void checkCompileGraphEraseEdge(Graph &G)220 {221 typename Graph::Edge e;222 G.erase(e);223 }224 225 template<class Graph> void checkCompileGraphEraseNode(Graph &G)226 {227 typename Graph::Node n;228 G.erase(n);229 }230 231 template<class Graph> void checkCompileErasableGraph(Graph &G)232 {233 checkCompileGraph(G);234 checkCompileGraphEraseNode(G);235 checkCompileGraphEraseEdge(G);236 }237 238 template<class Graph> void checkCompileGraphFindEdge(Graph &G)239 {240 typedef typename Graph::NodeIt Node;241 typedef typename Graph::NodeIt NodeIt;242 243 G.findEdge(NodeIt(G),++NodeIt(G),G.findEdge(NodeIt(G),++NodeIt(G)));244 G.findEdge(Node(),Node(),G.findEdge(Node(),Node()));245 }246 247 template<class Graph> void checkGraphNodeList(Graph &G, int nn)248 {249 typename Graph::NodeIt n(G);250 for(int i=0;i<nn;i++) {251 252 253 }254 check(n==INVALID,"Wrong Node list linking.");255 }256 257 template<class Graph> void checkGraphEdgeList(Graph &G, int nn)258 {259 typedef typename Graph::EdgeIt EdgeIt;260 261 EdgeIt e(G);262 for(int i=0;i<nn;i++) {263 264 265 }266 check(e==INVALID,"Wrong Edge list linking.");267 }268 269 template<class Graph> void checkGraphOutEdgeList(Graph &G,270 typename Graph::Node n,271 int nn)272 {273 typename Graph::OutEdgeIt e(G,n);274 for(int i=0;i<nn;i++) {275 276 277 }278 check(e==INVALID,"Wrong OutEdge list linking.");279 }280 281 template<class Graph> void checkGraphInEdgeList(Graph &G,282 typename Graph::Node n,283 int nn)284 {285 typename Graph::InEdgeIt e(G,n);286 for(int i=0;i<nn;i++) {287 288 289 }290 check(e==INVALID,"Wrong InEdge list linking.");291 }292 293 ///\file294 ///\todo Check head(), tail() as well;227 // G.clear(); 228 } 229 230 template<class Graph> void checkCompileGraphEraseEdge(Graph &G) 231 { 232 typename Graph::Edge e; 233 G.erase(e); 234 } 235 236 template<class Graph> void checkCompileGraphEraseNode(Graph &G) 237 { 238 typename Graph::Node n; 239 G.erase(n); 240 } 241 242 template<class Graph> void checkCompileErasableGraph(Graph &G) 243 { 244 checkCompileGraph(G); 245 checkCompileGraphEraseNode(G); 246 checkCompileGraphEraseEdge(G); 247 } 248 249 template<class Graph> void checkCompileGraphFindEdge(Graph &G) 250 { 251 typedef typename Graph::NodeIt Node; 252 typedef typename Graph::NodeIt NodeIt; 253 254 G.findEdge(NodeIt(G),++NodeIt(G),G.findEdge(NodeIt(G),++NodeIt(G))); 255 G.findEdge(Node(),Node(),G.findEdge(Node(),Node())); 256 } 257 258 template<class Graph> void checkGraphNodeList(Graph &G, int nn) 259 { 260 typename Graph::NodeIt n(G); 261 for(int i=0;i<nn;i++) { 262 check(n!=INVALID,"Wrong Node list linking."); 263 ++n; 264 } 265 check(n==INVALID,"Wrong Node list linking."); 266 } 267 268 template<class Graph> void checkGraphEdgeList(Graph &G, int nn) 269 { 270 typedef typename Graph::EdgeIt EdgeIt; 271 272 EdgeIt e(G); 273 for(int i=0;i<nn;i++) { 274 check(e!=INVALID,"Wrong Edge list linking."); 275 ++e; 276 } 277 check(e==INVALID,"Wrong Edge list linking."); 278 } 279 280 template<class Graph> void checkGraphOutEdgeList(Graph &G, 281 typename Graph::Node n, 282 int nn) 283 { 284 typename Graph::OutEdgeIt e(G,n); 285 for(int i=0;i<nn;i++) { 286 check(e!=INVALID,"Wrong OutEdge list linking."); 287 ++e; 288 } 289 check(e==INVALID,"Wrong OutEdge list linking."); 290 } 291 292 template<class Graph> void checkGraphInEdgeList(Graph &G, 293 typename Graph::Node n, 294 int nn) 295 { 296 typename Graph::InEdgeIt e(G,n); 297 for(int i=0;i<nn;i++) { 298 check(e!=INVALID,"Wrong InEdge list linking."); 299 ++e; 300 } 301 check(e==INVALID,"Wrong InEdge list linking."); 302 } 303 304 ///\file 305 ///\todo Check head(), tail() as well; 295 306 296 307 -
src/test/graph_wrapper_test.cc
r878 r891 19 19 20 20 21 //Compile SmartGraph22 21 typedef SmartGraph Graph; 22 23 //Compile GraphWrapper 23 24 typedef GraphWrapper<Graph> GW; 24 25 template void checkCompileStaticGraph<GW>(GW &); 25 //template void checkCompileGraphFindEdge<SmartGraph>(SmartGraph &);26 26 27 //Compile SymSmartGraph27 //Compile RevGraphWrapper 28 28 typedef RevGraphWrapper<Graph> RevGW; 29 29 template void checkCompileStaticGraph<RevGW>(RevGW &); 30 //template void checkCompileGraphFindEdge<SymSmartGraph>(SymSmartGraph &); 30 31 //Compile SubGraphWrapper 32 typedef SubGraphWrapper<Graph, Graph::NodeMap<bool>, 33 Graph::EdgeMap<bool> > SubGW; 34 template void checkCompileStaticGraph<SubGW>(SubGW &); 35 36 //Compile UndirGraphWrapper 37 /// \bug UndirGraphWrapper cannot pass the StaticGraph test 38 //typedef UndirGraphWrapper<Graph> UndirGW; 39 //template void checkCompileStaticGraph<UndirGW>(UndirGW &); 40 41 //Compile UndirGraph 42 //typedef UndirGraph<Graph> UndirG; 43 //template void checkCompileStaticGraph<UndirG>(UndirG &); 44 45 //typedef SubBidirGraphWrapper<Graph, Graph::EdgeMap<bool>, 46 /// \bug SubBidirGraphWrapper cannot pass the StaticGraph test 47 // Graph::EdgeMap<bool> > SubBDGW; 48 //template void checkCompileStaticGraph<SubBDGW>(SubBDGW &); 49 50 //Compile BidirGraphWrapper 51 //typedef BidirGraphWrapper<Graph> BidirGW; 52 //template void checkCompileStaticGraph<BidirGW>(BidirGW &); 53 54 //Compile BidirGraph 55 //typedef BidirGraph<Graph> BidirG; 56 //template void checkCompileStaticGraph<BidirG>(BidirG &); 57 58 //Compile ResGraphWrapper 59 //typedef ResGraphWrapper<Graph, int, Graph::EdgeMap<int>, 60 // Graph::EdgeMap<int> > ResGW; 61 //template void checkCompileStaticGraph<ResGW>(ResGW &); 62 63 //Compile ErasingFirstGraphWrapper 64 typedef ErasingFirstGraphWrapper<Graph, Graph::NodeMap<Graph::Edge> > ErasingFirstGW; 65 template void checkCompileStaticGraph<ErasingFirstGW>(ErasingFirstGW &); 31 66 32 67
Note: See TracChangeset
for help on using the changeset viewer.