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