src/test/old_path_test.cc
author alpar
Sun, 19 Sep 2004 12:45:35 +0000
changeset 883 4af619b64d98
permissions -rw-r--r--
Put away debug.h and error.h temporarily.
     1 #include <string>
     2 #include <iostream>
     3 //#include <hugo/skeletons/path.h>
     4 #include <hugo/path.h>
     5 #include <hugo/list_graph.h>
     6 
     7 using namespace std;
     8 using namespace hugo;
     9 #ifdef HUGO_SKELETON_PATH_H
    10 using namespace skeleton;
    11 #endif
    12 
    13 bool passed = true;
    14 
    15 void check(bool rc) {
    16   passed = passed && rc;
    17   if(!rc) {
    18     cout << "Test failed!" << endl;
    19   }
    20 }
    21 
    22 #ifdef DEBUG
    23 const bool debug = true;
    24 #else
    25 const bool debug = false;
    26 #endif
    27 
    28 
    29 int main() {
    30 
    31   try {
    32 
    33     typedef ListGraph::Node Node;
    34     typedef ListGraph::Edge Edge;
    35 
    36     ListGraph G;
    37 
    38     Node s=G.addNode();
    39     Node v1=G.addNode();
    40     Node v2=G.addNode();
    41     Node v3=G.addNode();
    42     Node v4=G.addNode();
    43     Node t=G.addNode();
    44   
    45     Edge e1 = G.addEdge(s, v1);
    46     Edge e2 = G.addEdge(s, v2);
    47     Edge e3 = G.addEdge(v1, v2);
    48     Edge e4 = G.addEdge(v2, v1);
    49     Edge e5 = G.addEdge(v1, v3);
    50     Edge e6 = G.addEdge(v3, v2);
    51     Edge e7 = G.addEdge(v2, v4);
    52     Edge e8 = G.addEdge(v4, v3);
    53     Edge e9 = G.addEdge(v3, t);
    54     Edge e10 = G.addEdge(v4, t);
    55 
    56 #ifdef DEBUG
    57     bool rc;
    58 #endif
    59 
    60     {
    61       cout << "\n\n\nDirPath tesztelese...\n";
    62 
    63 
    64       cout << "Ures path letrehozasa" << endl;
    65 
    66 #ifndef HUGO_SKELETON_PATH_H
    67       typedef DirPath<ListGraph> DPath;
    68 #else
    69       typedef Path<ListGraph> DPath;
    70 #endif
    71 
    72       DPath P(G);
    73 
    74       cout << "P.length() == " << P.length() << endl;
    75       check(P.length() == 0);
    76 
    77       cout << "P.tail() valid? " << (P.tail()!=INVALID) << endl;
    78       check(! (P.tail()!=INVALID));
    79       {
    80 	cout << "Builder objektum letrehozasa" << endl;
    81 	DPath::Builder B(P);
    82 
    83 	cout << "Hozzaadunk az elejehez ket elet..." << endl;
    84 	B.pushFront(e6);
    85 	B.pushFront(e5);
    86 	cout << "P.length() == " << P.length() << endl;
    87 	check(P.length() == 0);
    88       
    89 	cout << "Commitolunk..." << endl;
    90 	B.commit();
    91 
    92 	cout << "P.length() == " << P.length() << endl;
    93 	check(P.length() == 2);
    94 
    95 	cout << "P.tail() valid? " << (P.tail()!=INVALID) << endl;
    96 	check(P.tail()!=INVALID);
    97 	cout << "P.tail()==v1 ? " << (P.tail()==v1) << endl;
    98 	check(P.tail() == v1);
    99 
   100 	// Na ja, ez igy nem igazi, mindket esetet le kene tesztelni,
   101 	// de legalabb valami:
   102 #ifdef DEBUG
   103 	cout << "Hozzaadunk az elejehez egy nem illeszkedo elet..." << endl;
   104 	rc = false;
   105 	try {
   106 	  B.pushFront(e3);
   107 	}
   108 	catch(const Exception &e) {
   109 	  cout << "E: " << e.what() << endl;
   110 	  rc = true;
   111 	}
   112 	check(rc);
   113 #endif
   114 
   115 	cout << "Hozzaadunk a vegehez ket elet..." << endl;
   116 	B.pushBack(e7);
   117 	B.pushBack(e8);
   118 	cout << "P.length() == " << P.length() << endl;
   119 	check(P.length() == 2);
   120       
   121 	cout << "Es commitolunk...\n";
   122 	B.commit();
   123       }
   124       cout << "P.length() == " << P.length() << endl;
   125       check(P.length() == 4);
   126 
   127       cout << "P.head()==v3 ? " << (P.head()==v3) << endl;
   128       check(P.head() == v3);
   129 
   130 #ifndef HUGO_SKELETON_PATH_H
   131       cout << "Vegigiteralunk az eleken." << endl;
   132       typedef DPath::NodeIt NodeIt;
   133       typedef DPath::EdgeIt EdgeIt;
   134       EdgeIt e;
   135       int i=1;
   136       for(P.first(e); e!=INVALID; ++e, ++i) {
   137 	cout << i << ". el: " <</* e << */endl;
   138       }
   139 #endif
   140 
   141       // Na ja, ez igy nem igazi, mindket esetet le kene tesztelni,
   142       // de legalabb valami:
   143 
   144 #ifdef DEBUG
   145       rc = false;
   146       try {
   147 	cout << "Setting an edgeiter to a nonexistant edge." << endl;
   148 	//P.nth(e,134);
   149 	rc = !debug;
   150       }
   151       catch(const Exception &e) {
   152 	cout << "E: " << e.what() << endl;
   153 	rc = debug;
   154       }
   155       check(rc);
   156 #endif
   157     }
   158 
   159   }
   160   catch(const std::exception &e) {
   161     cout << "Uncaught exception: " << e.what() << endl;
   162     return 1;
   163   }
   164   catch(...) {
   165     cout << "Something horrible happened: an exception which isn't "
   166 	 << "std::exception" << endl;
   167     return 2;
   168   }
   169 
   170 
   171   cout << (passed ? "All tests passed." : "Some of the tests failed!!!")
   172        << endl;
   173 
   174   return passed ? 0 : 1;
   175 }