src/test/test_tools.h
author deba
Mon, 04 Oct 2004 17:13:21 +0000
changeset 937 d4e911acef3d
parent 921 818510fa3d99
child 946 c94ef40a22ce
permissions -rw-r--r--
Revert backport changes -r1230.
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.
deba@937
    70
///\return The nodes and edges of 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
deba@937
    90
///Structure returned by \ref addSymPetersen().
alpar@574
    91
deba@937
    92
///Structure returned by \ref addSymPetersen().
deba@937
    93
///
deba@937
    94
template<class Graph> struct SymPetStruct
deba@937
    95
{
deba@937
    96
  ///Vector containing the outer nodes.
deba@937
    97
  std::vector<typename Graph::Node> outer;
deba@937
    98
  ///Vector containing the inner nodes.
deba@937
    99
  std::vector<typename Graph::Node> inner;
deba@937
   100
  ///Vector containing the edges of the inner circle.
deba@937
   101
  std::vector<typename Graph::SymEdge> incir;
deba@937
   102
  ///Vector containing the edges of the outer circle.
deba@937
   103
  std::vector<typename Graph::SymEdge> outcir;
deba@937
   104
  ///Vector containing the chord edges.
deba@937
   105
  std::vector<typename Graph::SymEdge> chords;
deba@937
   106
};
deba@937
   107
deba@937
   108
///Adds a Petersen graph to the symmetric \c G.
deba@937
   109
deba@937
   110
///Adds a Petersen graph to the symmetric \c G.
deba@937
   111
///\return The nodes and edges of the generated graph.
deba@937
   112
deba@937
   113
template<typename Graph>
deba@937
   114
SymPetStruct<Graph> addSymPetersen(Graph &G,int num=5)
deba@937
   115
{
deba@937
   116
  SymPetStruct<Graph> n;
deba@937
   117
deba@937
   118
  for(int i=0;i<num;i++) {
deba@937
   119
    n.outer.push_back(G.addNode());
deba@937
   120
    n.inner.push_back(G.addNode());
deba@937
   121
  }
deba@937
   122
deba@937
   123
 for(int i=0;i<num;i++) {
deba@937
   124
   n.chords.push_back(G.addEdge(n.outer[i],n.inner[i]));
deba@937
   125
   n.outcir.push_back(G.addEdge(n.outer[i],n.outer[(i+1)%5]));
deba@937
   126
   n.incir.push_back(G.addEdge(n.inner[i],n.inner[(i+2)%5]));
deba@937
   127
  }
deba@937
   128
 return n;
deba@937
   129
}
alpar@574
   130
alpar@574
   131
#endif