COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/test/graph_test.h @ 920:2d6c8075d9d0

Last change on this file since 920:2d6c8075d9d0 was 919:6153d9cf78c6, checked in by Alpar Juttner, 20 years ago
  • Backport -r1227 and -r1220
  • Temporarily remove (move to attic) tight_edge_filter.h
File size: 7.9 KB
Line 
1/* -*- C++ -*-
2 * src/test/graph_test.h - Part of HUGOlib, a generic C++ optimization library
3 *
4 * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
5 * (Egervary Combinatorial Optimization Research Group, EGRES).
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#ifndef HUGO_TEST_GRAPH_TEST_H
17#define HUGO_TEST_GRAPH_TEST_H
18
19
20#include "test_tools.h"
21
22//! \ingroup misc
23//! \file
24//! \brief Some utility to  test graph classes.
25namespace hugo {
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 conversion
62        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 conversion
82        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 conversion
96        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 conversion
110        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 tests
121      { Node n; int i=G.id(n); i=i; }
122      { Edge e; int i=G.id(e); i=i; }
123      //NodeMap tests
124      {
125        Node k;
126        typename Graph::template NodeMap<int> m(G);
127        //Const map
128        typename Graph::template NodeMap<int> const &cm = m;
129        //Inicialize with default value
130        typename Graph::template NodeMap<int> mdef(G,12);
131        //Copy
132        typename Graph::template NodeMap<int> mm(cm);
133        //Copy from another type
134        typename Graph::template NodeMap<double> dm(cm);
135        //Copy to more complex type
136        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 type 
143        em=cm; //Copy to more complex type
144        {
145          //Check the typedef's
146          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 NodeMap
153        Node k;
154        typename Graph::template NodeMap<bool> m(G);
155        typename Graph::template NodeMap<bool> const &cm = m;  //Const map
156        //Inicialize with default value
157        typename Graph::template NodeMap<bool> mdef(G,12);
158        typename Graph::template NodeMap<bool> mm(cm);   //Copy
159        typename Graph::template NodeMap<int> dm(cm); //Copy from another type
160        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 type
166        m=dm; //Copy to another type
167
168        {
169          //Check the typedef's
170          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 tests
177      {
178        Edge k;
179        typename Graph::template EdgeMap<int> m(G);
180        typename Graph::template EdgeMap<int> const &cm = m;  //Const map
181        //Inicialize with default value
182        typename Graph::template EdgeMap<int> mdef(G,12);
183        typename Graph::template EdgeMap<int> mm(cm);   //Copy
184        typename Graph::template EdgeMap<double> dm(cm); //Copy from another type
185        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 type
191        {
192          //Check the typedef's
193          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 EdgeMap
200        Edge k;
201        typename Graph::template EdgeMap<bool> m(G);
202        typename Graph::template EdgeMap<bool> const &cm = m;  //Const map
203        //Inicialize with default value
204        typename Graph::template EdgeMap<bool> mdef(G,12);
205        typename Graph::template EdgeMap<bool> mm(cm);   //Copy
206        typename Graph::template EdgeMap<int> dm(cm); //Copy from another type
207        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 type
213        m=dm; //Copy to another type
214        {
215          //Check the typedef's
216          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
272  template<class Graph> void checkGraphNodeList(Graph &G, int nn)
273    {
274      typename Graph::NodeIt n(G);
275      for(int i=0;i<nn;i++) {
276        check(n!=INVALID,"Wrong Node list linking.");
277        ++n;
278      }
279      check(n==INVALID,"Wrong Node list linking.");
280    }
281
282  template<class Graph> void checkGraphEdgeList(Graph &G, int nn)
283    {
284      typedef typename Graph::EdgeIt EdgeIt;
285
286      EdgeIt e(G);
287      for(int i=0;i<nn;i++) {
288        check(e!=INVALID,"Wrong Edge list linking.");
289        ++e;
290      }
291      check(e==INVALID,"Wrong Edge list linking.");
292    }
293
294  template<class Graph> void checkGraphOutEdgeList(Graph &G,
295                                                   typename Graph::Node n,
296                                                   int nn)
297    {
298      typename Graph::OutEdgeIt e(G,n);
299      for(int i=0;i<nn;i++) {
300        check(e!=INVALID,"Wrong OutEdge list linking.");
301        ++e;
302      }
303      check(e==INVALID,"Wrong OutEdge list linking.");
304    }
305
306  template<class Graph> void checkGraphInEdgeList(Graph &G,
307                                                  typename Graph::Node n,
308                                                  int nn)
309    {
310      typename Graph::InEdgeIt e(G,n);
311      for(int i=0;i<nn;i++) {
312        check(e!=INVALID,"Wrong InEdge list linking.");
313        ++e;
314      }
315      check(e==INVALID,"Wrong InEdge list linking.");
316    }
317
318  ///\file
319  ///\todo Check head(), tail() as well;
320
321 
322} //namespace hugo
323
324
325#endif
Note: See TracBrowser for help on using the repository browser.