Improved LEMON_FUNCTION_NAME macro.
It should work fine with GCC and the MS C++ compilers. Otherwise it reverts to
using the __func__ variable which is C99, but I couldn't find a better
alternative.
3 * This file is a part of LEMON, a generic C++ optimization library
5 * Copyright (C) 2003-2008
6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 * (Egervary Research Group on Combinatorial Optimization, EGRES).
9 * Permission to use, modify and distribute this software is granted
10 * provided that this copyright notice appears in all copies. For
11 * precise terms see the accompanying LICENSE file.
13 * This software is provided "AS IS" with no warranty of any kind,
14 * express or implied, and with no claim as to its suitability for any
19 #ifndef LEMON_TEST_TEST_TOOLS_H
20 #define LEMON_TEST_TEST_TOOLS_H
28 #include <lemon/concept_check.h>
29 #include <lemon/concepts/digraph.h>
31 #include <lemon/random.h>
33 using namespace lemon;
37 //! \brief Some utilities to write test programs.
40 ///If \c rc is fail, writes an error message end exit.
42 ///If \c rc is fail, writes an error message end exit.
43 ///The error message contains the file name and the line number of the
44 ///source code in a standard from, which makes it possible to go there
45 ///using good source browsers like e.g. \c emacs.
48 ///\code check(0==1,"This is obviously false.");\endcode will
49 ///print this (and then exits).
50 ///\verbatim digraph_test.cc:123: error: This is obviously false. \endverbatim
52 ///\todo It should be in \c error.h
53 #define check(rc, msg) \
55 std::cerr << __FILE__ ":" << __LINE__ << ": error: " << msg << std::endl; \
59 ///Structure returned by \ref addPetersen().
61 ///Structure returned by \ref addPetersen().
63 template<class Digraph> struct PetStruct
65 ///Vector containing the outer nodes.
66 std::vector<typename Digraph::Node> outer;
67 ///Vector containing the inner nodes.
68 std::vector<typename Digraph::Node> inner;
69 ///Vector containing the arcs of the inner circle.
70 std::vector<typename Digraph::Arc> incir;
71 ///Vector containing the arcs of the outer circle.
72 std::vector<typename Digraph::Arc> outcir;
73 ///Vector containing the chord arcs.
74 std::vector<typename Digraph::Arc> chords;
79 ///Adds a Petersen digraph to \c G.
81 ///Adds a Petersen digraph to \c G.
82 ///\return The nodes and arcs of the generated digraph.
84 template<typename Digraph>
85 PetStruct<Digraph> addPetersen(Digraph &G,int num = 5)
89 for(int i=0;i<num;i++) {
90 n.outer.push_back(G.addNode());
91 n.inner.push_back(G.addNode());
94 for(int i=0;i<num;i++) {
95 n.chords.push_back(G.addArc(n.outer[i],n.inner[i]));
96 n.outcir.push_back(G.addArc(n.outer[i],n.outer[(i+1) % num]));
97 n.incir.push_back(G.addArc(n.inner[i],n.inner[(i+2) % num]));
102 /// \brief Adds to the digraph the reverse pair of all arcs.
104 /// Adds to the digraph the reverse pair of all arcs.
106 template<class Digraph> void bidirDigraph(Digraph &G)
108 typedef typename Digraph::Arc Arc;
109 typedef typename Digraph::ArcIt ArcIt;
113 for(ArcIt e(G);e!=INVALID;++e) ee.push_back(e);
115 for(typename std::vector<Arc>::iterator p=ee.begin();p!=ee.end();p++)
116 G.addArc(G.target(*p),G.source(*p));
120 /// \brief Checks the bidirectioned Petersen digraph.
122 /// Checks the bidirectioned Petersen digraph.
124 template<class Digraph> void checkBidirPetersen(Digraph &G, int num = 5)
126 typedef typename Digraph::Node Node;
128 typedef typename Digraph::ArcIt ArcIt;
129 typedef typename Digraph::NodeIt NodeIt;
131 checkDigraphNodeList(G, 2 * num);
132 checkDigraphArcList(G, 6 * num);
134 for(NodeIt n(G);n!=INVALID;++n) {
135 checkDigraphInArcList(G, n, 3);
136 checkDigraphOutArcList(G, n, 3);
140 ///Structure returned by \ref addUPetersen().
142 ///Structure returned by \ref addUPetersen().
144 template<class Digraph> struct UPetStruct
146 ///Vector containing the outer nodes.
147 std::vector<typename Digraph::Node> outer;
148 ///Vector containing the inner nodes.
149 std::vector<typename Digraph::Node> inner;
150 ///Vector containing the arcs of the inner circle.
151 std::vector<typename Digraph::Edge> incir;
152 ///Vector containing the arcs of the outer circle.
153 std::vector<typename Digraph::Edge> outcir;
154 ///Vector containing the chord arcs.
155 std::vector<typename Digraph::Edge> chords;
158 ///Adds a Petersen digraph to the undirected \c G.
160 ///Adds a Petersen digraph to the undirected \c G.
161 ///\return The nodes and arcs of the generated digraph.
163 template<typename Digraph>
164 UPetStruct<Digraph> addUPetersen(Digraph &G,int num=5)
166 UPetStruct<Digraph> n;
168 for(int i=0;i<num;i++) {
169 n.outer.push_back(G.addNode());
170 n.inner.push_back(G.addNode());
173 for(int i=0;i<num;i++) {
174 n.chords.push_back(G.addArc(n.outer[i],n.inner[i]));
175 n.outcir.push_back(G.addArc(n.outer[i],n.outer[(i+1)%5]));
176 n.incir.push_back(G.addArc(n.inner[i],n.inner[(i+2)%5]));