src/test/test_tools.h
author marci
Wed, 29 Sep 2004 19:02:26 +0000
changeset 923 acbef5dd0e65
parent 919 6153d9cf78c6
child 937 d4e911acef3d
permissions -rw-r--r--
more docs
alpar@906
     1
/* -*- C++ -*-
alpar@921
     2
 * src/test/test_tools.h - Part of LEMON, a generic C++ optimization library
alpar@906
     3
 *
alpar@906
     4
 * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
alpar@906
     5
 * (Egervary Combinatorial Optimization Research Group, EGRES).
alpar@906
     6
 *
alpar@906
     7
 * Permission to use, modify and distribute this software is granted
alpar@906
     8
 * provided that this copyright notice appears in all copies. For
alpar@906
     9
 * precise terms see the accompanying LICENSE file.
alpar@906
    10
 *
alpar@906
    11
 * This software is provided "AS IS" with no warranty of any kind,
alpar@906
    12
 * express or implied, and with no claim as to its suitability for any
alpar@906
    13
 * purpose.
alpar@906
    14
 *
alpar@906
    15
 */
alpar@906
    16
alpar@921
    17
#ifndef LEMON_TEST_TEST_TOOLS_H
alpar@921
    18
#define LEMON_TEST_TEST_TOOLS_H
alpar@574
    19
alpar@574
    20
//! \ingroup misc
alpar@574
    21
//! \file
alpar@574
    22
//! \brief Some utility to write test programs.
alpar@574
    23
alpar@574
    24
alpar@574
    25
#include<iostream>
alpar@574
    26
#include<vector>
alpar@574
    27
alpar@679
    28
///If \c rc is fail, writes an error message end exit.
alpar@574
    29
alpar@574
    30
///If \c rc is fail, writes an error message end exit.
alpar@574
    31
///The error message contains the file name and the line number of the
alpar@679
    32
///source code in a standard from, which makes it possible to go there
alpar@574
    33
///using good source browsers like e.g. \c emacs.
alpar@574
    34
///
alpar@574
    35
///For example
alpar@574
    36
///\code check(0==1,"This is obviously false.");\endcode will
alpar@574
    37
///print this (and then exits).
alpar@574
    38
///\verbatim graph_test.cc:123: error: This is obviously false. \endverbatim
alpar@774
    39
///
alpar@774
    40
///\todo It should be in \c error.h
alpar@574
    41
#define check(rc, msg) \
alpar@574
    42
  if(!(rc)) { \
alpar@574
    43
    std::cerr << __FILE__ ":" << __LINE__ << ": error: " << msg << std::endl; \
alpar@574
    44
    exit(1); \
alpar@574
    45
  } else { } \
alpar@574
    46
alpar@574
    47
///Structure returned by \ref addPetersen().
alpar@574
    48
alpar@574
    49
///Structure returned by \ref addPetersen().
alpar@574
    50
///
alpar@574
    51
template<class Graph> struct PetStruct
alpar@574
    52
{
alpar@825
    53
  ///Vector containing the outer nodes.
alpar@825
    54
  std::vector<typename Graph::Node> outer;
alpar@825
    55
  ///Vector containing the inner nodes.
alpar@825
    56
  std::vector<typename Graph::Node> inner;
alpar@825
    57
  ///Vector containing the edges of the inner circle.
alpar@825
    58
  std::vector<typename Graph::Edge> incir;
alpar@825
    59
  ///Vector containing the edges of the outer circle.
alpar@825
    60
  std::vector<typename Graph::Edge> outcir;
alpar@825
    61
  ///Vector containing the chord edges.
alpar@825
    62
  std::vector<typename Graph::Edge> chords;
alpar@574
    63
};
alpar@574
    64
alpar@721
    65
alpar@721
    66
alpar@574
    67
///Adds a Petersen graph to \c G.
alpar@574
    68
alpar@574
    69
///Adds a Petersen graph to \c G.
alpar@919
    70
///\return The nodes end edges og the generated graph.
alpar@721
    71
alpar@721
    72
template<typename Graph>
alpar@721
    73
PetStruct<Graph> addPetersen(Graph &G,int num=5)
alpar@574
    74
{
alpar@574
    75
  PetStruct<Graph> n;
alpar@574
    76
alpar@574
    77
  for(int i=0;i<num;i++) {
alpar@574
    78
    n.outer.push_back(G.addNode());
alpar@574
    79
    n.inner.push_back(G.addNode());
alpar@574
    80
  }
alpar@574
    81
alpar@574
    82
 for(int i=0;i<num;i++) {
alpar@574
    83
   n.chords.push_back(G.addEdge(n.outer[i],n.inner[i]));
alpar@574
    84
   n.outcir.push_back(G.addEdge(n.outer[i],n.outer[(i+1)%5]));
alpar@574
    85
   n.incir.push_back(G.addEdge(n.inner[i],n.inner[(i+2)%5]));
alpar@574
    86
  }
alpar@574
    87
 return n;
alpar@574
    88
}
alpar@574
    89
alpar@574
    90
alpar@574
    91
alpar@574
    92
#endif