src/test/test_tools.h
author marci
Wed, 01 Sep 2004 09:04:07 +0000
changeset 779 83c49c272679
parent 721 1df9b762269b
child 825 738abd9d1262
permissions -rw-r--r--
correction
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@774
    23
///
alpar@774
    24
///\todo It should be in \c error.h
alpar@574
    25
#define check(rc, msg) \
alpar@574
    26
  if(!(rc)) { \
alpar@574
    27
    std::cerr << __FILE__ ":" << __LINE__ << ": error: " << msg << std::endl; \
alpar@574
    28
    exit(1); \
alpar@574
    29
  } else { } \
alpar@574
    30
alpar@574
    31
///Structure returned by \ref addPetersen().
alpar@574
    32
alpar@574
    33
///Structure returned by \ref addPetersen().
alpar@574
    34
///
alpar@574
    35
template<class Graph> struct PetStruct
alpar@574
    36
{
alpar@574
    37
  ///.
alpar@574
    38
  std::vector<typename Graph::Node> outer, inner;
alpar@574
    39
  ///.
alpar@574
    40
  std::vector<typename Graph::Edge> outcir, incir, chords;
alpar@574
    41
};
alpar@574
    42
alpar@721
    43
alpar@721
    44
alpar@574
    45
///Adds a Petersen graph to \c G.
alpar@574
    46
alpar@574
    47
///Adds a Petersen graph to \c G.
alpar@574
    48
///The nodes end edges will be listed in the return structure.
alpar@721
    49
alpar@721
    50
template<typename Graph>
alpar@721
    51
PetStruct<Graph> addPetersen(Graph &G,int num=5)
alpar@574
    52
{
alpar@574
    53
  PetStruct<Graph> n;
alpar@574
    54
alpar@574
    55
  for(int i=0;i<num;i++) {
alpar@574
    56
    n.outer.push_back(G.addNode());
alpar@574
    57
    n.inner.push_back(G.addNode());
alpar@574
    58
  }
alpar@574
    59
alpar@574
    60
 for(int i=0;i<num;i++) {
alpar@574
    61
   n.chords.push_back(G.addEdge(n.outer[i],n.inner[i]));
alpar@574
    62
   n.outcir.push_back(G.addEdge(n.outer[i],n.outer[(i+1)%5]));
alpar@574
    63
   n.incir.push_back(G.addEdge(n.inner[i],n.inner[(i+2)%5]));
alpar@574
    64
  }
alpar@574
    65
 return n;
alpar@574
    66
}
alpar@574
    67
alpar@574
    68
alpar@574
    69
alpar@574
    70
#endif