1.1 --- a/test/test_tools.h Tue Mar 18 16:45:21 2008 +0100
1.2 +++ b/test/test_tools.h Thu Mar 20 12:12:24 2008 +0000
1.3 @@ -20,6 +20,17 @@
1.4 #define LEMON_TEST_TEST_TOOLS_H
1.5
1.6 #include <iostream>
1.7 +#include <vector>
1.8 +
1.9 +#include <cstdlib>
1.10 +#include <ctime>
1.11 +
1.12 +#include <lemon/concept_check.h>
1.13 +#include <lemon/concepts/digraph.h>
1.14 +
1.15 +#include <lemon/random.h>
1.16 +
1.17 +using namespace lemon;
1.18
1.19 //! \ingroup misc
1.20 //! \file
1.21 @@ -36,7 +47,7 @@
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 +///\verbatim digraph_test.cc:123: error: This is obviously false. \endverbatim
1.27 ///
1.28 ///\todo It should be in \c error.h
1.29 #define check(rc, msg) \
1.30 @@ -45,4 +56,126 @@
1.31 abort(); \
1.32 } else { } \
1.33
1.34 +///Structure returned by \ref addPetersen().
1.35 +
1.36 +///Structure returned by \ref addPetersen().
1.37 +///
1.38 +template<class Digraph> struct PetStruct
1.39 +{
1.40 + ///Vector containing the outer nodes.
1.41 + std::vector<typename Digraph::Node> outer;
1.42 + ///Vector containing the inner nodes.
1.43 + std::vector<typename Digraph::Node> inner;
1.44 + ///Vector containing the arcs of the inner circle.
1.45 + std::vector<typename Digraph::Arc> incir;
1.46 + ///Vector containing the arcs of the outer circle.
1.47 + std::vector<typename Digraph::Arc> outcir;
1.48 + ///Vector containing the chord arcs.
1.49 + std::vector<typename Digraph::Arc> chords;
1.50 +};
1.51 +
1.52 +
1.53 +
1.54 +///Adds a Petersen digraph to \c G.
1.55 +
1.56 +///Adds a Petersen digraph to \c G.
1.57 +///\return The nodes and arcs of the generated digraph.
1.58 +
1.59 +template<typename Digraph>
1.60 +PetStruct<Digraph> addPetersen(Digraph &G,int num = 5)
1.61 +{
1.62 + PetStruct<Digraph> n;
1.63 +
1.64 + for(int i=0;i<num;i++) {
1.65 + n.outer.push_back(G.addNode());
1.66 + n.inner.push_back(G.addNode());
1.67 + }
1.68 +
1.69 + for(int i=0;i<num;i++) {
1.70 + n.chords.push_back(G.addArc(n.outer[i],n.inner[i]));
1.71 + n.outcir.push_back(G.addArc(n.outer[i],n.outer[(i+1) % num]));
1.72 + n.incir.push_back(G.addArc(n.inner[i],n.inner[(i+2) % num]));
1.73 + }
1.74 + return n;
1.75 +}
1.76 +
1.77 +/// \brief Adds to the digraph the reverse pair of all arcs.
1.78 +///
1.79 +/// Adds to the digraph the reverse pair of all arcs.
1.80 +///
1.81 +template<class Digraph> void bidirDigraph(Digraph &G)
1.82 +{
1.83 + typedef typename Digraph::Arc Arc;
1.84 + typedef typename Digraph::ArcIt ArcIt;
1.85 +
1.86 + std::vector<Arc> ee;
1.87 +
1.88 + for(ArcIt e(G);e!=INVALID;++e) ee.push_back(e);
1.89 +
1.90 + for(typename std::vector<Arc>::iterator p=ee.begin();p!=ee.end();p++)
1.91 + G.addArc(G.target(*p),G.source(*p));
1.92 +}
1.93 +
1.94 +
1.95 +/// \brief Checks the bidirectioned Petersen digraph.
1.96 +///
1.97 +/// Checks the bidirectioned Petersen digraph.
1.98 +///
1.99 +template<class Digraph> void checkBidirPetersen(Digraph &G, int num = 5)
1.100 +{
1.101 + typedef typename Digraph::Node Node;
1.102 +
1.103 + typedef typename Digraph::ArcIt ArcIt;
1.104 + typedef typename Digraph::NodeIt NodeIt;
1.105 +
1.106 + checkDigraphNodeList(G, 2 * num);
1.107 + checkDigraphArcList(G, 6 * num);
1.108 +
1.109 + for(NodeIt n(G);n!=INVALID;++n) {
1.110 + checkDigraphInArcList(G, n, 3);
1.111 + checkDigraphOutArcList(G, n, 3);
1.112 + }
1.113 +}
1.114 +
1.115 +///Structure returned by \ref addUPetersen().
1.116 +
1.117 +///Structure returned by \ref addUPetersen().
1.118 +///
1.119 +template<class Digraph> struct UPetStruct
1.120 +{
1.121 + ///Vector containing the outer nodes.
1.122 + std::vector<typename Digraph::Node> outer;
1.123 + ///Vector containing the inner nodes.
1.124 + std::vector<typename Digraph::Node> inner;
1.125 + ///Vector containing the arcs of the inner circle.
1.126 + std::vector<typename Digraph::Edge> incir;
1.127 + ///Vector containing the arcs of the outer circle.
1.128 + std::vector<typename Digraph::Edge> outcir;
1.129 + ///Vector containing the chord arcs.
1.130 + std::vector<typename Digraph::Edge> chords;
1.131 +};
1.132 +
1.133 +///Adds a Petersen digraph to the undirected \c G.
1.134 +
1.135 +///Adds a Petersen digraph to the undirected \c G.
1.136 +///\return The nodes and arcs of the generated digraph.
1.137 +
1.138 +template<typename Digraph>
1.139 +UPetStruct<Digraph> addUPetersen(Digraph &G,int num=5)
1.140 +{
1.141 + UPetStruct<Digraph> n;
1.142 +
1.143 + for(int i=0;i<num;i++) {
1.144 + n.outer.push_back(G.addNode());
1.145 + n.inner.push_back(G.addNode());
1.146 + }
1.147 +
1.148 + for(int i=0;i<num;i++) {
1.149 + n.chords.push_back(G.addArc(n.outer[i],n.inner[i]));
1.150 + n.outcir.push_back(G.addArc(n.outer[i],n.outer[(i+1)%5]));
1.151 + n.incir.push_back(G.addArc(n.inner[i],n.inner[(i+2)%5]));
1.152 + }
1.153 + return n;
1.154 +}
1.155 +
1.156 #endif