COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/test/test_tools.h @ 818:2b687ca1a08b

Last change on this file since 818:2b687ca1a08b was 774:4297098d9677, checked in by Alpar Juttner, 20 years ago

Merge back the whole branches/hugo++ to trunk.

File size: 1.7 KB
RevLine 
[574]1#ifndef HUGO_TEST_TEST_TOOLS_H
2#define HUGO_TEST_TEST_TOOLS_H
3
4//! \ingroup misc
5//! \file
6//! \brief Some utility to write test programs.
7
8
9#include<iostream>
10#include<vector>
11
[679]12///If \c rc is fail, writes an error message end exit.
[574]13
14///If \c rc is fail, writes an error message end exit.
15///The error message contains the file name and the line number of the
[679]16///source code in a standard from, which makes it possible to go there
[574]17///using good source browsers like e.g. \c emacs.
18///
19///For example
20///\code check(0==1,"This is obviously false.");\endcode will
21///print this (and then exits).
22///\verbatim graph_test.cc:123: error: This is obviously false. \endverbatim
[774]23///
24///\todo It should be in \c error.h
[574]25#define check(rc, msg) \
26  if(!(rc)) { \
27    std::cerr << __FILE__ ":" << __LINE__ << ": error: " << msg << std::endl; \
28    exit(1); \
29  } else { } \
30
31///Structure returned by \ref addPetersen().
32
33///Structure returned by \ref addPetersen().
34///
35template<class Graph> struct PetStruct
36{
37  ///.
38  std::vector<typename Graph::Node> outer, inner;
39  ///.
40  std::vector<typename Graph::Edge> outcir, incir, chords;
41};
42
[721]43
44
[574]45///Adds a Petersen graph to \c G.
46
47///Adds a Petersen graph to \c G.
48///The nodes end edges will be listed in the return structure.
[721]49
50template<typename Graph>
51PetStruct<Graph> addPetersen(Graph &G,int num=5)
[574]52{
53  PetStruct<Graph> n;
54
55  for(int i=0;i<num;i++) {
56    n.outer.push_back(G.addNode());
57    n.inner.push_back(G.addNode());
58  }
59
60 for(int i=0;i<num;i++) {
61   n.chords.push_back(G.addEdge(n.outer[i],n.inner[i]));
62   n.outcir.push_back(G.addEdge(n.outer[i],n.outer[(i+1)%5]));
63   n.incir.push_back(G.addEdge(n.inner[i],n.inner[(i+2)%5]));
64  }
65 return n;
66}
67
68
69
70#endif
Note: See TracBrowser for help on using the repository browser.