hegyi@831: #include <string>
hegyi@831: #include <iostream>
hegyi@831: //#include <hugo/skeletons/path.h>
hegyi@831: #include <hugo/path.h>
hegyi@831: #include <hugo/list_graph.h>
hegyi@831: 
hegyi@831: using namespace std;
hegyi@831: using namespace hugo;
hegyi@831: #ifdef HUGO_SKELETON_PATH_H
hegyi@831: using namespace skeleton;
hegyi@831: #endif
hegyi@831: 
hegyi@831: bool passed = true;
hegyi@831: 
hegyi@831: void check(bool rc) {
hegyi@831:   passed = passed && rc;
hegyi@831:   if(!rc) {
hegyi@831:     cout << "Test failed!" << endl;
hegyi@831:   }
hegyi@831: }
hegyi@831: 
hegyi@831: #ifdef DEBUG
hegyi@831: const bool debug = true;
hegyi@831: #else
hegyi@831: const bool debug = false;
hegyi@831: #endif
hegyi@831: 
hegyi@831: 
hegyi@831: int main() {
hegyi@831: 
hegyi@831:   try {
hegyi@831: 
hegyi@831:     typedef ListGraph::Node Node;
hegyi@831:     typedef ListGraph::Edge Edge;
hegyi@831: 
hegyi@831:     ListGraph G;
hegyi@831: 
hegyi@831:     Node s=G.addNode();
hegyi@831:     Node v1=G.addNode();
hegyi@831:     Node v2=G.addNode();
hegyi@831:     Node v3=G.addNode();
hegyi@831:     Node v4=G.addNode();
hegyi@831:     Node t=G.addNode();
hegyi@831:   
hegyi@831:     Edge e1 = G.addEdge(s, v1);
hegyi@831:     Edge e2 = G.addEdge(s, v2);
hegyi@831:     Edge e3 = G.addEdge(v1, v2);
hegyi@831:     Edge e4 = G.addEdge(v2, v1);
hegyi@831:     Edge e5 = G.addEdge(v1, v3);
hegyi@831:     Edge e6 = G.addEdge(v3, v2);
hegyi@831:     Edge e7 = G.addEdge(v2, v4);
hegyi@831:     Edge e8 = G.addEdge(v4, v3);
hegyi@831:     Edge e9 = G.addEdge(v3, t);
hegyi@831:     Edge e10 = G.addEdge(v4, t);
hegyi@831: 
hegyi@831: #ifdef DEBUG
hegyi@831:     bool rc;
hegyi@831: #endif
hegyi@831: 
hegyi@831:     {
hegyi@831:       cout << "\n\n\nDirPath tesztelese...\n";
hegyi@831: 
hegyi@831: 
hegyi@831:       cout << "Ures path letrehozasa" << endl;
hegyi@831: 
hegyi@831: #ifndef HUGO_SKELETON_PATH_H
hegyi@831:       typedef DirPath<ListGraph> DPath;
hegyi@831: #else
hegyi@831:       typedef Path<ListGraph> DPath;
hegyi@831: #endif
hegyi@831: 
hegyi@831:       DPath P(G);
hegyi@831: 
hegyi@831:       cout << "P.length() == " << P.length() << endl;
hegyi@831:       check(P.length() == 0);
hegyi@831: 
hegyi@831:       cout << "P.tail() valid? " << (P.tail()!=INVALID) << endl;
hegyi@831:       check(! (P.tail()!=INVALID));
hegyi@831:       {
hegyi@831: 	cout << "Builder objektum letrehozasa" << endl;
hegyi@831: 	DPath::Builder B(P);
hegyi@831: 
hegyi@831: 	cout << "Hozzaadunk az elejehez ket elet..." << endl;
hegyi@831: 	B.pushFront(e6);
hegyi@831: 	B.pushFront(e5);
hegyi@831: 	cout << "P.length() == " << P.length() << endl;
hegyi@831: 	check(P.length() == 0);
hegyi@831:       
hegyi@831: 	cout << "Commitolunk..." << endl;
hegyi@831: 	B.commit();
hegyi@831: 
hegyi@831: 	cout << "P.length() == " << P.length() << endl;
hegyi@831: 	check(P.length() == 2);
hegyi@831: 
hegyi@831: 	cout << "P.tail() valid? " << (P.tail()!=INVALID) << endl;
hegyi@831: 	check(P.tail()!=INVALID);
hegyi@831: 	cout << "P.tail()==v1 ? " << (P.tail()==v1) << endl;
hegyi@831: 	check(P.tail() == v1);
hegyi@831: 
hegyi@831: 	// Na ja, ez igy nem igazi, mindket esetet le kene tesztelni,
hegyi@831: 	// de legalabb valami:
hegyi@831: #ifdef DEBUG
hegyi@831: 	cout << "Hozzaadunk az elejehez egy nem illeszkedo elet..." << endl;
hegyi@831: 	rc = false;
hegyi@831: 	try {
hegyi@831: 	  B.pushFront(e3);
hegyi@831: 	}
hegyi@831: 	catch(const Exception &e) {
hegyi@831: 	  cout << "E: " << e.what() << endl;
hegyi@831: 	  rc = true;
hegyi@831: 	}
hegyi@831: 	check(rc);
hegyi@831: #endif
hegyi@831: 
hegyi@831: 	cout << "Hozzaadunk a vegehez ket elet..." << endl;
hegyi@831: 	B.pushBack(e7);
hegyi@831: 	B.pushBack(e8);
hegyi@831: 	cout << "P.length() == " << P.length() << endl;
hegyi@831: 	check(P.length() == 2);
hegyi@831:       
hegyi@831: 	cout << "Es commitolunk...\n";
hegyi@831: 	B.commit();
hegyi@831:       }
hegyi@831:       cout << "P.length() == " << P.length() << endl;
hegyi@831:       check(P.length() == 4);
hegyi@831: 
hegyi@831:       cout << "P.head()==v3 ? " << (P.head()==v3) << endl;
hegyi@831:       check(P.head() == v3);
hegyi@831: 
hegyi@831: #ifndef HUGO_SKELETON_PATH_H
hegyi@831:       cout << "Vegigiteralunk az eleken." << endl;
hegyi@831:       typedef DPath::NodeIt NodeIt;
hegyi@831:       typedef DPath::EdgeIt EdgeIt;
hegyi@831:       EdgeIt e;
hegyi@831:       int i=1;
hegyi@831:       for(P.first(e); e!=INVALID; ++e, ++i) {
hegyi@831: 	cout << i << ". el: " <</* e << */endl;
hegyi@831:       }
hegyi@831: #endif
hegyi@831: 
hegyi@831:       // Na ja, ez igy nem igazi, mindket esetet le kene tesztelni,
hegyi@831:       // de legalabb valami:
hegyi@831: 
hegyi@831: #ifdef DEBUG
hegyi@831:       rc = false;
hegyi@831:       try {
hegyi@831: 	cout << "Setting an edgeiter to a nonexistant edge." << endl;
hegyi@831: 	//P.nth(e,134);
hegyi@831: 	rc = !debug;
hegyi@831:       }
hegyi@831:       catch(const Exception &e) {
hegyi@831: 	cout << "E: " << e.what() << endl;
hegyi@831: 	rc = debug;
hegyi@831:       }
hegyi@831:       check(rc);
hegyi@831: #endif
hegyi@831:     }
hegyi@831: 
hegyi@831:   }
hegyi@831:   catch(const std::exception &e) {
hegyi@831:     cout << "Uncaught exception: " << e.what() << endl;
hegyi@831:     return 1;
hegyi@831:   }
hegyi@831:   catch(...) {
hegyi@831:     cout << "Something horrible happened: an exception which isn't "
hegyi@831: 	 << "std::exception" << endl;
hegyi@831:     return 2;
hegyi@831:   }
hegyi@831: 
hegyi@831: 
hegyi@831:   cout << (passed ? "All tests passed." : "Some of the tests failed!!!")
hegyi@831:        << endl;
hegyi@831: 
hegyi@831:   return passed ? 0 : 1;
hegyi@831: }