COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/test/sym_graph_test.h @ 938:70e2886211d5

Last change on this file since 938:70e2886211d5 was 938:70e2886211d5, checked in by Alpar Juttner, 20 years ago

Many of ckeckCompileXYZ()'s are now in the corresponding skeleton headers.
(Tests for Symmetric Graphs are still to be moved)

File size: 4.7 KB
Line 
1/* -*- C++ -*-
2 * src/test/sym_graph_test.h - Part of LEMON, 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 LEMON_TEST_SYM_GRAPH_TEST_H
17#define LEMON_TEST_SYM_GRAPH_TEST_H
18
19
20#include "graph_test.h"
21#include "test_tools.h"
22
23//! \ingroup misc
24//! \file
25//! \brief Some utility to test symmetric graph classes.
26namespace lemon {
27 
28  /// \e
29
30  /// \todo This should go to lemon/skeleton/symgraph.h
31  ///
32  template<class Graph> void checkCompileStaticSymGraph(Graph &G)
33    {
34      typedef typename Graph::Node Node;
35      typedef typename Graph::NodeIt NodeIt;
36      typedef typename Graph::SymEdge SymEdge;
37      typedef typename Graph::SymEdgeIt SymEdgeIt;
38      typedef typename Graph::Edge Edge;
39      typedef typename Graph::EdgeIt EdgeIt;
40      typedef typename Graph::InEdgeIt InEdgeIt;
41      typedef typename Graph::OutEdgeIt OutEdgeIt;
42
43      lemon::skeleton::checkCompileStaticGraph(G);
44 
45      {
46        SymEdge i; SymEdge j(i); SymEdge k(INVALID);
47        i=j;
48        bool b; b=true;
49        b=(i==INVALID); b=(i!=INVALID);
50        b=(i==j); b=(i!=j); b=(i<j);
51        Edge e;
52        e = G.forward(i);
53        e = G.backward(i);
54      }
55      {
56        SymEdgeIt i; SymEdgeIt j(i); SymEdgeIt k(INVALID); SymEdgeIt l(G);
57        i=j;
58        j=G.first(i);
59        j=++i;
60        bool b; b=true;
61        b=(i==INVALID); b=(i!=INVALID);
62        SymEdge n(i);
63        n=i;
64        b=(i==j); b=(i!=j); b=(i<j);
65        //SymEdge ->SymEdgeIt conversion
66        SymEdgeIt ni(G,n);
67      }
68      {
69        Edge i, j;
70        j = G.opposite(i);
71      }     
72      {
73        Node n;
74        SymEdge se;
75        se=INVALID;
76        n=G.tail(se);
77        n=G.head(se);
78      }
79      // id tests
80      { SymEdge n; int i=G.id(n); i=i; }
81      //SymEdgeMap tests
82      {
83        SymEdge k;
84        typename Graph::template SymEdgeMap<int> m(G);
85        typename Graph::template SymEdgeMap<int> const &cm = m;  //Const map
86        //Inicialize with default value
87        typename Graph::template SymEdgeMap<int> mdef(G,12);
88        typename Graph::template SymEdgeMap<int> mm(cm);   //Copy
89        typename Graph::template SymEdgeMap<double> dm(cm); //Copy from another type
90        int v;
91        v=m[k]; m[k]=v; m.set(k,v);
92        v=cm[k];
93   
94        m=cm; 
95        dm=cm; //Copy from another type
96        {
97          //Check the typedef's
98          typename Graph::template SymEdgeMap<int>::ValueType val;
99          val = 1;
100          typename Graph::template SymEdgeMap<int>::KeyType key;
101          key = typename Graph::SymEdgeIt(G);
102        }
103      } 
104      { //bool SymEdgeMap
105        SymEdge k;
106        typename Graph::template SymEdgeMap<bool> m(G);
107        typename Graph::template SymEdgeMap<bool> const &cm = m;  //Const map
108        //Inicialize with default value
109        typename Graph::template SymEdgeMap<bool> mdef(G,12);
110        typename Graph::template SymEdgeMap<bool> mm(cm);   //Copy
111        typename Graph::template SymEdgeMap<int> dm(cm); //Copy from another type
112        bool v;
113        v=m[k]; m[k]=v; m.set(k,v);
114        v=cm[k];
115   
116        m=cm; 
117        dm=cm; //Copy from another type
118        m=dm; //Copy to another type
119        {
120          //Check the typedef's
121          typename Graph::template SymEdgeMap<bool>::ValueType val;
122          val=true;
123          typename Graph::template SymEdgeMap<bool>::KeyType key;
124          key= typename Graph::SymEdgeIt(G);
125        }
126      }
127    }
128
129  template<class Graph> void checkCompileSymGraph(Graph &G)
130    {
131      checkCompileStaticSymGraph(G);
132
133      typedef typename Graph::Node Node;
134      typedef typename Graph::NodeIt NodeIt;
135      typedef typename Graph::SymEdge SymEdge;
136      typedef typename Graph::SymEdgeIt SymEdgeIt;
137      typedef typename Graph::Edge Edge;
138      typedef typename Graph::EdgeIt EdgeIt;
139      typedef typename Graph::InEdgeIt InEdgeIt;
140      typedef typename Graph::OutEdgeIt OutEdgeIt;
141 
142      Node n,m;
143      n=G.addNode();
144      m=G.addNode();
145      SymEdge e;
146      e = G.addEdge(n,m);
147 
148      //  G.clear();
149    }
150
151  template<class Graph> void checkCompileSymGraphEraseSymEdge(Graph &G)
152    {
153      typename Graph::SymEdge n;
154      G.erase(n);
155    }
156
157  template<class Graph> void checkCompileErasableSymGraph(Graph &G)
158    {
159      checkCompileSymGraph(G);
160      lemon::skeleton::checkCompileGraphEraseNode(G);
161      checkCompileSymGraphEraseSymEdge(G);
162    }
163
164  template<class Graph> void checkGraphSymEdgeList(Graph &G, int nn)
165    {
166      typedef typename Graph::SymEdgeIt SymEdgeIt;
167
168      SymEdgeIt e(G);
169      for(int i=0;i<nn;i++) {
170        check(e!=INVALID,"Wrong SymEdge list linking.");
171        ++e;
172      }
173      check(e==INVALID,"Wrong SymEdge list linking.");
174    }
175
176  ///\file
177  ///\todo Check head(), tail() as well;
178
179 
180} //namespace lemon
181
182
183#endif
Note: See TracBrowser for help on using the repository browser.