The first version of new path test program. The old became old_path_test.
1.1 --- a/src/hugo/path.h Sun Sep 12 19:32:21 2004 +0000
1.2 +++ b/src/hugo/path.h Sun Sep 12 21:46:26 2004 +0000
1.3 @@ -29,7 +29,7 @@
1.4
1.5 #include <hugo/invalid.h>
1.6 #include <hugo/error.h>
1.7 -#include <hugo/debug.h>
1.8 +//#include <hugo/debug.h>
1.9
1.10 namespace hugo {
1.11
1.12 @@ -48,7 +48,7 @@
1.13 //! and \c Edge of the original graph.
1.14 //!
1.15 //! \todo Thoroughfully check all the range and consistency tests.
1.16 - template<typename Graph, typename DM = DefaultDebugMode>
1.17 + template<typename Graph>
1.18 class DirPath {
1.19 public:
1.20 /// Edge type of the underlying graph.
1.21 @@ -74,7 +74,7 @@
1.22 /// Subpath defined by two nodes.
1.23 /// \warning It is an error if the two edges are not in order!
1.24 DirPath(const DirPath &P, const NodeIt &a, const NodeIt &b) {
1.25 - if( DM::range_check && (!a.valid() || !b.valid) ) {
1.26 + if(!a.valid() || !b.valid) {
1.27 // FIXME: this check should be more elaborate...
1.28 fault("DirPath, subpath ctor: invalid bounding nodes");
1.29 }
1.30 @@ -87,7 +87,7 @@
1.31 /// Subpath defined by two edges. Contains edges in [a,b)
1.32 /// \warning It is an error if the two edges are not in order!
1.33 DirPath(const DirPath &P, const EdgeIt &a, const EdgeIt &b) {
1.34 - if( DM::range_check && (!a.valid() || !b.valid) ) {
1.35 + if (!a.valid() || !b.valid) {
1.36 // FIXME: this check should be more elaborate...
1.37 fault("DirPath, subpath ctor: invalid bounding nodes");
1.38 }
1.39 @@ -107,14 +107,14 @@
1.40 ///
1.41 /// Starting point of the path.
1.42 /// Returns INVALID if the path is empty.
1.43 - GraphNode from() const {
1.44 + GraphNode tail() const {
1.45 return empty() ? INVALID : gr->tail(edges[0]);
1.46 }
1.47 /// \brief End point of the path.
1.48 ///
1.49 /// End point of the path.
1.50 /// Returns INVALID if the path is empty.
1.51 - GraphNode to() const {
1.52 + GraphNode head() const {
1.53 return empty() ? INVALID : gr->head(edges[length()-1]);
1.54 }
1.55
1.56 @@ -127,14 +127,14 @@
1.57
1.58 /// \brief Initializes node iterator to point to the node of a given index.
1.59 NodeIt& nth(NodeIt &i, int n) const {
1.60 - if( DM::range_check && (n<0 || n>int(length())) )
1.61 + if(n<0 || n>int(length()))
1.62 fault("DirPath::nth: index out of range");
1.63 return i=NodeIt(*this, n);
1.64 }
1.65
1.66 /// \brief Initializes edge iterator to point to the edge of a given index.
1.67 EdgeIt& nth(EdgeIt &i, int n) const {
1.68 - if( DM::range_check && (n<0 || n>=int(length())) )
1.69 + if(n<0 || n>=int(length()))
1.70 fault("DirPath::nth: index out of range");
1.71 return i=EdgeIt(*this, n);
1.72 }
1.73 @@ -148,7 +148,7 @@
1.74 template<typename It>
1.75 static
1.76 It& next(It &e) {
1.77 - if( DM::range_check && !e.valid() )
1.78 + if( !e.valid() )
1.79 fault("DirPath::next() on invalid iterator");
1.80 return ++e;
1.81 }
1.82 @@ -156,7 +156,7 @@
1.83 /// \brief Returns node iterator pointing to the head node of the
1.84 /// given edge iterator.
1.85 NodeIt head(const EdgeIt& e) const {
1.86 - if( DM::range_check && !e.valid() )
1.87 + if( !e.valid() )
1.88 fault("DirPath::head() on invalid iterator");
1.89 return NodeIt(*this, e.idx+1);
1.90 }
1.91 @@ -164,7 +164,7 @@
1.92 /// \brief Returns node iterator pointing to the tail node of the
1.93 /// given edge iterator.
1.94 NodeIt tail(const EdgeIt& e) const {
1.95 - if( DM::range_check && !e.valid() )
1.96 + if( !e.valid() )
1.97 fault("DirPath::tail() on invalid iterator");
1.98 return NodeIt(*this, e.idx);
1.99 }
1.100 @@ -252,7 +252,7 @@
1.101 ///Conversion to Graph::Node
1.102 operator const GraphNode& () const {
1.103 if(idx >= p->length())
1.104 - return p->to();
1.105 + return p->head();
1.106 else if(idx >= 0)
1.107 return p->gr->tail(p->edges[idx]);
1.108 else
1.109 @@ -312,7 +312,7 @@
1.110 ///Push a new edge to the front of the path.
1.111 ///\sa setStartNode
1.112 void pushFront(const GraphEdge& e) {
1.113 - if( DM::consistensy_check && !empty() && P.gr->head(e)!=from() ) {
1.114 + if( !empty() && P.gr->head(e)!=tail() ) {
1.115 fault("DirPath::Builder::pushFront: nonincident edge");
1.116 }
1.117 front.push_back(e);
1.118 @@ -323,7 +323,7 @@
1.119 ///Push a new edge to the back of the path.
1.120 ///\sa setStartNode
1.121 void pushBack(const GraphEdge& e) {
1.122 - if( DM::consistensy_check && !empty() && P.gr->tail(e)!=to() ) {
1.123 + if( !empty() && P.gr->tail(e)!=head() ) {
1.124 fault("DirPath::Builder::pushBack: nonincident edge");
1.125 }
1.126 back.push_back(e);
1.127 @@ -355,12 +355,15 @@
1.128 back.reserve(r);
1.129 }
1.130
1.131 + void reserveFront(size_t r) {}
1.132 + void reserveBack(size_t r) {}
1.133 +
1.134 private:
1.135 bool empty() {
1.136 return front.empty() && back.empty() && P.empty();
1.137 }
1.138
1.139 - GraphNode from() const {
1.140 + GraphNode tail() const {
1.141 if( ! front.empty() )
1.142 return P.gr->tail(front[front.size()-1]);
1.143 else if( ! P.empty() )
1.144 @@ -370,7 +373,7 @@
1.145 else
1.146 return INVALID;
1.147 }
1.148 - GraphNode to() const {
1.149 + GraphNode head() const {
1.150 if( ! back.empty() )
1.151 return P.gr->head(back[back.size()-1]);
1.152 else if( ! P.empty() )
1.153 @@ -411,7 +414,7 @@
1.154 //! and \c Edge of the original graph.
1.155 //!
1.156 //! \todo Thoroughfully check all the range and consistency tests.
1.157 - template<typename Graph, typename DM = DefaultDebugMode>
1.158 + template<typename Graph>
1.159 class UndirPath {
1.160 public:
1.161 /// Edge type of the underlying graph.
1.162 @@ -437,7 +440,7 @@
1.163 /// Subpath defined by two nodes.
1.164 /// \warning It is an error if the two edges are not in order!
1.165 UndirPath(const UndirPath &P, const NodeIt &a, const NodeIt &b) {
1.166 - if( DM::range_check && (!a.valid() || !b.valid) ) {
1.167 + if(!a.valid() || !b.valid) {
1.168 // FIXME: this check should be more elaborate...
1.169 fault("UndirPath, subpath ctor: invalid bounding nodes");
1.170 }
1.171 @@ -450,7 +453,7 @@
1.172 /// Subpath defined by two edges. Contains edges in [a,b)
1.173 /// \warning It is an error if the two edges are not in order!
1.174 UndirPath(const UndirPath &P, const EdgeIt &a, const EdgeIt &b) {
1.175 - if( DM::range_check && (!a.valid() || !b.valid) ) {
1.176 + if(!a.valid() || !b.valid) {
1.177 // FIXME: this check should be more elaborate...
1.178 fault("UndirPath, subpath ctor: invalid bounding nodes");
1.179 }
1.180 @@ -470,14 +473,14 @@
1.181 ///
1.182 /// Starting point of the path.
1.183 /// Returns INVALID if the path is empty.
1.184 - GraphNode from() const {
1.185 + GraphNode tail() const {
1.186 return empty() ? INVALID : gr->tail(edges[0]);
1.187 }
1.188 /// \brief End point of the path.
1.189 ///
1.190 /// End point of the path.
1.191 /// Returns INVALID if the path is empty.
1.192 - GraphNode to() const {
1.193 + GraphNode head() const {
1.194 return empty() ? INVALID : gr->head(edges[length()-1]);
1.195 }
1.196
1.197 @@ -490,14 +493,14 @@
1.198
1.199 /// \brief Initializes node iterator to point to the node of a given index.
1.200 NodeIt& nth(NodeIt &i, int n) const {
1.201 - if( DM::range_check && (n<0 || n>int(length())) )
1.202 + if(n<0 || n>int(length()))
1.203 fault("UndirPath::nth: index out of range");
1.204 return i=NodeIt(*this, n);
1.205 }
1.206
1.207 /// \brief Initializes edge iterator to point to the edge of a given index.
1.208 EdgeIt& nth(EdgeIt &i, int n) const {
1.209 - if( DM::range_check && (n<0 || n>=int(length())) )
1.210 + if(n<0 || n>=int(length()))
1.211 fault("UndirPath::nth: index out of range");
1.212 return i=EdgeIt(*this, n);
1.213 }
1.214 @@ -511,7 +514,7 @@
1.215 template<typename It>
1.216 static
1.217 It& next(It &e) {
1.218 - if( DM::range_check && !e.valid() )
1.219 + if( !e.valid() )
1.220 fault("UndirPath::next() on invalid iterator");
1.221 return ++e;
1.222 }
1.223 @@ -519,7 +522,7 @@
1.224 /// \brief Returns node iterator pointing to the head node of the
1.225 /// given edge iterator.
1.226 NodeIt head(const EdgeIt& e) const {
1.227 - if( DM::range_check && !e.valid() )
1.228 + if( !e.valid() )
1.229 fault("UndirPath::head() on invalid iterator");
1.230 return NodeIt(*this, e.idx+1);
1.231 }
1.232 @@ -527,7 +530,7 @@
1.233 /// \brief Returns node iterator pointing to the tail node of the
1.234 /// given edge iterator.
1.235 NodeIt tail(const EdgeIt& e) const {
1.236 - if( DM::range_check && !e.valid() )
1.237 + if( !e.valid() )
1.238 fault("UndirPath::tail() on invalid iterator");
1.239 return NodeIt(*this, e.idx);
1.240 }
1.241 @@ -613,7 +616,7 @@
1.242 ///Conversion to Graph::Node
1.243 operator const GraphNode& () const {
1.244 if(idx >= p->length())
1.245 - return p->to();
1.246 + return p->head();
1.247 else if(idx >= 0)
1.248 return p->gr->tail(p->edges[idx]);
1.249 else
1.250 @@ -673,7 +676,7 @@
1.251 ///Push a new edge to the front of the path.
1.252 ///\sa setStartNode
1.253 void pushFront(const GraphEdge& e) {
1.254 - if( DM::consistensy_check && !empty() && P.gr->head(e)!=from() ) {
1.255 + if( !empty() && P.gr->head(e)!=tail() ) {
1.256 fault("UndirPath::Builder::pushFront: nonincident edge");
1.257 }
1.258 front.push_back(e);
1.259 @@ -684,7 +687,7 @@
1.260 ///Push a new edge to the back of the path.
1.261 ///\sa setStartNode
1.262 void pushBack(const GraphEdge& e) {
1.263 - if( DM::consistensy_check && !empty() && P.gr->tail(e)!=to() ) {
1.264 + if( !empty() && P.gr->tail(e)!=head() ) {
1.265 fault("UndirPath::Builder::pushBack: nonincident edge");
1.266 }
1.267 back.push_back(e);
1.268 @@ -716,12 +719,15 @@
1.269 back.reserve(r);
1.270 }
1.271
1.272 + void reserveFront(size_t r) {}
1.273 + void reserveBack(size_t r) {}
1.274 +
1.275 private:
1.276 bool empty() {
1.277 return front.empty() && back.empty() && P.empty();
1.278 }
1.279
1.280 - GraphNode from() const {
1.281 + GraphNode tail() const {
1.282 if( ! front.empty() )
1.283 return P.gr->tail(front[front.size()-1]);
1.284 else if( ! P.empty() )
1.285 @@ -731,7 +737,7 @@
1.286 else
1.287 return INVALID;
1.288 }
1.289 - GraphNode to() const {
1.290 + GraphNode head() const {
1.291 if( ! back.empty() )
1.292 return P.gr->head(back[back.size()-1]);
1.293 else if( ! P.empty() )
1.294 @@ -791,8 +797,8 @@
1.295 DynamicPath(const DynamicPath &P, const EdgeIt &a, const EdgeIt &b);
1.296
1.297 size_t length() const { return edges.size(); }
1.298 - GraphNode from() const { return _first; }
1.299 - GraphNode to() const { return _last; }
1.300 + GraphNode tail() const { return _first; }
1.301 + GraphNode head() const { return _last; }
1.302
1.303 NodeIt& first(NodeIt &n) const { return nth(n, 0); }
1.304 EdgeIt& first(EdgeIt &e) const { return nth(e, 0); }
2.1 --- a/src/hugo/skeletons/path.h Sun Sep 12 19:32:21 2004 +0000
2.2 +++ b/src/hugo/skeletons/path.h Sun Sep 12 21:46:26 2004 +0000
2.3 @@ -1,12 +1,11 @@
2.4 -#define SKELETON
2.5 // -*- c++ -*- //
2.6
2.7 ///\ingroup skeletons
2.8 ///\file
2.9 ///\brief Classes for representing paths in graphs.
2.10
2.11 -#ifndef HUGO_PATH_H
2.12 -#define HUGO_PATH_H
2.13 +#ifndef HUGO_SKELETON_PATH_H
2.14 +#define HUGO_SKELETON_PATH_H
2.15
2.16 #include <hugo/invalid.h>
2.17
2.18 @@ -14,38 +13,38 @@
2.19 namespace skeleton {
2.20 /// \addtogroup skeletons
2.21 /// @{
2.22 -
2.23 -
2.24 +
2.25 +
2.26 //! \brief A skeletom structure for representing directed paths in a graph.
2.27 //!
2.28 //! A skeleton structure for representing directed paths in a graph.
2.29 //! \param GR The graph type in which the path is.
2.30 - //!
2.31 + //!
2.32 //! In a sense, the path can be treated as a graph, for is has \c NodeIt
2.33 //! and \c EdgeIt with the same usage. These types converts to the \c Node
2.34 //! and \c Edge of the original graph.
2.35 template<typename GR>
2.36 class Path {
2.37 public:
2.38 -
2.39 +
2.40 /// Type of the underlying graph.
2.41 typedef /*typename*/ GR Graph;
2.42 /// Edge type of the underlying graph.
2.43 - typedef typename Graph::Edge GraphEdge;
2.44 + typedef typename Graph::Edge GraphEdge;
2.45 /// Node type of the underlying graph.
2.46 typedef typename Graph::Node GraphNode;
2.47 class NodeIt;
2.48 class EdgeIt;
2.49 -
2.50 +
2.51 /// \param _G The graph in which the path is.
2.52 ///
2.53 Path(const Graph &_G) {}
2.54 -
2.55 +
2.56 /// Length of the path.
2.57 size_t length() const {return 0;}
2.58 /// Returns whether the path is empty.
2.59 - bool empty() const {}
2.60 -
2.61 + bool empty() const { return true;}
2.62 +
2.63 /// Resets the path to an empty path.
2.64 void clear() {}
2.65
2.66 @@ -71,25 +70,25 @@
2.67 ///
2.68 /// Returns node iterator pointing to the head node of the
2.69 /// given edge iterator.
2.70 - NodeIt head(const EdgeIt& e) const {}
2.71 + NodeIt head(const EdgeIt& e) const {return INVALID;}
2.72
2.73 /// \brief The tail of an edge.
2.74 ///
2.75 /// Returns node iterator pointing to the tail node of the
2.76 /// given edge iterator.
2.77 - NodeIt tail(const EdgeIt& e) const {}
2.78 + NodeIt tail(const EdgeIt& e) const {return INVALID;}
2.79
2.80
2.81 /* Iterator classes */
2.82
2.83 /**
2.84 * \brief Iterator class to iterate on the edges of the paths
2.85 - *
2.86 + *
2.87 * \ingroup skeletons
2.88 * This class is used to iterate on the edges of the paths
2.89 *
2.90 * Of course it converts to Graph::Edge
2.91 - *
2.92 + *
2.93 */
2.94 class EdgeIt {
2.95 public:
2.96 @@ -103,7 +102,7 @@
2.97 operator GraphEdge () const {}
2.98
2.99 /// Next edge
2.100 - EdgeIt& operator++() {}
2.101 + EdgeIt& operator++() {return *this;}
2.102
2.103 /// Comparison operator
2.104 bool operator==(const EdgeIt& e) const {return true;}
2.105 @@ -117,12 +116,12 @@
2.106
2.107 /**
2.108 * \brief Iterator class to iterate on the nodes of the paths
2.109 - *
2.110 + *
2.111 * \ingroup skeletons
2.112 * This class is used to iterate on the nodes of the paths
2.113 *
2.114 * Of course it converts to Graph::Node.
2.115 - *
2.116 + *
2.117 */
2.118 class NodeIt {
2.119 public:
2.120 @@ -136,23 +135,23 @@
2.121 ///Conversion to Graph::Node
2.122 operator const GraphNode& () const {}
2.123 /// Next node
2.124 - NodeIt& operator++() {}
2.125 + NodeIt& operator++() {return *this;}
2.126
2.127 /// Comparison operator
2.128 - bool operator==(const NodeIt& e) const {}
2.129 + bool operator==(const NodeIt& e) const {return true;}
2.130 /// Comparison operator
2.131 - bool operator!=(const NodeIt& e) const {}
2.132 + bool operator!=(const NodeIt& e) const {return true;}
2.133 // /// Comparison operator
2.134 // /// \todo It is not clear what is the "natural" ordering.
2.135 // bool operator<(const NodeIt& e) const {}
2.136
2.137 };
2.138
2.139 - friend class Builder;
2.140 + friend class Builder;
2.141
2.142 /**
2.143 * \brief Class to build paths
2.144 - *
2.145 + *
2.146 * \ingroup skeletons
2.147 * This class is used to fill a path with edges.
2.148 *
2.149 @@ -174,7 +173,7 @@
2.150 Builder(Path &_P) : P(_P) {}
2.151
2.152 /// Sets the starting node of the path.
2.153 -
2.154 +
2.155 /// Sets the starting node of the path. Edge added to the path
2.156 /// afterwards have to be incident to this node.
2.157 /// You \em must start building an empry path with this functions.
2.158 @@ -217,7 +216,7 @@
2.159
2.160 ///@}
2.161 }
2.162 -
2.163 +
2.164 } // namespace hugo
2.165
2.166 -#endif // HUGO_PATH_H
2.167 +#endif // HUGO_SKELETON_PATH_H
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/src/test/old_path_test.cc Sun Sep 12 21:46:26 2004 +0000
3.3 @@ -0,0 +1,175 @@
3.4 +#include <string>
3.5 +#include <iostream>
3.6 +//#include <hugo/skeletons/path.h>
3.7 +#include <hugo/path.h>
3.8 +#include <hugo/list_graph.h>
3.9 +
3.10 +using namespace std;
3.11 +using namespace hugo;
3.12 +#ifdef HUGO_SKELETON_PATH_H
3.13 +using namespace skeleton;
3.14 +#endif
3.15 +
3.16 +bool passed = true;
3.17 +
3.18 +void check(bool rc) {
3.19 + passed = passed && rc;
3.20 + if(!rc) {
3.21 + cout << "Test failed!" << endl;
3.22 + }
3.23 +}
3.24 +
3.25 +#ifdef DEBUG
3.26 +const bool debug = true;
3.27 +#else
3.28 +const bool debug = false;
3.29 +#endif
3.30 +
3.31 +
3.32 +int main() {
3.33 +
3.34 + try {
3.35 +
3.36 + typedef ListGraph::Node Node;
3.37 + typedef ListGraph::Edge Edge;
3.38 +
3.39 + ListGraph G;
3.40 +
3.41 + Node s=G.addNode();
3.42 + Node v1=G.addNode();
3.43 + Node v2=G.addNode();
3.44 + Node v3=G.addNode();
3.45 + Node v4=G.addNode();
3.46 + Node t=G.addNode();
3.47 +
3.48 + Edge e1 = G.addEdge(s, v1);
3.49 + Edge e2 = G.addEdge(s, v2);
3.50 + Edge e3 = G.addEdge(v1, v2);
3.51 + Edge e4 = G.addEdge(v2, v1);
3.52 + Edge e5 = G.addEdge(v1, v3);
3.53 + Edge e6 = G.addEdge(v3, v2);
3.54 + Edge e7 = G.addEdge(v2, v4);
3.55 + Edge e8 = G.addEdge(v4, v3);
3.56 + Edge e9 = G.addEdge(v3, t);
3.57 + Edge e10 = G.addEdge(v4, t);
3.58 +
3.59 +#ifdef DEBUG
3.60 + bool rc;
3.61 +#endif
3.62 +
3.63 + {
3.64 + cout << "\n\n\nDirPath tesztelese...\n";
3.65 +
3.66 +
3.67 + cout << "Ures path letrehozasa" << endl;
3.68 +
3.69 +#ifndef HUGO_SKELETON_PATH_H
3.70 + typedef DirPath<ListGraph> DPath;
3.71 +#else
3.72 + typedef Path<ListGraph> DPath;
3.73 +#endif
3.74 +
3.75 + DPath P(G);
3.76 +
3.77 + cout << "P.length() == " << P.length() << endl;
3.78 + check(P.length() == 0);
3.79 +
3.80 + cout << "P.tail() valid? " << (P.tail()!=INVALID) << endl;
3.81 + check(! (P.tail()!=INVALID));
3.82 + {
3.83 + cout << "Builder objektum letrehozasa" << endl;
3.84 + DPath::Builder B(P);
3.85 +
3.86 + cout << "Hozzaadunk az elejehez ket elet..." << endl;
3.87 + B.pushFront(e6);
3.88 + B.pushFront(e5);
3.89 + cout << "P.length() == " << P.length() << endl;
3.90 + check(P.length() == 0);
3.91 +
3.92 + cout << "Commitolunk..." << endl;
3.93 + B.commit();
3.94 +
3.95 + cout << "P.length() == " << P.length() << endl;
3.96 + check(P.length() == 2);
3.97 +
3.98 + cout << "P.tail() valid? " << (P.tail()!=INVALID) << endl;
3.99 + check(P.tail()!=INVALID);
3.100 + cout << "P.tail()==v1 ? " << (P.tail()==v1) << endl;
3.101 + check(P.tail() == v1);
3.102 +
3.103 + // Na ja, ez igy nem igazi, mindket esetet le kene tesztelni,
3.104 + // de legalabb valami:
3.105 +#ifdef DEBUG
3.106 + cout << "Hozzaadunk az elejehez egy nem illeszkedo elet..." << endl;
3.107 + rc = false;
3.108 + try {
3.109 + B.pushFront(e3);
3.110 + }
3.111 + catch(const Exception &e) {
3.112 + cout << "E: " << e.what() << endl;
3.113 + rc = true;
3.114 + }
3.115 + check(rc);
3.116 +#endif
3.117 +
3.118 + cout << "Hozzaadunk a vegehez ket elet..." << endl;
3.119 + B.pushBack(e7);
3.120 + B.pushBack(e8);
3.121 + cout << "P.length() == " << P.length() << endl;
3.122 + check(P.length() == 2);
3.123 +
3.124 + cout << "Es commitolunk...\n";
3.125 + B.commit();
3.126 + }
3.127 + cout << "P.length() == " << P.length() << endl;
3.128 + check(P.length() == 4);
3.129 +
3.130 + cout << "P.head()==v3 ? " << (P.head()==v3) << endl;
3.131 + check(P.head() == v3);
3.132 +
3.133 +#ifndef HUGO_SKELETON_PATH_H
3.134 + cout << "Vegigiteralunk az eleken." << endl;
3.135 + typedef DPath::NodeIt NodeIt;
3.136 + typedef DPath::EdgeIt EdgeIt;
3.137 + EdgeIt e;
3.138 + int i=1;
3.139 + for(P.first(e); e!=INVALID; ++e, ++i) {
3.140 + cout << i << ". el: " <</* e << */endl;
3.141 + }
3.142 +#endif
3.143 +
3.144 + // Na ja, ez igy nem igazi, mindket esetet le kene tesztelni,
3.145 + // de legalabb valami:
3.146 +
3.147 +#ifdef DEBUG
3.148 + rc = false;
3.149 + try {
3.150 + cout << "Setting an edgeiter to a nonexistant edge." << endl;
3.151 + //P.nth(e,134);
3.152 + rc = !debug;
3.153 + }
3.154 + catch(const Exception &e) {
3.155 + cout << "E: " << e.what() << endl;
3.156 + rc = debug;
3.157 + }
3.158 + check(rc);
3.159 +#endif
3.160 + }
3.161 +
3.162 + }
3.163 + catch(const std::exception &e) {
3.164 + cout << "Uncaught exception: " << e.what() << endl;
3.165 + return 1;
3.166 + }
3.167 + catch(...) {
3.168 + cout << "Something horrible happened: an exception which isn't "
3.169 + << "std::exception" << endl;
3.170 + return 2;
3.171 + }
3.172 +
3.173 +
3.174 + cout << (passed ? "All tests passed." : "Some of the tests failed!!!")
3.175 + << endl;
3.176 +
3.177 + return passed ? 0 : 1;
3.178 +}
4.1 --- a/src/test/path_test.cc Sun Sep 12 19:32:21 2004 +0000
4.2 +++ b/src/test/path_test.cc Sun Sep 12 21:46:26 2004 +0000
4.3 @@ -1,190 +1,84 @@
4.4 #include <string>
4.5 #include <iostream>
4.6 -//#include <hugo/path.h>
4.7 #include <hugo/skeletons/path.h>
4.8 +#include <hugo/path.h>
4.9 #include <hugo/list_graph.h>
4.10
4.11 using namespace std;
4.12 using namespace hugo;
4.13 -#ifdef SKELETON
4.14 using namespace skeleton;
4.15 -#endif
4.16
4.17 -bool passed = true;
4.18 +template<class Path> void checkCompilePath(Path &P)
4.19 +{
4.20 + typedef typename Path::EdgeIt EdgeIt;
4.21 + typedef typename Path::NodeIt NodeIt;
4.22 + typedef typename Path::GraphNode GraphNode;
4.23 + typedef typename Path::GraphEdge GraphEdge;
4.24 + //typedef typename Path::Builder Builder;
4.25 + //??? ha csinalok ilyet es siman Builderrel peldanyositok, akkor warningol. Talan friend miatt? De ki az?
4.26
4.27 -void check(bool rc) {
4.28 - passed = passed && rc;
4.29 - if(!rc) {
4.30 - cout << "Test failed!" << endl;
4.31 - }
4.32 + EdgeIt ei;
4.33 + NodeIt ni;
4.34 + GraphNode gn;
4.35 + GraphEdge ge;
4.36 +
4.37 + size_t st;
4.38 + bool b;
4.39 +
4.40 + //Path(const Graph &_G) {} //the constructor has been already called
4.41 +
4.42 + st=P.length(); //size_t length() const {return 0;}
4.43 + b=P.empty(); //bool empty() const {}
4.44 + P.clear(); //void clear() {}
4.45 +
4.46 + gn=P.head(); //GraphNode/*It*/ head() const {return INVALID;}
4.47 + gn=P.tail(); //GraphNode/*It*/ tail() const {return INVALID;}
4.48 +
4.49 + ei=P.first(ei); //It& first(It &i) const { return i=It(*this); }
4.50 +
4.51 + ni=P.head(ei); //NodeIt head(const EdgeIt& e) const {}
4.52 + ni=P.tail(ei); //NodeIt tail(const EdgeIt& e) const {}
4.53 +
4.54 +
4.55 + ListGraph lg;
4.56 + Path p(lg);
4.57 +
4.58 + EdgeIt i; //EdgeIt() {}
4.59 + EdgeIt j(INVALID); //EdgeIt(Invalid) {}
4.60 + EdgeIt k(p); //EdgeIt(const Path &_p) {}
4.61 +
4.62 + //??? operator GraphEdge () const {}
4.63 +
4.64 + //INVALIDra megy a ++????
4.65 + i=++j; //EdgeIt& operator++() {}
4.66 + b=(i==j); //bool operator==(const EdgeIt& e) const {return true;}
4.67 + b=(i!=j); //bool operator!=(const EdgeIt& e) const {return true;}
4.68 +
4.69 +
4.70 + NodeIt l; //NodeIt() {}
4.71 + NodeIt m(INVALID); //NodeIt(Invalid) {}
4.72 + NodeIt n(p); //NodeIt(const Path &_p) {}
4.73 +
4.74 + //operator const GraphNode& () const {}
4.75 +
4.76 + l=++m; //NodeIt& operator++() {}
4.77 + b=(m==n); //bool operator==(const NodeIt& e) const {}
4.78 + b=(m!=n); //bool operator!=(const NodeIt& e) const {}
4.79 +
4.80 + typename Path::Builder builder(p); //Builder(Path &_P) : P(_P) {}
4.81 + builder.setStartNode(gn); //void setStartNode(const GraphNode &) {}
4.82 + builder.pushFront(ge); //void pushFront(const GraphEdge& e) {}
4.83 + builder.pushBack(ge); //void pushBack(const GraphEdge& e) {}
4.84 + builder.commit(); //void commit() {}
4.85 + builder.reserveFront(st); //void reserveFront(size_t r) {}
4.86 + builder.reserveBack(st); //void reserveBack(size_t r) {}
4.87 +
4.88 }
4.89
4.90 -#ifdef DEBUG
4.91 -const bool debug = true;
4.92 -#else
4.93 -const bool debug = false;
4.94 -#endif
4.95 +template void checkCompilePath< skeleton::Path<ListGraph> >(skeleton::Path<ListGraph> &);
4.96 +template void checkCompilePath< DirPath<ListGraph> >(DirPath<ListGraph> &);
4.97 +template void checkCompilePath< UndirPath<ListGraph> >(UndirPath<ListGraph> &);
4.98
4.99 -
4.100 -int main() {
4.101 -
4.102 - try {
4.103 -
4.104 - typedef ListGraph::Node Node;
4.105 - typedef ListGraph::Edge Edge;
4.106 -
4.107 - ListGraph G;
4.108 -
4.109 - Node s=G.addNode();
4.110 - Node v1=G.addNode();
4.111 - Node v2=G.addNode();
4.112 - Node v3=G.addNode();
4.113 - Node v4=G.addNode();
4.114 - Node t=G.addNode();
4.115 -
4.116 - Edge e1 = G.addEdge(s, v1);
4.117 - Edge e2 = G.addEdge(s, v2);
4.118 - Edge e3 = G.addEdge(v1, v2);
4.119 - Edge e4 = G.addEdge(v2, v1);
4.120 - Edge e5 = G.addEdge(v1, v3);
4.121 - Edge e6 = G.addEdge(v3, v2);
4.122 - Edge e7 = G.addEdge(v2, v4);
4.123 - Edge e8 = G.addEdge(v4, v3);
4.124 - Edge e9 = G.addEdge(v3, t);
4.125 - Edge e10 = G.addEdge(v4, t);
4.126 -
4.127 -#ifdef DEBUG
4.128 - bool rc;
4.129 -#endif
4.130 -
4.131 - {
4.132 - cout << "\n\n\nDirPath tesztelese...\n";
4.133 -
4.134 -
4.135 - cout << "Ures path letrehozasa" << endl;
4.136 -#ifdef SKELETON
4.137 - typedef Path <ListGraph> DPath;
4.138 -#else
4.139 - typedef DirPath<ListGraph> DPath;
4.140 -#endif
4.141 - DPath P(G);
4.142 -
4.143 - cout << "P.length() == " << P.length() << endl;
4.144 - check(P.length() == 0);
4.145 -
4.146 -#ifdef SKELETON
4.147 - cout << "P.tail() valid? " << (P.tail()!=INVALID) << endl;
4.148 - check(! (P.tail()!=INVALID));
4.149 -#else
4.150 - cout << "P.tail() valid? " << (P.from()!=INVALID) << endl;
4.151 - check(! (P.to()!=INVALID));
4.152 -#endif
4.153 - {
4.154 - cout << "Builder objektum letrehozasa" << endl;
4.155 - DPath::Builder B(P);
4.156 -
4.157 - cout << "Hozzaadunk az elejehez ket elet..." << endl;
4.158 - B.pushFront(e6);
4.159 - B.pushFront(e5);
4.160 - cout << "P.length() == " << P.length() << endl;
4.161 - check(P.length() == 0);
4.162 -
4.163 - cout << "Commitolunk..." << endl;
4.164 - B.commit();
4.165 -
4.166 - cout << "P.length() == " << P.length() << endl;
4.167 - check(P.length() == 2);
4.168 -
4.169 -#ifdef SKELETON
4.170 - cout << "P.tail() valid? " << (P.tail()!=INVALID) << endl;
4.171 - check(P.tail()!=INVALID);
4.172 - cout << "P.tail()==v1 ? " << (P.tail()==v1) << endl;
4.173 - check(P.tail() == v1);
4.174 -#else
4.175 - cout << "P.tail() valid? " << (P.from()!=INVALID) << endl;
4.176 - check(P.from()!=INVALID);
4.177 - cout << "P.tail()==v1 ? " << (P.from()==v1) << endl;
4.178 - check(P.from() == v1);
4.179 -#endif
4.180 -
4.181 - // Na ja, ez igy nem igazi, mindket esetet le kene tesztelni,
4.182 - // de legalabb valami:
4.183 -#ifdef DEBUG
4.184 - cout << "Hozzaadunk az elejehez egy nem illeszkedo elet..." << endl;
4.185 - rc = false;
4.186 - try {
4.187 - B.pushFront(e3);
4.188 - }
4.189 - catch(const Exception &e) {
4.190 - cout << "E: " << e.what() << endl;
4.191 - rc = true;
4.192 - }
4.193 - check(rc);
4.194 -#endif
4.195 -
4.196 - cout << "Hozzaadunk a vegehez ket elet..." << endl;
4.197 - B.pushBack(e7);
4.198 - B.pushBack(e8);
4.199 - cout << "P.length() == " << P.length() << endl;
4.200 - check(P.length() == 2);
4.201 -
4.202 - cout << "Es commitolunk...\n";
4.203 - B.commit();
4.204 - }
4.205 - cout << "P.length() == " << P.length() << endl;
4.206 - check(P.length() == 4);
4.207 -
4.208 -#ifdef SKELETON
4.209 - cout << "P.head()==v3 ? " << (P.head()==v3) << endl;
4.210 - check(P.head() == v3);
4.211 -#else
4.212 - cout << "P.head()==v3 ? " << (P.to()==v3) << endl;
4.213 - check(P.to() == v3);
4.214 -#endif
4.215 -
4.216 -#ifndef SKELETON
4.217 - cout << "Vegigiteralunk az eleken." << endl;
4.218 - typedef DPath::NodeIt NodeIt;
4.219 - typedef DPath::EdgeIt EdgeIt;
4.220 - EdgeIt e;
4.221 - int i=1;
4.222 - for(P.first(e); e!=INVALID; ++e, ++i) {
4.223 - cout << i << ". el: " <</* e << */endl;
4.224 - }
4.225 -#endif
4.226 -
4.227 - // Na ja, ez igy nem igazi, mindket esetet le kene tesztelni,
4.228 - // de legalabb valami:
4.229 -
4.230 -#ifdef DEBUG
4.231 - rc = false;
4.232 - try {
4.233 - cout << "Setting an edgeiter to a nonexistant edge." << endl;
4.234 - //P.nth(e,134);
4.235 - rc = !debug;
4.236 - }
4.237 - catch(const Exception &e) {
4.238 - cout << "E: " << e.what() << endl;
4.239 - rc = debug;
4.240 - }
4.241 - check(rc);
4.242 -#endif
4.243 - }
4.244 -
4.245 - }
4.246 - catch(const std::exception &e) {
4.247 - cout << "Uncaught exception: " << e.what() << endl;
4.248 - return 1;
4.249 - }
4.250 - catch(...) {
4.251 - cout << "Something horrible happened: an exception which isn't "
4.252 - << "std::exception" << endl;
4.253 - return 2;
4.254 - }
4.255 -
4.256 -
4.257 - cout << (passed ? "All tests passed." : "Some of the tests failed!!!")
4.258 - << endl;
4.259 -
4.260 - return passed ? 0 : 1;
4.261 +int main()
4.262 +{
4.263 }