1.1 --- a/test/path_test.cc Tue Oct 17 10:42:19 2006 +0000
1.2 +++ b/test/path_test.cc Tue Oct 17 10:50:57 2006 +0000
1.3 @@ -18,81 +18,91 @@
1.4
1.5 #include <string>
1.6 #include <iostream>
1.7 +
1.8 #include <lemon/concept/path.h>
1.9 +#include <lemon/concept/graph.h>
1.10 +
1.11 #include <lemon/path.h>
1.12 #include <lemon/list_graph.h>
1.13
1.14 +#include "test_tools.h"
1.15 +
1.16 using namespace std;
1.17 using namespace lemon;
1.18 -using namespace lemon::concept;
1.19
1.20 -template<class Path> void checkCompilePath(Path &P)
1.21 -{
1.22 - typedef typename Path::EdgeIt EdgeIt;
1.23 - typedef typename Path::NodeIt NodeIt;
1.24 - typedef typename Path::GraphNode GraphNode;
1.25 - typedef typename Path::GraphEdge GraphEdge;
1.26 - //typedef typename Path::Builder Builder;
1.27 - //??? ha csinalok ilyet es siman Builderrel peldanyositok, akkor warningol. Talan friend miatt? De ki az?
1.28 -
1.29 - EdgeIt ei;
1.30 - NodeIt ni;
1.31 - GraphNode gn;
1.32 - GraphEdge ge;
1.33 -
1.34 - size_t st;
1.35 - bool b;
1.36 -
1.37 - //Path(const Graph &_G) {} //the constructor has been already called
1.38 -
1.39 - st=P.length(); //size_t length() const {return 0;}
1.40 - b=P.empty(); //bool empty() const {}
1.41 - P.clear(); //void clear() {}
1.42 -
1.43 - gn=P.target(); //GraphNode/*It*/ target() const {return INVALID;}
1.44 - gn=P.source(); //GraphNode/*It*/ source() const {return INVALID;}
1.45 -
1.46 - ei=P.first(ei); //It& first(It &i) const { return i=It(*this); }
1.47 -
1.48 - ni=P.target(ei); //NodeIt target(const EdgeIt& e) const {}
1.49 - ni=P.source(ei); //NodeIt source(const EdgeIt& e) const {}
1.50 -
1.51 -
1.52 - ListGraph lg;
1.53 - Path p(lg);
1.54 -
1.55 - EdgeIt i; //EdgeIt() {}
1.56 - EdgeIt j(INVALID); //EdgeIt(Invalid) {}
1.57 - EdgeIt k(p); //EdgeIt(const Path &_p) {}
1.58 -
1.59 - i=++j; //EdgeIt& operator++() {}
1.60 - ++k;
1.61 - b=(i==j); //bool operator==(const EdgeIt& e) const {return true;}
1.62 - b=(i!=j); //bool operator!=(const EdgeIt& e) const {return true;}
1.63 -
1.64 -
1.65 - NodeIt l; //NodeIt() {}
1.66 - NodeIt m(INVALID); //NodeIt(Invalid) {}
1.67 - NodeIt n(p); //NodeIt(const Path &_p) {}
1.68 -
1.69 - l=++m; //NodeIt& operator++() {}
1.70 - b=(m==n); //bool operator==(const NodeIt& e) const {}
1.71 - b=(m!=n); //bool operator!=(const NodeIt& e) const {}
1.72 -
1.73 - typename Path::Builder builder(p); //Builder(Path &_P) : P(_P) {}
1.74 - builder.setStartNode(gn); //void setStartNode(const GraphNode &) {}
1.75 - builder.pushFront(ge); //void pushFront(const GraphEdge& e) {}
1.76 - builder.pushBack(ge); //void pushBack(const GraphEdge& e) {}
1.77 - builder.commit(); //void commit() {}
1.78 - builder.reserveFront(st); //void reserveFront(size_t r) {}
1.79 - builder.reserveBack(st); //void reserveBack(size_t r) {}
1.80 -
1.81 +void check_concepts() {
1.82 + checkConcept<concept::Path<concept::Graph>,
1.83 + concept::Path<concept::Graph> >();
1.84 + checkConcept<concept::Path<concept::Graph>,
1.85 + Path<concept::Graph> >();
1.86 + checkConcept<concept::Path<ListGraph>, Path<ListGraph> >();
1.87 }
1.88
1.89 -template void checkCompilePath< concept::Path<ListGraph> >(concept::Path<ListGraph> &);
1.90 -template void checkCompilePath< DirPath<ListGraph> >(DirPath<ListGraph> &);
1.91 -template void checkCompilePath< UPath<ListGraph> >(UPath<ListGraph> &);
1.92 +int main() {
1.93 + check_concepts();
1.94 +
1.95 + ListGraph g;
1.96 +
1.97 + ListGraph::Node n1 = g.addNode();
1.98 + ListGraph::Node n2 = g.addNode();
1.99 + ListGraph::Node n3 = g.addNode();
1.100 + ListGraph::Node n4 = g.addNode();
1.101 + ListGraph::Node n5 = g.addNode();
1.102 +
1.103 + ListGraph::Edge e1 = g.addEdge(n1, n2);
1.104 + ListGraph::Edge e2 = g.addEdge(n2, n3);
1.105 + ListGraph::Edge e3 = g.addEdge(n3, n4);
1.106 + ListGraph::Edge e4 = g.addEdge(n4, n5);
1.107 + ListGraph::Edge e5 = g.addEdge(n5, n1);
1.108
1.109 -int main()
1.110 -{
1.111 + {
1.112 + Path<ListGraph> p(g);
1.113 +
1.114 + check(p.empty(), "Wrong Path");
1.115 + check(p.length() == 0, "Wrong Path");
1.116 +
1.117 + {
1.118 + Path<ListGraph>::Builder b(p);
1.119 + b.setStartNode(n3);
1.120 + b.commit();
1.121 + }
1.122 +
1.123 + check(!p.empty(), "Wrong Path");
1.124 + check(p.length() == 0, "Wrong Path");
1.125 + check(p.source() == n3, "Wrong Path");
1.126 + check(p.target() == n3, "Wrong Path");
1.127 +
1.128 + {
1.129 + Path<ListGraph>::Builder b(p);
1.130 + b.pushBack(e3);
1.131 + b.pushBack(e4);
1.132 + b.pushFront(e2);
1.133 + b.commit();
1.134 + }
1.135 +
1.136 + check(!p.empty(), "Wrong Path");
1.137 + check(p.length() == 3, "Wrong Path");
1.138 + check(p.source() == n2, "Wrong Path");
1.139 + check(p.target() == n5, "Wrong Path");
1.140 +
1.141 + {
1.142 + Path<ListGraph>::NodeIt it(p);
1.143 + check((ListGraph::Node)it == n2, "Wrong Path"); ++it;
1.144 + check((ListGraph::Node)it == n3, "Wrong Path"); ++it;
1.145 + check((ListGraph::Node)it == n4, "Wrong Path"); ++it;
1.146 + check((ListGraph::Node)it == n5, "Wrong Path"); ++it;
1.147 + check((ListGraph::Node)it == INVALID, "Wrong Path");
1.148 + }
1.149 +
1.150 + {
1.151 + Path<ListGraph>::EdgeIt it(p);
1.152 + check((ListGraph::Edge)it == e2, "Wrong Path"); ++it;
1.153 + check((ListGraph::Edge)it == e3, "Wrong Path"); ++it;
1.154 + check((ListGraph::Edge)it == e4, "Wrong Path"); ++it;
1.155 + check((ListGraph::Edge)it == INVALID, "Wrong Path");
1.156 + }
1.157 +
1.158 + }
1.159 +
1.160 + return 0;
1.161 }