src/test/test_tools.h
author hegyi
Mon, 13 Sep 2004 15:30:01 +0000
changeset 837 2d50d1f045c5
parent 774 4297098d9677
child 844 9bf990cb066d
permissions -rw-r--r--
Reserve is resolved.
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@825
    37
  ///Vector containing the outer nodes.
alpar@825
    38
  std::vector<typename Graph::Node> outer;
alpar@825
    39
  ///Vector containing the inner nodes.
alpar@825
    40
  std::vector<typename Graph::Node> inner;
alpar@825
    41
  ///Vector containing the edges of the inner circle.
alpar@825
    42
  std::vector<typename Graph::Edge> incir;
alpar@825
    43
  ///Vector containing the edges of the outer circle.
alpar@825
    44
  std::vector<typename Graph::Edge> outcir;
alpar@825
    45
  ///Vector containing the chord edges.
alpar@825
    46
  std::vector<typename Graph::Edge> chords;
alpar@574
    47
};
alpar@574
    48
alpar@721
    49
alpar@721
    50
alpar@574
    51
///Adds a Petersen graph to \c G.
alpar@574
    52
alpar@574
    53
///Adds a Petersen graph to \c G.
alpar@825
    54
///\return The nodes end edges og the generated graph.
alpar@721
    55
alpar@721
    56
template<typename Graph>
alpar@721
    57
PetStruct<Graph> addPetersen(Graph &G,int num=5)
alpar@574
    58
{
alpar@574
    59
  PetStruct<Graph> n;
alpar@574
    60
alpar@574
    61
  for(int i=0;i<num;i++) {
alpar@574
    62
    n.outer.push_back(G.addNode());
alpar@574
    63
    n.inner.push_back(G.addNode());
alpar@574
    64
  }
alpar@574
    65
alpar@574
    66
 for(int i=0;i<num;i++) {
alpar@574
    67
   n.chords.push_back(G.addEdge(n.outer[i],n.inner[i]));
alpar@574
    68
   n.outcir.push_back(G.addEdge(n.outer[i],n.outer[(i+1)%5]));
alpar@574
    69
   n.incir.push_back(G.addEdge(n.inner[i],n.inner[(i+2)%5]));
alpar@574
    70
  }
alpar@574
    71
 return n;
alpar@574
    72
}
alpar@574
    73
alpar@574
    74
alpar@574
    75
alpar@574
    76
#endif