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