src/test/test_tools.h
changeset 1435 8e85e6bbefdf
parent 1434 d8475431bbbb
child 1436 e0beb94d08bf
     1.1 --- a/src/test/test_tools.h	Sat May 21 21:04:57 2005 +0000
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,173 +0,0 @@
     1.4 -/* -*- C++ -*-
     1.5 - * src/test/test_tools.h - Part of LEMON, a generic C++ optimization library
     1.6 - *
     1.7 - * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
     1.8 - * (Egervary Research Group on Combinatorial Optimization, 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 -
    1.20 -#ifndef LEMON_TEST_TEST_TOOLS_H
    1.21 -#define LEMON_TEST_TEST_TOOLS_H
    1.22 -
    1.23 -#include <iostream>
    1.24 -#include <vector>
    1.25 -
    1.26 -#include <lemon/invalid.h>
    1.27 -
    1.28 -using namespace lemon;
    1.29 -
    1.30 -//! \ingroup misc
    1.31 -//! \file
    1.32 -//! \brief Some utilities to write test programs.
    1.33 -
    1.34 -
    1.35 -///If \c rc is fail, writes an error message end exit.
    1.36 -
    1.37 -///If \c rc is fail, writes an error message end exit.
    1.38 -///The error message contains the file name and the line number of the
    1.39 -///source code in a standard from, which makes it possible to go there
    1.40 -///using good source browsers like e.g. \c emacs.
    1.41 -///
    1.42 -///For example
    1.43 -///\code check(0==1,"This is obviously false.");\endcode will
    1.44 -///print this (and then exits).
    1.45 -///\verbatim graph_test.cc:123: error: This is obviously false. \endverbatim
    1.46 -///
    1.47 -///\todo It should be in \c error.h
    1.48 -#define check(rc, msg) \
    1.49 -  if(!(rc)) { \
    1.50 -    std::cerr << __FILE__ ":" << __LINE__ << ": error: " << msg << std::endl; \
    1.51 -    exit(1); \
    1.52 -  } else { } \
    1.53 -
    1.54 -///Structure returned by \ref addPetersen().
    1.55 -
    1.56 -///Structure returned by \ref addPetersen().
    1.57 -///
    1.58 -template<class Graph> struct PetStruct
    1.59 -{
    1.60 -  ///Vector containing the outer nodes.
    1.61 -  std::vector<typename Graph::Node> outer;
    1.62 -  ///Vector containing the inner nodes.
    1.63 -  std::vector<typename Graph::Node> inner;
    1.64 -  ///Vector containing the edges of the inner circle.
    1.65 -  std::vector<typename Graph::Edge> incir;
    1.66 -  ///Vector containing the edges of the outer circle.
    1.67 -  std::vector<typename Graph::Edge> outcir;
    1.68 -  ///Vector containing the chord edges.
    1.69 -  std::vector<typename Graph::Edge> chords;
    1.70 -};
    1.71 -
    1.72 -
    1.73 -
    1.74 -///Adds a Petersen graph to \c G.
    1.75 -
    1.76 -///Adds a Petersen graph to \c G.
    1.77 -///\return The nodes and edges of the generated graph.
    1.78 -
    1.79 -template<typename Graph>
    1.80 -PetStruct<Graph> addPetersen(Graph &G,int num = 5)
    1.81 -{
    1.82 -  PetStruct<Graph> n;
    1.83 -
    1.84 -  for(int i=0;i<num;i++) {
    1.85 -    n.outer.push_back(G.addNode());
    1.86 -    n.inner.push_back(G.addNode());
    1.87 -  }
    1.88 -
    1.89 - for(int i=0;i<num;i++) {
    1.90 -   n.chords.push_back(G.addEdge(n.outer[i],n.inner[i]));
    1.91 -   n.outcir.push_back(G.addEdge(n.outer[i],n.outer[(i+1) % num]));
    1.92 -   n.incir.push_back(G.addEdge(n.inner[i],n.inner[(i+2) % num]));
    1.93 -  }
    1.94 - return n;
    1.95 -}
    1.96 -
    1.97 -/// \brief Adds to the graph the reverse pair of all edges.
    1.98 -///
    1.99 -/// Adds to the graph the reverse pair of all edges.
   1.100 -///
   1.101 -template<class Graph> void bidirGraph(Graph &G)
   1.102 -{
   1.103 -  typedef typename Graph::Edge Edge;
   1.104 -  typedef typename Graph::EdgeIt EdgeIt;
   1.105 -  
   1.106 -  std::vector<Edge> ee;
   1.107 -  
   1.108 -  for(EdgeIt e(G);e!=INVALID;++e) ee.push_back(e);
   1.109 -
   1.110 -  for(typename std::vector<Edge>::iterator p=ee.begin();p!=ee.end();p++)
   1.111 -    G.addEdge(G.target(*p),G.source(*p));
   1.112 -}
   1.113 -
   1.114 -
   1.115 -/// \brief Checks the bidirectioned Petersen graph.
   1.116 -///
   1.117 -///  Checks the bidirectioned Petersen graph.
   1.118 -///
   1.119 -template<class Graph> void checkBidirPetersen(Graph &G, int num = 5)
   1.120 -{
   1.121 -  typedef typename Graph::Node Node;
   1.122 -
   1.123 -  typedef typename Graph::EdgeIt EdgeIt;
   1.124 -  typedef typename Graph::NodeIt NodeIt;
   1.125 -
   1.126 -  checkGraphNodeList(G, 2 * num);
   1.127 -  checkGraphEdgeList(G, 6 * num);
   1.128 -
   1.129 -  for(NodeIt n(G);n!=INVALID;++n) {
   1.130 -    checkGraphInEdgeList(G, n, 3);
   1.131 -    checkGraphOutEdgeList(G, n, 3);
   1.132 -  }  
   1.133 -}
   1.134 -
   1.135 -///Structure returned by \ref addSymPetersen().
   1.136 -
   1.137 -///Structure returned by \ref addSymPetersen().
   1.138 -///
   1.139 -template<class Graph> struct SymPetStruct
   1.140 -{
   1.141 -  ///Vector containing the outer nodes.
   1.142 -  std::vector<typename Graph::Node> outer;
   1.143 -  ///Vector containing the inner nodes.
   1.144 -  std::vector<typename Graph::Node> inner;
   1.145 -  ///Vector containing the edges of the inner circle.
   1.146 -  std::vector<typename Graph::SymEdge> incir;
   1.147 -  ///Vector containing the edges of the outer circle.
   1.148 -  std::vector<typename Graph::SymEdge> outcir;
   1.149 -  ///Vector containing the chord edges.
   1.150 -  std::vector<typename Graph::SymEdge> chords;
   1.151 -};
   1.152 -
   1.153 -///Adds a Petersen graph to the symmetric \c G.
   1.154 -
   1.155 -///Adds a Petersen graph to the symmetric \c G.
   1.156 -///\return The nodes and edges of the generated graph.
   1.157 -
   1.158 -template<typename Graph>
   1.159 -SymPetStruct<Graph> addSymPetersen(Graph &G,int num=5)
   1.160 -{
   1.161 -  SymPetStruct<Graph> n;
   1.162 -
   1.163 -  for(int i=0;i<num;i++) {
   1.164 -    n.outer.push_back(G.addNode());
   1.165 -    n.inner.push_back(G.addNode());
   1.166 -  }
   1.167 -
   1.168 - for(int i=0;i<num;i++) {
   1.169 -   n.chords.push_back(G.addEdge(n.outer[i],n.inner[i]));
   1.170 -   n.outcir.push_back(G.addEdge(n.outer[i],n.outer[(i+1)%5]));
   1.171 -   n.incir.push_back(G.addEdge(n.inner[i],n.inner[(i+2)%5]));
   1.172 -  }
   1.173 - return n;
   1.174 -}
   1.175 -
   1.176 -#endif