Put an end to every gcc-4.0 warning.
2 * test/test_tools.h - Part of LEMON, a generic C++ optimization library
4 * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
5 * (Egervary Research Group on Combinatorial Optimization, EGRES).
7 * Permission to use, modify and distribute this software is granted
8 * provided that this copyright notice appears in all copies. For
9 * precise terms see the accompanying LICENSE file.
11 * This software is provided "AS IS" with no warranty of any kind,
12 * express or implied, and with no claim as to its suitability for any
17 #ifndef LEMON_TEST_TEST_TOOLS_H
18 #define LEMON_TEST_TEST_TOOLS_H
23 #include <lemon/invalid.h>
25 using namespace lemon;
29 //! \brief Some utilities to write test programs.
32 ///If \c rc is fail, writes an error message end exit.
34 ///If \c rc is fail, writes an error message end exit.
35 ///The error message contains the file name and the line number of the
36 ///source code in a standard from, which makes it possible to go there
37 ///using good source browsers like e.g. \c emacs.
40 ///\code check(0==1,"This is obviously false.");\endcode will
41 ///print this (and then exits).
42 ///\verbatim graph_test.cc:123: error: This is obviously false. \endverbatim
44 ///\todo It should be in \c error.h
45 #define check(rc, msg) \
47 std::cerr << __FILE__ ":" << __LINE__ << ": error: " << msg << std::endl; \
51 ///Structure returned by \ref addPetersen().
53 ///Structure returned by \ref addPetersen().
55 template<class Graph> struct PetStruct
57 ///Vector containing the outer nodes.
58 std::vector<typename Graph::Node> outer;
59 ///Vector containing the inner nodes.
60 std::vector<typename Graph::Node> inner;
61 ///Vector containing the edges of the inner circle.
62 std::vector<typename Graph::Edge> incir;
63 ///Vector containing the edges of the outer circle.
64 std::vector<typename Graph::Edge> outcir;
65 ///Vector containing the chord edges.
66 std::vector<typename Graph::Edge> chords;
71 ///Adds a Petersen graph to \c G.
73 ///Adds a Petersen graph to \c G.
74 ///\return The nodes and edges of the generated graph.
76 template<typename Graph>
77 PetStruct<Graph> addPetersen(Graph &G,int num = 5)
81 for(int i=0;i<num;i++) {
82 n.outer.push_back(G.addNode());
83 n.inner.push_back(G.addNode());
86 for(int i=0;i<num;i++) {
87 n.chords.push_back(G.addEdge(n.outer[i],n.inner[i]));
88 n.outcir.push_back(G.addEdge(n.outer[i],n.outer[(i+1) % num]));
89 n.incir.push_back(G.addEdge(n.inner[i],n.inner[(i+2) % num]));
94 /// \brief Adds to the graph the reverse pair of all edges.
96 /// Adds to the graph the reverse pair of all edges.
98 template<class Graph> void bidirGraph(Graph &G)
100 typedef typename Graph::Edge Edge;
101 typedef typename Graph::EdgeIt EdgeIt;
103 std::vector<Edge> ee;
105 for(EdgeIt e(G);e!=INVALID;++e) ee.push_back(e);
107 for(typename std::vector<Edge>::iterator p=ee.begin();p!=ee.end();p++)
108 G.addEdge(G.target(*p),G.source(*p));
112 /// \brief Checks the bidirectioned Petersen graph.
114 /// Checks the bidirectioned Petersen graph.
116 template<class Graph> void checkBidirPetersen(Graph &G, int num = 5)
118 typedef typename Graph::Node Node;
120 typedef typename Graph::EdgeIt EdgeIt;
121 typedef typename Graph::NodeIt NodeIt;
123 checkGraphNodeList(G, 2 * num);
124 checkGraphEdgeList(G, 6 * num);
126 for(NodeIt n(G);n!=INVALID;++n) {
127 checkGraphInEdgeList(G, n, 3);
128 checkGraphOutEdgeList(G, n, 3);
132 ///Structure returned by \ref addSymPetersen().
134 ///Structure returned by \ref addSymPetersen().
136 template<class Graph> struct SymPetStruct
138 ///Vector containing the outer nodes.
139 std::vector<typename Graph::Node> outer;
140 ///Vector containing the inner nodes.
141 std::vector<typename Graph::Node> inner;
142 ///Vector containing the edges of the inner circle.
143 std::vector<typename Graph::SymEdge> incir;
144 ///Vector containing the edges of the outer circle.
145 std::vector<typename Graph::SymEdge> outcir;
146 ///Vector containing the chord edges.
147 std::vector<typename Graph::SymEdge> chords;
150 ///Adds a Petersen graph to the symmetric \c G.
152 ///Adds a Petersen graph to the symmetric \c G.
153 ///\return The nodes and edges of the generated graph.
155 template<typename Graph>
156 SymPetStruct<Graph> addSymPetersen(Graph &G,int num=5)
158 SymPetStruct<Graph> n;
160 for(int i=0;i<num;i++) {
161 n.outer.push_back(G.addNode());
162 n.inner.push_back(G.addNode());
165 for(int i=0;i<num;i++) {
166 n.chords.push_back(G.addEdge(n.outer[i],n.inner[i]));
167 n.outcir.push_back(G.addEdge(n.outer[i],n.outer[(i+1)%5]));
168 n.incir.push_back(G.addEdge(n.inner[i],n.inner[(i+2)%5]));