src/test/test_tools.h
author marci
Tue, 17 Aug 2004 10:24:19 +0000
changeset 761 58243a389464
parent 679 5860141a60b5
child 774 4297098d9677
permissions -rw-r--r--
flowValue() is reset to deal with excess[t].
alpar@574
     1
#ifndef HUGO_TEST_TEST_TOOLS_H
alpar@574
     2
#define HUGO_TEST_TEST_TOOLS_H
alpar@574
     3
alpar@574
     4
//! \ingroup misc
alpar@574
     5
//! \file
alpar@574
     6
//! \brief Some utility to write test programs.
alpar@574
     7
alpar@574
     8
alpar@574
     9
#include<iostream>
alpar@574
    10
#include<vector>
alpar@574
    11
alpar@679
    12
///If \c rc is fail, writes an error message end exit.
alpar@574
    13
alpar@574
    14
///If \c rc is fail, writes an error message end exit.
alpar@574
    15
///The error message contains the file name and the line number of the
alpar@679
    16
///source code in a standard from, which makes it possible to go there
alpar@574
    17
///using good source browsers like e.g. \c emacs.
alpar@574
    18
///
alpar@574
    19
///For example
alpar@574
    20
///\code check(0==1,"This is obviously false.");\endcode will
alpar@574
    21
///print this (and then exits).
alpar@574
    22
///\verbatim graph_test.cc:123: error: This is obviously false. \endverbatim
alpar@574
    23
#define check(rc, msg) \
alpar@574
    24
  if(!(rc)) { \
alpar@574
    25
    std::cerr << __FILE__ ":" << __LINE__ << ": error: " << msg << std::endl; \
alpar@574
    26
    exit(1); \
alpar@574
    27
  } else { } \
alpar@574
    28
alpar@574
    29
///Structure returned by \ref addPetersen().
alpar@574
    30
alpar@574
    31
///Structure returned by \ref addPetersen().
alpar@574
    32
///
alpar@574
    33
template<class Graph> struct PetStruct
alpar@574
    34
{
alpar@574
    35
  ///.
alpar@574
    36
  std::vector<typename Graph::Node> outer, inner;
alpar@574
    37
  ///.
alpar@574
    38
  std::vector<typename Graph::Edge> outcir, incir, chords;
alpar@574
    39
};
alpar@574
    40
alpar@721
    41
alpar@721
    42
alpar@574
    43
///Adds a Petersen graph to \c G.
alpar@574
    44
alpar@574
    45
///Adds a Petersen graph to \c G.
alpar@574
    46
///The nodes end edges will be listed in the return structure.
alpar@721
    47
alpar@721
    48
template<typename Graph>
alpar@721
    49
PetStruct<Graph> addPetersen(Graph &G,int num=5)
alpar@574
    50
{
alpar@574
    51
  PetStruct<Graph> n;
alpar@574
    52
alpar@574
    53
  for(int i=0;i<num;i++) {
alpar@574
    54
    n.outer.push_back(G.addNode());
alpar@574
    55
    n.inner.push_back(G.addNode());
alpar@574
    56
  }
alpar@574
    57
alpar@574
    58
 for(int i=0;i<num;i++) {
alpar@574
    59
   n.chords.push_back(G.addEdge(n.outer[i],n.inner[i]));
alpar@574
    60
   n.outcir.push_back(G.addEdge(n.outer[i],n.outer[(i+1)%5]));
alpar@574
    61
   n.incir.push_back(G.addEdge(n.inner[i],n.inner[(i+2)%5]));
alpar@574
    62
  }
alpar@574
    63
 return n;
alpar@574
    64
}
alpar@574
    65
alpar@574
    66
alpar@574
    67
alpar@574
    68
#endif