| 1 | // -*- c++ -*- |
|---|
| 2 | #ifndef HUGO_TEST_TEST_TOOLS_H |
|---|
| 3 | #define HUGO_TEST_TEST_TOOLS_H |
|---|
| 4 | |
|---|
| 5 | //! \ingroup misc |
|---|
| 6 | //! \file |
|---|
| 7 | //! \brief Some utility to write test programs. |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | #include<iostream> |
|---|
| 11 | #include<vector> |
|---|
| 12 | |
|---|
| 13 | ///If \c rc is fail, writes an error message end exit. |
|---|
| 14 | |
|---|
| 15 | ///If \c rc is fail, writes an error message end exit. |
|---|
| 16 | ///The error message contains the file name and the line number of the |
|---|
| 17 | ///source code in a standard from, which makes it possible to go there |
|---|
| 18 | ///using good source browsers like e.g. \c emacs. |
|---|
| 19 | /// |
|---|
| 20 | ///For example |
|---|
| 21 | ///\code check(0==1,"This is obviously false.");\endcode will |
|---|
| 22 | ///print this (and then exits). |
|---|
| 23 | ///\verbatim graph_test.cc:123: error: This is obviously false. \endverbatim |
|---|
| 24 | /// |
|---|
| 25 | ///\todo It should be in \c error.h |
|---|
| 26 | #define check(rc, msg) \ |
|---|
| 27 | if(!(rc)) { \ |
|---|
| 28 | std::cerr << __FILE__ ":" << __LINE__ << ": error: " << msg << std::endl; \ |
|---|
| 29 | exit(1); \ |
|---|
| 30 | } else { } \ |
|---|
| 31 | |
|---|
| 32 | ///Structure returned by \ref addPetersen(). |
|---|
| 33 | |
|---|
| 34 | ///Structure returned by \ref addPetersen(). |
|---|
| 35 | /// |
|---|
| 36 | template<class Graph> struct PetStruct |
|---|
| 37 | { |
|---|
| 38 | ///Vector containing the outer nodes. |
|---|
| 39 | std::vector<typename Graph::Node> outer; |
|---|
| 40 | ///Vector containing the inner nodes. |
|---|
| 41 | std::vector<typename Graph::Node> inner; |
|---|
| 42 | ///Vector containing the edges of the inner circle. |
|---|
| 43 | std::vector<typename Graph::Edge> incir; |
|---|
| 44 | ///Vector containing the edges of the outer circle. |
|---|
| 45 | std::vector<typename Graph::Edge> outcir; |
|---|
| 46 | ///Vector containing the chord edges. |
|---|
| 47 | std::vector<typename Graph::Edge> chords; |
|---|
| 48 | }; |
|---|
| 49 | |
|---|
| 50 | |
|---|
| 51 | |
|---|
| 52 | ///Adds a Petersen graph to \c G. |
|---|
| 53 | |
|---|
| 54 | ///Adds a Petersen graph to \c G. |
|---|
| 55 | ///\return The nodes end edges og the generated graph. |
|---|
| 56 | |
|---|
| 57 | template<typename Graph> |
|---|
| 58 | PetStruct<Graph> addPetersen(Graph &G,int num=5) |
|---|
| 59 | { |
|---|
| 60 | PetStruct<Graph> n; |
|---|
| 61 | |
|---|
| 62 | for(int i=0;i<num;i++) { |
|---|
| 63 | n.outer.push_back(G.addNode()); |
|---|
| 64 | n.inner.push_back(G.addNode()); |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | for(int i=0;i<num;i++) { |
|---|
| 68 | n.chords.push_back(G.addEdge(n.outer[i],n.inner[i])); |
|---|
| 69 | n.outcir.push_back(G.addEdge(n.outer[i],n.outer[(i+1)%5])); |
|---|
| 70 | n.incir.push_back(G.addEdge(n.inner[i],n.inner[(i+2)%5])); |
|---|
| 71 | } |
|---|
| 72 | return n; |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | |
|---|
| 77 | #endif |
|---|