1.1 --- a/src/test/path_test.cc Sun Sep 12 19:32:21 2004 +0000
1.2 +++ b/src/test/path_test.cc Sun Sep 12 21:46:26 2004 +0000
1.3 @@ -1,190 +1,84 @@
1.4 #include <string>
1.5 #include <iostream>
1.6 -//#include <hugo/path.h>
1.7 #include <hugo/skeletons/path.h>
1.8 +#include <hugo/path.h>
1.9 #include <hugo/list_graph.h>
1.10
1.11 using namespace std;
1.12 using namespace hugo;
1.13 -#ifdef SKELETON
1.14 using namespace skeleton;
1.15 -#endif
1.16
1.17 -bool passed = true;
1.18 +template<class Path> void checkCompilePath(Path &P)
1.19 +{
1.20 + typedef typename Path::EdgeIt EdgeIt;
1.21 + typedef typename Path::NodeIt NodeIt;
1.22 + typedef typename Path::GraphNode GraphNode;
1.23 + typedef typename Path::GraphEdge GraphEdge;
1.24 + //typedef typename Path::Builder Builder;
1.25 + //??? ha csinalok ilyet es siman Builderrel peldanyositok, akkor warningol. Talan friend miatt? De ki az?
1.26
1.27 -void check(bool rc) {
1.28 - passed = passed && rc;
1.29 - if(!rc) {
1.30 - cout << "Test failed!" << endl;
1.31 - }
1.32 + EdgeIt ei;
1.33 + NodeIt ni;
1.34 + GraphNode gn;
1.35 + GraphEdge ge;
1.36 +
1.37 + size_t st;
1.38 + bool b;
1.39 +
1.40 + //Path(const Graph &_G) {} //the constructor has been already called
1.41 +
1.42 + st=P.length(); //size_t length() const {return 0;}
1.43 + b=P.empty(); //bool empty() const {}
1.44 + P.clear(); //void clear() {}
1.45 +
1.46 + gn=P.head(); //GraphNode/*It*/ head() const {return INVALID;}
1.47 + gn=P.tail(); //GraphNode/*It*/ tail() const {return INVALID;}
1.48 +
1.49 + ei=P.first(ei); //It& first(It &i) const { return i=It(*this); }
1.50 +
1.51 + ni=P.head(ei); //NodeIt head(const EdgeIt& e) const {}
1.52 + ni=P.tail(ei); //NodeIt tail(const EdgeIt& e) const {}
1.53 +
1.54 +
1.55 + ListGraph lg;
1.56 + Path p(lg);
1.57 +
1.58 + EdgeIt i; //EdgeIt() {}
1.59 + EdgeIt j(INVALID); //EdgeIt(Invalid) {}
1.60 + EdgeIt k(p); //EdgeIt(const Path &_p) {}
1.61 +
1.62 + //??? operator GraphEdge () const {}
1.63 +
1.64 + //INVALIDra megy a ++????
1.65 + i=++j; //EdgeIt& operator++() {}
1.66 + b=(i==j); //bool operator==(const EdgeIt& e) const {return true;}
1.67 + b=(i!=j); //bool operator!=(const EdgeIt& e) const {return true;}
1.68 +
1.69 +
1.70 + NodeIt l; //NodeIt() {}
1.71 + NodeIt m(INVALID); //NodeIt(Invalid) {}
1.72 + NodeIt n(p); //NodeIt(const Path &_p) {}
1.73 +
1.74 + //operator const GraphNode& () const {}
1.75 +
1.76 + l=++m; //NodeIt& operator++() {}
1.77 + b=(m==n); //bool operator==(const NodeIt& e) const {}
1.78 + b=(m!=n); //bool operator!=(const NodeIt& e) const {}
1.79 +
1.80 + typename Path::Builder builder(p); //Builder(Path &_P) : P(_P) {}
1.81 + builder.setStartNode(gn); //void setStartNode(const GraphNode &) {}
1.82 + builder.pushFront(ge); //void pushFront(const GraphEdge& e) {}
1.83 + builder.pushBack(ge); //void pushBack(const GraphEdge& e) {}
1.84 + builder.commit(); //void commit() {}
1.85 + builder.reserveFront(st); //void reserveFront(size_t r) {}
1.86 + builder.reserveBack(st); //void reserveBack(size_t r) {}
1.87 +
1.88 }
1.89
1.90 -#ifdef DEBUG
1.91 -const bool debug = true;
1.92 -#else
1.93 -const bool debug = false;
1.94 -#endif
1.95 +template void checkCompilePath< skeleton::Path<ListGraph> >(skeleton::Path<ListGraph> &);
1.96 +template void checkCompilePath< DirPath<ListGraph> >(DirPath<ListGraph> &);
1.97 +template void checkCompilePath< UndirPath<ListGraph> >(UndirPath<ListGraph> &);
1.98
1.99 -
1.100 -int main() {
1.101 -
1.102 - try {
1.103 -
1.104 - typedef ListGraph::Node Node;
1.105 - typedef ListGraph::Edge Edge;
1.106 -
1.107 - ListGraph G;
1.108 -
1.109 - Node s=G.addNode();
1.110 - Node v1=G.addNode();
1.111 - Node v2=G.addNode();
1.112 - Node v3=G.addNode();
1.113 - Node v4=G.addNode();
1.114 - Node t=G.addNode();
1.115 -
1.116 - Edge e1 = G.addEdge(s, v1);
1.117 - Edge e2 = G.addEdge(s, v2);
1.118 - Edge e3 = G.addEdge(v1, v2);
1.119 - Edge e4 = G.addEdge(v2, v1);
1.120 - Edge e5 = G.addEdge(v1, v3);
1.121 - Edge e6 = G.addEdge(v3, v2);
1.122 - Edge e7 = G.addEdge(v2, v4);
1.123 - Edge e8 = G.addEdge(v4, v3);
1.124 - Edge e9 = G.addEdge(v3, t);
1.125 - Edge e10 = G.addEdge(v4, t);
1.126 -
1.127 -#ifdef DEBUG
1.128 - bool rc;
1.129 -#endif
1.130 -
1.131 - {
1.132 - cout << "\n\n\nDirPath tesztelese...\n";
1.133 -
1.134 -
1.135 - cout << "Ures path letrehozasa" << endl;
1.136 -#ifdef SKELETON
1.137 - typedef Path <ListGraph> DPath;
1.138 -#else
1.139 - typedef DirPath<ListGraph> DPath;
1.140 -#endif
1.141 - DPath P(G);
1.142 -
1.143 - cout << "P.length() == " << P.length() << endl;
1.144 - check(P.length() == 0);
1.145 -
1.146 -#ifdef SKELETON
1.147 - cout << "P.tail() valid? " << (P.tail()!=INVALID) << endl;
1.148 - check(! (P.tail()!=INVALID));
1.149 -#else
1.150 - cout << "P.tail() valid? " << (P.from()!=INVALID) << endl;
1.151 - check(! (P.to()!=INVALID));
1.152 -#endif
1.153 - {
1.154 - cout << "Builder objektum letrehozasa" << endl;
1.155 - DPath::Builder B(P);
1.156 -
1.157 - cout << "Hozzaadunk az elejehez ket elet..." << endl;
1.158 - B.pushFront(e6);
1.159 - B.pushFront(e5);
1.160 - cout << "P.length() == " << P.length() << endl;
1.161 - check(P.length() == 0);
1.162 -
1.163 - cout << "Commitolunk..." << endl;
1.164 - B.commit();
1.165 -
1.166 - cout << "P.length() == " << P.length() << endl;
1.167 - check(P.length() == 2);
1.168 -
1.169 -#ifdef SKELETON
1.170 - cout << "P.tail() valid? " << (P.tail()!=INVALID) << endl;
1.171 - check(P.tail()!=INVALID);
1.172 - cout << "P.tail()==v1 ? " << (P.tail()==v1) << endl;
1.173 - check(P.tail() == v1);
1.174 -#else
1.175 - cout << "P.tail() valid? " << (P.from()!=INVALID) << endl;
1.176 - check(P.from()!=INVALID);
1.177 - cout << "P.tail()==v1 ? " << (P.from()==v1) << endl;
1.178 - check(P.from() == v1);
1.179 -#endif
1.180 -
1.181 - // Na ja, ez igy nem igazi, mindket esetet le kene tesztelni,
1.182 - // de legalabb valami:
1.183 -#ifdef DEBUG
1.184 - cout << "Hozzaadunk az elejehez egy nem illeszkedo elet..." << endl;
1.185 - rc = false;
1.186 - try {
1.187 - B.pushFront(e3);
1.188 - }
1.189 - catch(const Exception &e) {
1.190 - cout << "E: " << e.what() << endl;
1.191 - rc = true;
1.192 - }
1.193 - check(rc);
1.194 -#endif
1.195 -
1.196 - cout << "Hozzaadunk a vegehez ket elet..." << endl;
1.197 - B.pushBack(e7);
1.198 - B.pushBack(e8);
1.199 - cout << "P.length() == " << P.length() << endl;
1.200 - check(P.length() == 2);
1.201 -
1.202 - cout << "Es commitolunk...\n";
1.203 - B.commit();
1.204 - }
1.205 - cout << "P.length() == " << P.length() << endl;
1.206 - check(P.length() == 4);
1.207 -
1.208 -#ifdef SKELETON
1.209 - cout << "P.head()==v3 ? " << (P.head()==v3) << endl;
1.210 - check(P.head() == v3);
1.211 -#else
1.212 - cout << "P.head()==v3 ? " << (P.to()==v3) << endl;
1.213 - check(P.to() == v3);
1.214 -#endif
1.215 -
1.216 -#ifndef SKELETON
1.217 - cout << "Vegigiteralunk az eleken." << endl;
1.218 - typedef DPath::NodeIt NodeIt;
1.219 - typedef DPath::EdgeIt EdgeIt;
1.220 - EdgeIt e;
1.221 - int i=1;
1.222 - for(P.first(e); e!=INVALID; ++e, ++i) {
1.223 - cout << i << ". el: " <</* e << */endl;
1.224 - }
1.225 -#endif
1.226 -
1.227 - // Na ja, ez igy nem igazi, mindket esetet le kene tesztelni,
1.228 - // de legalabb valami:
1.229 -
1.230 -#ifdef DEBUG
1.231 - rc = false;
1.232 - try {
1.233 - cout << "Setting an edgeiter to a nonexistant edge." << endl;
1.234 - //P.nth(e,134);
1.235 - rc = !debug;
1.236 - }
1.237 - catch(const Exception &e) {
1.238 - cout << "E: " << e.what() << endl;
1.239 - rc = debug;
1.240 - }
1.241 - check(rc);
1.242 -#endif
1.243 - }
1.244 -
1.245 - }
1.246 - catch(const std::exception &e) {
1.247 - cout << "Uncaught exception: " << e.what() << endl;
1.248 - return 1;
1.249 - }
1.250 - catch(...) {
1.251 - cout << "Something horrible happened: an exception which isn't "
1.252 - << "std::exception" << endl;
1.253 - return 2;
1.254 - }
1.255 -
1.256 -
1.257 - cout << (passed ? "All tests passed." : "Some of the tests failed!!!")
1.258 - << endl;
1.259 -
1.260 - return passed ? 0 : 1;
1.261 +int main()
1.262 +{
1.263 }