[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 | |
---|
| 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 is 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 | #define check(rc, msg) \ |
---|
| 24 | if(!(rc)) { \ |
---|
| 25 | std::cerr << __FILE__ ":" << __LINE__ << ": error: " << msg << std::endl; \ |
---|
| 26 | exit(1); \ |
---|
| 27 | } else { } \ |
---|
| 28 | |
---|
| 29 | ///Structure returned by \ref addPetersen(). |
---|
| 30 | |
---|
| 31 | ///Structure returned by \ref addPetersen(). |
---|
| 32 | /// |
---|
| 33 | template<class Graph> struct PetStruct |
---|
| 34 | { |
---|
| 35 | ///. |
---|
| 36 | std::vector<typename Graph::Node> outer, inner; |
---|
| 37 | ///. |
---|
| 38 | std::vector<typename Graph::Edge> outcir, incir, chords; |
---|
| 39 | }; |
---|
| 40 | |
---|
| 41 | ///Adds a Petersen graph to \c G. |
---|
| 42 | |
---|
| 43 | ///Adds a Petersen graph to \c G. |
---|
| 44 | ///The nodes end edges will be listed in the return structure. |
---|
| 45 | template<class Graph> PetStruct<Graph> addPetersen(Graph &G,int num=5) |
---|
| 46 | { |
---|
| 47 | PetStruct<Graph> n; |
---|
| 48 | |
---|
| 49 | for(int i=0;i<num;i++) { |
---|
| 50 | n.outer.push_back(G.addNode()); |
---|
| 51 | n.inner.push_back(G.addNode()); |
---|
| 52 | } |
---|
| 53 | |
---|
| 54 | for(int i=0;i<num;i++) { |
---|
| 55 | n.chords.push_back(G.addEdge(n.outer[i],n.inner[i])); |
---|
| 56 | n.outcir.push_back(G.addEdge(n.outer[i],n.outer[(i+1)%5])); |
---|
| 57 | n.incir.push_back(G.addEdge(n.inner[i],n.inner[(i+2)%5])); |
---|
| 58 | } |
---|
| 59 | return n; |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | |
---|
| 63 | |
---|
| 64 | #endif |
---|