COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/test/test_tools.h @ 843:d56fad02dc55

Last change on this file since 843:d56fad02dc55 was 825:738abd9d1262, checked in by Alpar Juttner, 20 years ago

Improved docs.

File size: 2.0 KB
Line 
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
12///If \c rc is fail, writes an error message end exit.
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
16///source code in a standard from, which makes it possible to go there
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
23///
24///\todo It should be in \c error.h
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  ///Vector containing the outer nodes.
38  std::vector<typename Graph::Node> outer;
39  ///Vector containing the inner nodes.
40  std::vector<typename Graph::Node> inner;
41  ///Vector containing the edges of the inner circle.
42  std::vector<typename Graph::Edge> incir;
43  ///Vector containing the edges of the outer circle.
44  std::vector<typename Graph::Edge> outcir;
45  ///Vector containing the chord edges.
46  std::vector<typename Graph::Edge> chords;
47};
48
49
50
51///Adds a Petersen graph to \c G.
52
53///Adds a Petersen graph to \c G.
54///\return The nodes end edges og the generated graph.
55
56template<typename Graph>
57PetStruct<Graph> addPetersen(Graph &G,int num=5)
58{
59  PetStruct<Graph> n;
60
61  for(int i=0;i<num;i++) {
62    n.outer.push_back(G.addNode());
63    n.inner.push_back(G.addNode());
64  }
65
66 for(int i=0;i<num;i++) {
67   n.chords.push_back(G.addEdge(n.outer[i],n.inner[i]));
68   n.outcir.push_back(G.addEdge(n.outer[i],n.outer[(i+1)%5]));
69   n.incir.push_back(G.addEdge(n.inner[i],n.inner[(i+2)%5]));
70  }
71 return n;
72}
73
74
75
76#endif
Note: See TracBrowser for help on using the repository browser.