test/test_tools.h
changeset 171 02f4d5d9bfd7
parent 100 4f754b4cf82b
child 184 716b220697a0
     1.1 --- a/test/test_tools.h	Sun Jun 15 22:03:33 2008 +0200
     1.2 +++ b/test/test_tools.h	Sun Jun 15 22:05:23 2008 +0200
     1.3 @@ -19,163 +19,29 @@
     1.4  #ifndef LEMON_TEST_TEST_TOOLS_H
     1.5  #define LEMON_TEST_TEST_TOOLS_H
     1.6  
     1.7 +///\ingroup misc
     1.8 +///\file
     1.9 +///\brief Some utilities to write test programs.
    1.10 +
    1.11  #include <iostream>
    1.12 -#include <vector>
    1.13  
    1.14 -#include <cstdlib>
    1.15 -#include <ctime>
    1.16 +///If \c rc is fail, writes an error message and exits.
    1.17  
    1.18 -#include <lemon/concept_check.h>
    1.19 -#include <lemon/concepts/digraph.h>
    1.20 -
    1.21 -#include <lemon/random.h>
    1.22 -
    1.23 -using namespace lemon;
    1.24 -
    1.25 -//! \ingroup misc
    1.26 -//! \file
    1.27 -//! \brief Some utilities to write test programs.
    1.28 -
    1.29 -
    1.30 -///If \c rc is fail, writes an error message end exit.
    1.31 -
    1.32 -///If \c rc is fail, writes an error message end exit.
    1.33 +///If \c rc is fail, writes an error message and exits.
    1.34  ///The error message contains the file name and the line number of the
    1.35  ///source code in a standard from, which makes it possible to go there
    1.36  ///using good source browsers like e.g. \c emacs.
    1.37  ///
    1.38  ///For example
    1.39  ///\code check(0==1,"This is obviously false.");\endcode will
    1.40 -///print this (and then exits).
    1.41 -///\verbatim digraph_test.cc:123: error: This is obviously false. \endverbatim
    1.42 +///print something like this (and then exits).
    1.43 +///\verbatim file_name.cc:123: error: This is obviously false. \endverbatim
    1.44  ///
    1.45 -///\todo It should be in \c error.h
    1.46 +///\todo It should be in \c assert.h
    1.47  #define check(rc, msg) \
    1.48    if(!(rc)) { \
    1.49      std::cerr << __FILE__ ":" << __LINE__ << ": error: " << msg << std::endl; \
    1.50      abort(); \
    1.51    } else { } \
    1.52  
    1.53 -///Structure returned by \ref addPetersen().
    1.54 -
    1.55 -///Structure returned by \ref addPetersen().
    1.56 -///
    1.57 -template<class Digraph> struct PetStruct
    1.58 -{
    1.59 -  ///Vector containing the outer nodes.
    1.60 -  std::vector<typename Digraph::Node> outer;
    1.61 -  ///Vector containing the inner nodes.
    1.62 -  std::vector<typename Digraph::Node> inner;
    1.63 -  ///Vector containing the arcs of the inner circle.
    1.64 -  std::vector<typename Digraph::Arc> incir;
    1.65 -  ///Vector containing the arcs of the outer circle.
    1.66 -  std::vector<typename Digraph::Arc> outcir;
    1.67 -  ///Vector containing the chord arcs.
    1.68 -  std::vector<typename Digraph::Arc> chords;
    1.69 -};
    1.70 -
    1.71 -
    1.72 -
    1.73 -///Adds a Petersen digraph to \c G.
    1.74 -
    1.75 -///Adds a Petersen digraph to \c G.
    1.76 -///\return The nodes and arcs of the generated digraph.
    1.77 -
    1.78 -template<typename Digraph>
    1.79 -PetStruct<Digraph> addPetersen(Digraph &G,int num = 5)
    1.80 -{
    1.81 -  PetStruct<Digraph> n;
    1.82 -
    1.83 -  for(int i=0;i<num;i++) {
    1.84 -    n.outer.push_back(G.addNode());
    1.85 -    n.inner.push_back(G.addNode());
    1.86 -  }
    1.87 -
    1.88 - for(int i=0;i<num;i++) {
    1.89 -   n.chords.push_back(G.addArc(n.outer[i],n.inner[i]));
    1.90 -   n.outcir.push_back(G.addArc(n.outer[i],n.outer[(i+1) % num]));
    1.91 -   n.incir.push_back(G.addArc(n.inner[i],n.inner[(i+2) % num]));
    1.92 -  }
    1.93 - return n;
    1.94 -}
    1.95 -
    1.96 -/// \brief Adds to the digraph the reverse pair of all arcs.
    1.97 -///
    1.98 -/// Adds to the digraph the reverse pair of all arcs.
    1.99 -///
   1.100 -template<class Digraph> void bidirDigraph(Digraph &G)
   1.101 -{
   1.102 -  typedef typename Digraph::Arc Arc;
   1.103 -  typedef typename Digraph::ArcIt ArcIt;
   1.104 -  
   1.105 -  std::vector<Arc> ee;
   1.106 -  
   1.107 -  for(ArcIt e(G);e!=INVALID;++e) ee.push_back(e);
   1.108 -
   1.109 -  for(typename std::vector<Arc>::iterator p=ee.begin();p!=ee.end();p++)
   1.110 -    G.addArc(G.target(*p),G.source(*p));
   1.111 -}
   1.112 -
   1.113 -
   1.114 -/// \brief Checks the bidirectioned Petersen digraph.
   1.115 -///
   1.116 -///  Checks the bidirectioned Petersen digraph.
   1.117 -///
   1.118 -template<class Digraph> void checkBidirPetersen(Digraph &G, int num = 5)
   1.119 -{
   1.120 -  typedef typename Digraph::Node Node;
   1.121 -
   1.122 -  typedef typename Digraph::ArcIt ArcIt;
   1.123 -  typedef typename Digraph::NodeIt NodeIt;
   1.124 -
   1.125 -  checkDigraphNodeList(G, 2 * num);
   1.126 -  checkDigraphArcList(G, 6 * num);
   1.127 -
   1.128 -  for(NodeIt n(G);n!=INVALID;++n) {
   1.129 -    checkDigraphInArcList(G, n, 3);
   1.130 -    checkDigraphOutArcList(G, n, 3);
   1.131 -  }  
   1.132 -}
   1.133 -
   1.134 -///Structure returned by \ref addUPetersen().
   1.135 -
   1.136 -///Structure returned by \ref addUPetersen().
   1.137 -///
   1.138 -template<class Digraph> struct UPetStruct
   1.139 -{
   1.140 -  ///Vector containing the outer nodes.
   1.141 -  std::vector<typename Digraph::Node> outer;
   1.142 -  ///Vector containing the inner nodes.
   1.143 -  std::vector<typename Digraph::Node> inner;
   1.144 -  ///Vector containing the arcs of the inner circle.
   1.145 -  std::vector<typename Digraph::Edge> incir;
   1.146 -  ///Vector containing the arcs of the outer circle.
   1.147 -  std::vector<typename Digraph::Edge> outcir;
   1.148 -  ///Vector containing the chord arcs.
   1.149 -  std::vector<typename Digraph::Edge> chords;
   1.150 -};
   1.151 -
   1.152 -///Adds a Petersen digraph to the undirected \c G.
   1.153 -
   1.154 -///Adds a Petersen digraph to the undirected \c G.
   1.155 -///\return The nodes and arcs of the generated digraph.
   1.156 -
   1.157 -template<typename Digraph>
   1.158 -UPetStruct<Digraph> addUPetersen(Digraph &G,int num=5)
   1.159 -{
   1.160 -  UPetStruct<Digraph> n;
   1.161 -
   1.162 -  for(int i=0;i<num;i++) {
   1.163 -    n.outer.push_back(G.addNode());
   1.164 -    n.inner.push_back(G.addNode());
   1.165 -  }
   1.166 -
   1.167 - for(int i=0;i<num;i++) {
   1.168 -   n.chords.push_back(G.addArc(n.outer[i],n.inner[i]));
   1.169 -   n.outcir.push_back(G.addArc(n.outer[i],n.outer[(i+1)%5]));
   1.170 -   n.incir.push_back(G.addArc(n.inner[i],n.inner[(i+2)%5]));
   1.171 - }
   1.172 - return n;
   1.173 -}
   1.174 -
   1.175  #endif