src/test/test_tools.h
author alpar
Tue, 15 Jun 2004 06:30:03 +0000
changeset 685 c7e37b066033
parent 574 7b0b12eb603b
child 721 1df9b762269b
permissions -rw-r--r--
Doc updates
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@574
    41
///Adds a Petersen graph to \c G.
alpar@574
    42
alpar@574
    43
///Adds a Petersen graph to \c G.
alpar@574
    44
///The nodes end edges will be listed in the return structure.
alpar@574
    45
template<class Graph> PetStruct<Graph> addPetersen(Graph &G,int num=5)
alpar@574
    46
{
alpar@574
    47
  PetStruct<Graph> n;
alpar@574
    48
alpar@574
    49
  for(int i=0;i<num;i++) {
alpar@574
    50
    n.outer.push_back(G.addNode());
alpar@574
    51
    n.inner.push_back(G.addNode());
alpar@574
    52
  }
alpar@574
    53
alpar@574
    54
 for(int i=0;i<num;i++) {
alpar@574
    55
   n.chords.push_back(G.addEdge(n.outer[i],n.inner[i]));
alpar@574
    56
   n.outcir.push_back(G.addEdge(n.outer[i],n.outer[(i+1)%5]));
alpar@574
    57
   n.incir.push_back(G.addEdge(n.inner[i],n.inner[(i+2)%5]));
alpar@574
    58
  }
alpar@574
    59
 return n;
alpar@574
    60
}
alpar@574
    61
alpar@574
    62
alpar@574
    63
alpar@574
    64
#endif