src/test/sym_graph_test.h
changeset 937 d4e911acef3d
child 938 70e2886211d5
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/test/sym_graph_test.h	Mon Oct 04 17:13:21 2004 +0000
     1.3 @@ -0,0 +1,179 @@
     1.4 +/* -*- C++ -*-
     1.5 + * src/test/sym_graph_test.h - Part of LEMON, a generic C++ optimization library
     1.6 + *
     1.7 + * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
     1.8 + * (Egervary Combinatorial Optimization Research Group, EGRES).
     1.9 + *
    1.10 + * Permission to use, modify and distribute this software is granted
    1.11 + * provided that this copyright notice appears in all copies. For
    1.12 + * precise terms see the accompanying LICENSE file.
    1.13 + *
    1.14 + * This software is provided "AS IS" with no warranty of any kind,
    1.15 + * express or implied, and with no claim as to its suitability for any
    1.16 + * purpose.
    1.17 + *
    1.18 + */
    1.19 +#ifndef LEMON_TEST_SYM_GRAPH_TEST_H
    1.20 +#define LEMON_TEST_SYM_GRAPH_TEST_H
    1.21 +
    1.22 +
    1.23 +#include "graph_test.h"
    1.24 +#include "test_tools.h"
    1.25 +
    1.26 +//! \ingroup misc
    1.27 +//! \file
    1.28 +//! \brief Some utility to test symmetric graph classes.
    1.29 +namespace lemon {
    1.30 +
    1.31 +  template<class Graph> void checkCompileStaticSymGraph(Graph &G) 
    1.32 +    {
    1.33 +      typedef typename Graph::Node Node;
    1.34 +      typedef typename Graph::NodeIt NodeIt;
    1.35 +      typedef typename Graph::SymEdge SymEdge;
    1.36 +      typedef typename Graph::SymEdgeIt SymEdgeIt;
    1.37 +      typedef typename Graph::Edge Edge;
    1.38 +      typedef typename Graph::EdgeIt EdgeIt;
    1.39 +      typedef typename Graph::InEdgeIt InEdgeIt;
    1.40 +      typedef typename Graph::OutEdgeIt OutEdgeIt;
    1.41 +
    1.42 +      checkCompileStaticGraph(G);
    1.43 +  
    1.44 +      {
    1.45 +	SymEdge i; SymEdge j(i); SymEdge k(INVALID);
    1.46 +	i=j;
    1.47 +	bool b; b=true;
    1.48 +	b=(i==INVALID); b=(i!=INVALID);
    1.49 +	b=(i==j); b=(i!=j); b=(i<j);
    1.50 +	Edge e;
    1.51 +	e = G.forward(i);
    1.52 +	e = G.backward(i);
    1.53 +      }
    1.54 +      {
    1.55 +	SymEdgeIt i; SymEdgeIt j(i); SymEdgeIt k(INVALID); SymEdgeIt l(G);
    1.56 +	i=j;
    1.57 +	j=G.first(i);
    1.58 +	j=++i;
    1.59 +	bool b; b=true;
    1.60 +	b=(i==INVALID); b=(i!=INVALID);
    1.61 +	SymEdge n(i);
    1.62 +	n=i;
    1.63 +	b=(i==j); b=(i!=j); b=(i<j);
    1.64 +	//SymEdge ->SymEdgeIt conversion
    1.65 +	SymEdgeIt ni(G,n);
    1.66 +      }
    1.67 +      {
    1.68 +	Edge i, j;
    1.69 +	j = G.opposite(i);
    1.70 +      }      
    1.71 +      {
    1.72 +	Node n;
    1.73 +	SymEdge se;
    1.74 +	se=INVALID;
    1.75 +	n=G.tail(se);
    1.76 +	n=G.head(se);
    1.77 +      }
    1.78 +      // id tests
    1.79 +      { SymEdge n; int i=G.id(n); i=i; }
    1.80 +      //SymEdgeMap tests
    1.81 +      {
    1.82 +	SymEdge k;
    1.83 +	typename Graph::template SymEdgeMap<int> m(G);
    1.84 +	typename Graph::template SymEdgeMap<int> const &cm = m;  //Const map
    1.85 +	//Inicialize with default value
    1.86 +	typename Graph::template SymEdgeMap<int> mdef(G,12);
    1.87 +	typename Graph::template SymEdgeMap<int> mm(cm);   //Copy
    1.88 +	typename Graph::template SymEdgeMap<double> dm(cm); //Copy from another type
    1.89 +	int v;
    1.90 +	v=m[k]; m[k]=v; m.set(k,v);
    1.91 +	v=cm[k];
    1.92 +    
    1.93 +	m=cm;  
    1.94 +	dm=cm; //Copy from another type
    1.95 +	{
    1.96 +	  //Check the typedef's
    1.97 +	  typename Graph::template SymEdgeMap<int>::ValueType val;
    1.98 +	  val = 1;
    1.99 +	  typename Graph::template SymEdgeMap<int>::KeyType key;
   1.100 +	  key = typename Graph::SymEdgeIt(G);
   1.101 +	}
   1.102 +      }  
   1.103 +      { //bool SymEdgeMap
   1.104 +	SymEdge k;
   1.105 +	typename Graph::template SymEdgeMap<bool> m(G);
   1.106 +	typename Graph::template SymEdgeMap<bool> const &cm = m;  //Const map
   1.107 +	//Inicialize with default value
   1.108 +	typename Graph::template SymEdgeMap<bool> mdef(G,12);
   1.109 +	typename Graph::template SymEdgeMap<bool> mm(cm);   //Copy
   1.110 +	typename Graph::template SymEdgeMap<int> dm(cm); //Copy from another type
   1.111 +	bool v;
   1.112 +	v=m[k]; m[k]=v; m.set(k,v);
   1.113 +	v=cm[k];
   1.114 +    
   1.115 +	m=cm;  
   1.116 +	dm=cm; //Copy from another type
   1.117 +	m=dm; //Copy to another type
   1.118 +	{
   1.119 +	  //Check the typedef's
   1.120 +	  typename Graph::template SymEdgeMap<bool>::ValueType val;
   1.121 +	  val=true;
   1.122 +	  typename Graph::template SymEdgeMap<bool>::KeyType key;
   1.123 +	  key= typename Graph::SymEdgeIt(G);
   1.124 +	}
   1.125 +      }
   1.126 +    }
   1.127 +
   1.128 +  template<class Graph> void checkCompileSymGraph(Graph &G) 
   1.129 +    {
   1.130 +      checkCompileStaticSymGraph(G);
   1.131 +
   1.132 +      typedef typename Graph::Node Node;
   1.133 +      typedef typename Graph::NodeIt NodeIt;
   1.134 +      typedef typename Graph::SymEdge SymEdge;
   1.135 +      typedef typename Graph::SymEdgeIt SymEdgeIt;
   1.136 +      typedef typename Graph::Edge Edge;
   1.137 +      typedef typename Graph::EdgeIt EdgeIt;
   1.138 +      typedef typename Graph::InEdgeIt InEdgeIt;
   1.139 +      typedef typename Graph::OutEdgeIt OutEdgeIt;
   1.140 +  
   1.141 +      Node n,m;
   1.142 +      n=G.addNode();
   1.143 +      m=G.addNode();
   1.144 +      SymEdge e;
   1.145 +      e = G.addEdge(n,m); 
   1.146 +  
   1.147 +      //  G.clear();
   1.148 +    }
   1.149 +
   1.150 +  template<class Graph> void checkCompileSymGraphEraseSymEdge(Graph &G) 
   1.151 +    {
   1.152 +      typename Graph::SymEdge n;
   1.153 +      G.erase(n);
   1.154 +    }
   1.155 +
   1.156 +  template<class Graph> void checkCompileErasableSymGraph(Graph &G) 
   1.157 +    {
   1.158 +      checkCompileSymGraph(G);
   1.159 +      checkCompileGraphEraseNode(G);
   1.160 +      checkCompileSymGraphEraseSymEdge(G);
   1.161 +    }
   1.162 +
   1.163 +  template<class Graph> void checkGraphSymEdgeList(Graph &G, int nn)
   1.164 +    {
   1.165 +      typedef typename Graph::SymEdgeIt SymEdgeIt;
   1.166 +
   1.167 +      SymEdgeIt e(G);
   1.168 +      for(int i=0;i<nn;i++) {
   1.169 +	check(e!=INVALID,"Wrong SymEdge list linking.");
   1.170 +	++e;
   1.171 +      }
   1.172 +      check(e==INVALID,"Wrong SymEdge list linking.");
   1.173 +    }
   1.174 +
   1.175 +  ///\file
   1.176 +  ///\todo Check head(), tail() as well;
   1.177 +
   1.178 +  
   1.179 +} //namespace lemon
   1.180 +
   1.181 +
   1.182 +#endif