path_test is getting under construction
authorhegyi
Wed, 08 Sep 2004 11:57:13 +0000
changeset 820a9b6a7f73895
parent 819 3623e8dbce49
child 821 283a7fe3a00e
path_test is getting under construction
src/test/Makefile.am
src/test/path_test.cc
     1.1 --- a/src/test/Makefile.am	Wed Sep 08 11:49:09 2004 +0000
     1.2 +++ b/src/test/Makefile.am	Wed Sep 08 11:57:13 2004 +0000
     1.3 @@ -11,6 +11,7 @@
     1.4  	kruskal_test \
     1.5  	mincostflows_test \
     1.6  	minlengthpaths_test \
     1.7 +	path_test \
     1.8  	test_tools_fail \
     1.9  	test_tools_pass \
    1.10  	time_measure_test \
    1.11 @@ -29,6 +30,7 @@
    1.12  kruskal_test_SOURCES = kruskal_test.cc
    1.13  mincostflows_test_SOURCES = mincostflows_test.cc
    1.14  minlengthpaths_test_SOURCES = minlengthpaths_test.cc
    1.15 +path_test_SOURCES = path_test.cc
    1.16  time_measure_test_SOURCES = time_measure_test.cc
    1.17  test_tools_fail_SOURCES = test_tools_fail.cc
    1.18  test_tools_pass_SOURCES = test_tools_pass.cc
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/src/test/path_test.cc	Wed Sep 08 11:57:13 2004 +0000
     2.3 @@ -0,0 +1,189 @@
     2.4 +#include <string>
     2.5 +#include <iostream>
     2.6 +//#include <hugo/path.h>
     2.7 +#include <hugo/skeletons/path.h>
     2.8 +#include <hugo/list_graph.h>
     2.9 +
    2.10 +using namespace std;
    2.11 +using namespace hugo;
    2.12 +#ifdef SKELETON
    2.13 +using namespace skeleton;
    2.14 +#endif
    2.15 +
    2.16 +bool passed = true;
    2.17 +
    2.18 +void check(bool rc) {
    2.19 +  passed = passed && rc;
    2.20 +  if(!rc) {
    2.21 +    cout << "Test failed!" << endl;
    2.22 +  }
    2.23 +}
    2.24 +
    2.25 +#ifdef DEBUG
    2.26 +const bool debug = true;
    2.27 +#else
    2.28 +const bool debug = false;
    2.29 +#endif
    2.30 +
    2.31 +
    2.32 +int main() {
    2.33 +
    2.34 +  try {
    2.35 +
    2.36 +    typedef ListGraph::Node Node;
    2.37 +    typedef ListGraph::Edge Edge;
    2.38 +
    2.39 +    ListGraph G;
    2.40 +
    2.41 +    Node s=G.addNode();
    2.42 +    Node v1=G.addNode();
    2.43 +    Node v2=G.addNode();
    2.44 +    Node v3=G.addNode();
    2.45 +    Node v4=G.addNode();
    2.46 +    Node t=G.addNode();
    2.47 +  
    2.48 +    Edge e1 = G.addEdge(s, v1);
    2.49 +    Edge e2 = G.addEdge(s, v2);
    2.50 +    Edge e3 = G.addEdge(v1, v2);
    2.51 +    Edge e4 = G.addEdge(v2, v1);
    2.52 +    Edge e5 = G.addEdge(v1, v3);
    2.53 +    Edge e6 = G.addEdge(v3, v2);
    2.54 +    Edge e7 = G.addEdge(v2, v4);
    2.55 +    Edge e8 = G.addEdge(v4, v3);
    2.56 +    Edge e9 = G.addEdge(v3, t);
    2.57 +    Edge e10 = G.addEdge(v4, t);
    2.58 +
    2.59 +#ifdef DEBUG
    2.60 +    bool rc;
    2.61 +#endif
    2.62 +
    2.63 +    {
    2.64 +      cout << "\n\n\nDirPath tesztelese...\n";
    2.65 +
    2.66 +
    2.67 +      cout << "Ures path letrehozasa" << endl;
    2.68 +#ifdef SKELETON
    2.69 +      typedef Path <ListGraph> DPath;
    2.70 +#else
    2.71 +      typedef DirPath<ListGraph> DPath;
    2.72 +#endif
    2.73 +      DPath P(G);
    2.74 +
    2.75 +      cout << "P.length() == " << P.length() << endl;
    2.76 +      check(P.length() == 0);
    2.77 +
    2.78 +#ifdef SKELETON
    2.79 +      cout << "P.tail() valid? " << (P.tail()!=INVALID) << endl;
    2.80 +      check(! (P.tail()!=INVALID));
    2.81 +#else
    2.82 +      cout << "P.tail() valid? " << (P.from()!=INVALID) << endl;
    2.83 +      check(! (P.to()!=INVALID));
    2.84 +#endif
    2.85 +      {
    2.86 +	cout << "Builder objektum letrehozasa" << endl;
    2.87 +	DPath::Builder B(P);
    2.88 +
    2.89 +	cout << "Hozzaadunk az elejehez ket elet..." << endl;
    2.90 +	B.pushFront(e6);
    2.91 +	B.pushFront(e5);
    2.92 +	cout << "P.length() == " << P.length() << endl;
    2.93 +	check(P.length() == 0);
    2.94 +      
    2.95 +	cout << "Commitolunk..." << endl;
    2.96 +	B.commit();
    2.97 +
    2.98 +	cout << "P.length() == " << P.length() << endl;
    2.99 +	check(P.length() == 2);
   2.100 +
   2.101 +#ifdef SKELETON
   2.102 +	cout << "P.tail() valid? " << (P.tail()!=INVALID) << endl;
   2.103 +	check(P.tail()!=INVALID);
   2.104 +	cout << "P.tail()==v1 ? " << (P.tail()==v1) << endl;
   2.105 +	check(P.tail() == v1);
   2.106 +#else
   2.107 +	cout << "P.tail() valid? " << (P.from()!=INVALID) << endl;
   2.108 +	check(P.from()!=INVALID);
   2.109 +	cout << "P.tail()==v1 ? " << (P.from()==v1) << endl;
   2.110 +	check(P.from() == v1);
   2.111 +#endif
   2.112 +
   2.113 +	// Na ja, ez igy nem igazi, mindket esetet le kene tesztelni,
   2.114 +	// de legalabb valami:
   2.115 +#ifdef DEBUG
   2.116 +	cout << "Hozzaadunk az elejehez egy nem illeszkedo elet..." << endl;
   2.117 +	rc = false;
   2.118 +	try {
   2.119 +	  B.pushFront(e3);
   2.120 +	}
   2.121 +	catch(const Exception &e) {
   2.122 +	  cout << "E: " << e.what() << endl;
   2.123 +	  rc = true;
   2.124 +	}
   2.125 +	check(rc);
   2.126 +#endif
   2.127 +
   2.128 +	cout << "Hozzaadunk a vegehez ket elet..." << endl;
   2.129 +	B.pushBack(e7);
   2.130 +	B.pushBack(e8);
   2.131 +	cout << "P.length() == " << P.length() << endl;
   2.132 +	check(P.length() == 2);
   2.133 +      
   2.134 +	cout << "Es commitolunk...\n";
   2.135 +	B.commit();
   2.136 +      }
   2.137 +      cout << "P.length() == " << P.length() << endl;
   2.138 +      check(P.length() == 4);
   2.139 +
   2.140 +#ifdef SKELETON
   2.141 +      cout << "P.head()==v3 ? " << (P.head()==v3) << endl;
   2.142 +      check(P.head() == v3);
   2.143 +#else
   2.144 +      cout << "P.head()==v3 ? " << (P.to()==v3) << endl;
   2.145 +      check(P.to() == v3);
   2.146 +#endif
   2.147 +
   2.148 +      cout << "Vegigiteralunk az eleken." << endl;
   2.149 +      typedef DPath::NodeIt NodeIt;
   2.150 +      typedef DPath::EdgeIt EdgeIt;
   2.151 +      EdgeIt e;
   2.152 +      int i=1;
   2.153 +      for(P.first(e); e!=INVALID; ++e, ++i) {
   2.154 +	cout << i << ". el: " <</* e << */endl;
   2.155 +      }
   2.156 +
   2.157 +
   2.158 +      // Na ja, ez igy nem igazi, mindket esetet le kene tesztelni,
   2.159 +      // de legalabb valami:
   2.160 +
   2.161 +#ifdef DEBUG
   2.162 +      rc = false;
   2.163 +      try {
   2.164 +	cout << "Setting an edgeiter to a nonexistant edge." << endl;
   2.165 +	//P.nth(e,134);
   2.166 +	rc = !debug;
   2.167 +      }
   2.168 +      catch(const Exception &e) {
   2.169 +	cout << "E: " << e.what() << endl;
   2.170 +	rc = debug;
   2.171 +      }
   2.172 +      check(rc);
   2.173 +#endif
   2.174 +    }
   2.175 +
   2.176 +  }
   2.177 +  catch(const std::exception &e) {
   2.178 +    cout << "Uncaught exception: " << e.what() << endl;
   2.179 +    return 1;
   2.180 +  }
   2.181 +  catch(...) {
   2.182 +    cout << "Something horrible happened: an exception which isn't "
   2.183 +	 << "std::exception" << endl;
   2.184 +    return 2;
   2.185 +  }
   2.186 +
   2.187 +
   2.188 +  cout << (passed ? "All tests passed." : "Some of the tests failed!!!")
   2.189 +       << endl;
   2.190 +
   2.191 +  return passed ? 0 : 1;
   2.192 +}