1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/test/test_tools.h Fri May 07 10:22:30 2004 +0000
1.3 @@ -0,0 +1,64 @@
1.4 +#ifndef HUGO_TEST_TEST_TOOLS_H
1.5 +#define HUGO_TEST_TEST_TOOLS_H
1.6 +
1.7 +//! \ingroup misc
1.8 +//! \file
1.9 +//! \brief Some utility to write test programs.
1.10 +
1.11 +
1.12 +#include<iostream>
1.13 +#include<vector>
1.14 +
1.15 +//If \c rc is fail, writes an error message end exit.
1.16 +
1.17 +///If \c rc is fail, writes an error message end exit.
1.18 +///The error message contains the file name and the line number of the
1.19 +///source code is a standard from, which makes it possible to go there
1.20 +///using good source browsers like e.g. \c emacs.
1.21 +///
1.22 +///For example
1.23 +///\code check(0==1,"This is obviously false.");\endcode will
1.24 +///print this (and then exits).
1.25 +///\verbatim graph_test.cc:123: error: This is obviously false. \endverbatim
1.26 +#define check(rc, msg) \
1.27 + if(!(rc)) { \
1.28 + std::cerr << __FILE__ ":" << __LINE__ << ": error: " << msg << std::endl; \
1.29 + exit(1); \
1.30 + } else { } \
1.31 +
1.32 +///Structure returned by \ref addPetersen().
1.33 +
1.34 +///Structure returned by \ref addPetersen().
1.35 +///
1.36 +template<class Graph> struct PetStruct
1.37 +{
1.38 + ///.
1.39 + std::vector<typename Graph::Node> outer, inner;
1.40 + ///.
1.41 + std::vector<typename Graph::Edge> outcir, incir, chords;
1.42 +};
1.43 +
1.44 +///Adds a Petersen graph to \c G.
1.45 +
1.46 +///Adds a Petersen graph to \c G.
1.47 +///The nodes end edges will be listed in the return structure.
1.48 +template<class Graph> PetStruct<Graph> addPetersen(Graph &G,int num=5)
1.49 +{
1.50 + PetStruct<Graph> n;
1.51 +
1.52 + for(int i=0;i<num;i++) {
1.53 + n.outer.push_back(G.addNode());
1.54 + n.inner.push_back(G.addNode());
1.55 + }
1.56 +
1.57 + for(int i=0;i<num;i++) {
1.58 + n.chords.push_back(G.addEdge(n.outer[i],n.inner[i]));
1.59 + n.outcir.push_back(G.addEdge(n.outer[i],n.outer[(i+1)%5]));
1.60 + n.incir.push_back(G.addEdge(n.inner[i],n.inner[(i+2)%5]));
1.61 + }
1.62 + return n;
1.63 +}
1.64 +
1.65 +
1.66 +
1.67 +#endif