1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/test/path_test.cc Wed Sep 08 11:57:13 2004 +0000
1.3 @@ -0,0 +1,189 @@
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/list_graph.h>
1.9 +
1.10 +using namespace std;
1.11 +using namespace hugo;
1.12 +#ifdef SKELETON
1.13 +using namespace skeleton;
1.14 +#endif
1.15 +
1.16 +bool passed = true;
1.17 +
1.18 +void check(bool rc) {
1.19 + passed = passed && rc;
1.20 + if(!rc) {
1.21 + cout << "Test failed!" << endl;
1.22 + }
1.23 +}
1.24 +
1.25 +#ifdef DEBUG
1.26 +const bool debug = true;
1.27 +#else
1.28 +const bool debug = false;
1.29 +#endif
1.30 +
1.31 +
1.32 +int main() {
1.33 +
1.34 + try {
1.35 +
1.36 + typedef ListGraph::Node Node;
1.37 + typedef ListGraph::Edge Edge;
1.38 +
1.39 + ListGraph G;
1.40 +
1.41 + Node s=G.addNode();
1.42 + Node v1=G.addNode();
1.43 + Node v2=G.addNode();
1.44 + Node v3=G.addNode();
1.45 + Node v4=G.addNode();
1.46 + Node t=G.addNode();
1.47 +
1.48 + Edge e1 = G.addEdge(s, v1);
1.49 + Edge e2 = G.addEdge(s, v2);
1.50 + Edge e3 = G.addEdge(v1, v2);
1.51 + Edge e4 = G.addEdge(v2, v1);
1.52 + Edge e5 = G.addEdge(v1, v3);
1.53 + Edge e6 = G.addEdge(v3, v2);
1.54 + Edge e7 = G.addEdge(v2, v4);
1.55 + Edge e8 = G.addEdge(v4, v3);
1.56 + Edge e9 = G.addEdge(v3, t);
1.57 + Edge e10 = G.addEdge(v4, t);
1.58 +
1.59 +#ifdef DEBUG
1.60 + bool rc;
1.61 +#endif
1.62 +
1.63 + {
1.64 + cout << "\n\n\nDirPath tesztelese...\n";
1.65 +
1.66 +
1.67 + cout << "Ures path letrehozasa" << endl;
1.68 +#ifdef SKELETON
1.69 + typedef Path <ListGraph> DPath;
1.70 +#else
1.71 + typedef DirPath<ListGraph> DPath;
1.72 +#endif
1.73 + DPath P(G);
1.74 +
1.75 + cout << "P.length() == " << P.length() << endl;
1.76 + check(P.length() == 0);
1.77 +
1.78 +#ifdef SKELETON
1.79 + cout << "P.tail() valid? " << (P.tail()!=INVALID) << endl;
1.80 + check(! (P.tail()!=INVALID));
1.81 +#else
1.82 + cout << "P.tail() valid? " << (P.from()!=INVALID) << endl;
1.83 + check(! (P.to()!=INVALID));
1.84 +#endif
1.85 + {
1.86 + cout << "Builder objektum letrehozasa" << endl;
1.87 + DPath::Builder B(P);
1.88 +
1.89 + cout << "Hozzaadunk az elejehez ket elet..." << endl;
1.90 + B.pushFront(e6);
1.91 + B.pushFront(e5);
1.92 + cout << "P.length() == " << P.length() << endl;
1.93 + check(P.length() == 0);
1.94 +
1.95 + cout << "Commitolunk..." << endl;
1.96 + B.commit();
1.97 +
1.98 + cout << "P.length() == " << P.length() << endl;
1.99 + check(P.length() == 2);
1.100 +
1.101 +#ifdef SKELETON
1.102 + cout << "P.tail() valid? " << (P.tail()!=INVALID) << endl;
1.103 + check(P.tail()!=INVALID);
1.104 + cout << "P.tail()==v1 ? " << (P.tail()==v1) << endl;
1.105 + check(P.tail() == v1);
1.106 +#else
1.107 + cout << "P.tail() valid? " << (P.from()!=INVALID) << endl;
1.108 + check(P.from()!=INVALID);
1.109 + cout << "P.tail()==v1 ? " << (P.from()==v1) << endl;
1.110 + check(P.from() == v1);
1.111 +#endif
1.112 +
1.113 + // Na ja, ez igy nem igazi, mindket esetet le kene tesztelni,
1.114 + // de legalabb valami:
1.115 +#ifdef DEBUG
1.116 + cout << "Hozzaadunk az elejehez egy nem illeszkedo elet..." << endl;
1.117 + rc = false;
1.118 + try {
1.119 + B.pushFront(e3);
1.120 + }
1.121 + catch(const Exception &e) {
1.122 + cout << "E: " << e.what() << endl;
1.123 + rc = true;
1.124 + }
1.125 + check(rc);
1.126 +#endif
1.127 +
1.128 + cout << "Hozzaadunk a vegehez ket elet..." << endl;
1.129 + B.pushBack(e7);
1.130 + B.pushBack(e8);
1.131 + cout << "P.length() == " << P.length() << endl;
1.132 + check(P.length() == 2);
1.133 +
1.134 + cout << "Es commitolunk...\n";
1.135 + B.commit();
1.136 + }
1.137 + cout << "P.length() == " << P.length() << endl;
1.138 + check(P.length() == 4);
1.139 +
1.140 +#ifdef SKELETON
1.141 + cout << "P.head()==v3 ? " << (P.head()==v3) << endl;
1.142 + check(P.head() == v3);
1.143 +#else
1.144 + cout << "P.head()==v3 ? " << (P.to()==v3) << endl;
1.145 + check(P.to() == v3);
1.146 +#endif
1.147 +
1.148 + cout << "Vegigiteralunk az eleken." << endl;
1.149 + typedef DPath::NodeIt NodeIt;
1.150 + typedef DPath::EdgeIt EdgeIt;
1.151 + EdgeIt e;
1.152 + int i=1;
1.153 + for(P.first(e); e!=INVALID; ++e, ++i) {
1.154 + cout << i << ". el: " <</* e << */endl;
1.155 + }
1.156 +
1.157 +
1.158 + // Na ja, ez igy nem igazi, mindket esetet le kene tesztelni,
1.159 + // de legalabb valami:
1.160 +
1.161 +#ifdef DEBUG
1.162 + rc = false;
1.163 + try {
1.164 + cout << "Setting an edgeiter to a nonexistant edge." << endl;
1.165 + //P.nth(e,134);
1.166 + rc = !debug;
1.167 + }
1.168 + catch(const Exception &e) {
1.169 + cout << "E: " << e.what() << endl;
1.170 + rc = debug;
1.171 + }
1.172 + check(rc);
1.173 +#endif
1.174 + }
1.175 +
1.176 + }
1.177 + catch(const std::exception &e) {
1.178 + cout << "Uncaught exception: " << e.what() << endl;
1.179 + return 1;
1.180 + }
1.181 + catch(...) {
1.182 + cout << "Something horrible happened: an exception which isn't "
1.183 + << "std::exception" << endl;
1.184 + return 2;
1.185 + }
1.186 +
1.187 +
1.188 + cout << (passed ? "All tests passed." : "Some of the tests failed!!!")
1.189 + << endl;
1.190 +
1.191 + return passed ? 0 : 1;
1.192 +}