Changeset 938:70e2886211d5 in lemon-0.x for src/test/graph_test.h
- Timestamp:
- 10/05/04 11:41:05 (20 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1266
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/test/graph_test.h
r937 r938 24 24 //! \brief Some utility to test graph classes. 25 25 namespace lemon { 26 27 struct DummyType {28 int value;29 DummyType() {}30 DummyType(int p) : value(p) {}31 DummyType& operator=(int p) { value = p; return *this;}32 };33 34 35 template<class Graph> void checkCompileStaticGraph(Graph &G)36 {37 typedef typename Graph::Node Node;38 typedef typename Graph::NodeIt NodeIt;39 typedef typename Graph::Edge Edge;40 typedef typename Graph::EdgeIt EdgeIt;41 typedef typename Graph::InEdgeIt InEdgeIt;42 typedef typename Graph::OutEdgeIt OutEdgeIt;43 44 {45 Node i; Node j(i); Node k(INVALID);46 i=j;47 bool b; b=true;48 b=(i==INVALID); b=(i!=INVALID);49 b=(i==j); b=(i!=j); b=(i<j);50 }51 {52 NodeIt i; NodeIt j(i); NodeIt k(INVALID); NodeIt l(G);53 i=j;54 j=G.first(i);55 j=++i;56 bool b; b=true;57 b=(i==INVALID); b=(i!=INVALID);58 Node n(i);59 n=i;60 b=(i==j); b=(i!=j); b=(i<j);61 //Node ->NodeIt conversion62 NodeIt ni(G,n);63 }64 {65 Edge i; Edge j(i); Edge k(INVALID);66 i=j;67 bool b; b=true;68 b=(i==INVALID); b=(i!=INVALID);69 b=(i==j); b=(i!=j); b=(i<j);70 }71 {72 EdgeIt i; EdgeIt j(i); EdgeIt k(INVALID); EdgeIt l(G);73 i=j;74 j=G.first(i);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 ->EdgeIt conversion82 EdgeIt ei(G,e);83 }84 {85 Node n;86 InEdgeIt i; InEdgeIt j(i); InEdgeIt k(INVALID); InEdgeIt 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 ->InEdgeIt conversion96 InEdgeIt ei(G,e);97 }98 {99 Node n;100 OutEdgeIt i; OutEdgeIt j(i); OutEdgeIt k(INVALID); OutEdgeIt l(G,n);101 i=j;102 j=G.first(i,n);103 j=++i;104 bool b; b=true;105 b=(i==INVALID); b=(i!=INVALID);106 Edge e(i);107 e=i;108 b=(i==j); b=(i!=j); b=(i<j);109 //Edge ->OutEdgeIt conversion110 OutEdgeIt ei(G,e);111 }112 {113 Node n,m;114 n=m=INVALID;115 Edge e;116 e=INVALID;117 n=G.tail(e);118 n=G.head(e);119 }120 // id tests121 { Node n; int i=G.id(n); i=i; }122 { Edge e; int i=G.id(e); i=i; }123 //NodeMap tests124 {125 Node k;126 typename Graph::template NodeMap<int> m(G);127 //Const map128 typename Graph::template NodeMap<int> const &cm = m;129 //Inicialize with default value130 typename Graph::template NodeMap<int> mdef(G,12);131 //Copy132 typename Graph::template NodeMap<int> mm(cm);133 //Copy from another type134 typename Graph::template NodeMap<double> dm(cm);135 //Copy to more complex type136 typename Graph::template NodeMap<DummyType> em(cm);137 int v;138 v=m[k]; m[k]=v; m.set(k,v);139 v=cm[k];140 141 m=cm;142 dm=cm; //Copy from another type143 em=cm; //Copy to more complex type144 {145 //Check the typedef's146 typename Graph::template NodeMap<int>::ValueType val;147 val=1;148 typename Graph::template NodeMap<int>::KeyType key;149 key = typename Graph::NodeIt(G);150 }151 }152 { //bool NodeMap153 Node k;154 typename Graph::template NodeMap<bool> m(G);155 typename Graph::template NodeMap<bool> const &cm = m; //Const map156 //Inicialize with default value157 typename Graph::template NodeMap<bool> mdef(G,12);158 typename Graph::template NodeMap<bool> mm(cm); //Copy159 typename Graph::template NodeMap<int> dm(cm); //Copy from another type160 bool v;161 v=m[k]; m[k]=v; m.set(k,v);162 v=cm[k];163 164 m=cm;165 dm=cm; //Copy from another type166 m=dm; //Copy to another type167 168 {169 //Check the typedef's170 typename Graph::template NodeMap<bool>::ValueType val;171 val=true;172 typename Graph::template NodeMap<bool>::KeyType key;173 key= typename Graph::NodeIt(G);174 }175 }176 //EdgeMap tests177 {178 Edge k;179 typename Graph::template EdgeMap<int> m(G);180 typename Graph::template EdgeMap<int> const &cm = m; //Const map181 //Inicialize with default value182 typename Graph::template EdgeMap<int> mdef(G,12);183 typename Graph::template EdgeMap<int> mm(cm); //Copy184 typename Graph::template EdgeMap<double> dm(cm); //Copy from another type185 int v;186 v=m[k]; m[k]=v; m.set(k,v);187 v=cm[k];188 189 m=cm;190 dm=cm; //Copy from another type191 {192 //Check the typedef's193 typename Graph::template EdgeMap<int>::ValueType val;194 val=1;195 typename Graph::template EdgeMap<int>::KeyType key;196 key= typename Graph::EdgeIt(G);197 }198 }199 { //bool EdgeMap200 Edge k;201 typename Graph::template EdgeMap<bool> m(G);202 typename Graph::template EdgeMap<bool> const &cm = m; //Const map203 //Inicialize with default value204 typename Graph::template EdgeMap<bool> mdef(G,12);205 typename Graph::template EdgeMap<bool> mm(cm); //Copy206 typename Graph::template EdgeMap<int> dm(cm); //Copy from another type207 bool v;208 v=m[k]; m[k]=v; m.set(k,v);209 v=cm[k];210 211 m=cm;212 dm=cm; //Copy from another type213 m=dm; //Copy to another type214 {215 //Check the typedef's216 typename Graph::template EdgeMap<bool>::ValueType val;217 val=true;218 typename Graph::template EdgeMap<bool>::KeyType key;219 key= typename Graph::EdgeIt(G);220 }221 }222 }223 224 template<class Graph> void checkCompileGraph(Graph &G)225 {226 checkCompileStaticGraph(G);227 228 typedef typename Graph::Node Node;229 typedef typename Graph::NodeIt NodeIt;230 typedef typename Graph::Edge Edge;231 typedef typename Graph::EdgeIt EdgeIt;232 typedef typename Graph::InEdgeIt InEdgeIt;233 typedef typename Graph::OutEdgeIt OutEdgeIt;234 235 Node n,m;236 n=G.addNode();237 m=G.addNode();238 Edge e;239 e=G.addEdge(n,m);240 241 // G.clear();242 }243 244 template<class Graph> void checkCompileGraphEraseEdge(Graph &G)245 {246 typename Graph::Edge e;247 G.erase(e);248 }249 250 template<class Graph> void checkCompileGraphEraseNode(Graph &G)251 {252 typename Graph::Node n;253 G.erase(n);254 }255 256 template<class Graph> void checkCompileErasableGraph(Graph &G)257 {258 checkCompileGraph(G);259 checkCompileGraphEraseNode(G);260 checkCompileGraphEraseEdge(G);261 }262 263 template<class Graph> void checkCompileGraphFindEdge(Graph &G)264 {265 typedef typename Graph::NodeIt Node;266 typedef typename Graph::NodeIt NodeIt;267 268 G.findEdge(NodeIt(G),++NodeIt(G),G.findEdge(NodeIt(G),++NodeIt(G)));269 G.findEdge(Node(),Node(),G.findEdge(Node(),Node()));270 }271 26 272 27 template<class Graph> void checkGraphNodeList(Graph &G, int nn)
Note: See TracChangeset
for help on using the changeset viewer.