src/work/klao/path_test.cc
changeset 493 bbd1db03f0fe
parent 369 dc9c19f4ca9a
     1.1 --- a/src/work/klao/path_test.cc	Fri Apr 30 01:10:13 2004 +0000
     1.2 +++ b/src/work/klao/path_test.cc	Fri Apr 30 01:59:15 2004 +0000
     1.3 @@ -16,233 +16,142 @@
     1.4    }
     1.5  }
     1.6  
     1.7 +#ifdef DEBUG
     1.8 +const bool debug = true;
     1.9 +#else
    1.10 +const bool debug = false;
    1.11 +#endif
    1.12 +
    1.13 +
    1.14  int main() {
    1.15  
    1.16 -  typedef ListGraph::Node Node;
    1.17 -  typedef ListGraph::Edge Edge;
    1.18 +  try {
    1.19  
    1.20 -  ListGraph G;
    1.21 +    typedef ListGraph::Node Node;
    1.22 +    typedef ListGraph::Edge Edge;
    1.23  
    1.24 -  Node s=G.addNode();
    1.25 -  Node v1=G.addNode();
    1.26 -  Node v2=G.addNode();
    1.27 -  Node v3=G.addNode();
    1.28 -  Node v4=G.addNode();
    1.29 -  Node t=G.addNode();
    1.30 +    ListGraph G;
    1.31 +
    1.32 +    Node s=G.addNode();
    1.33 +    Node v1=G.addNode();
    1.34 +    Node v2=G.addNode();
    1.35 +    Node v3=G.addNode();
    1.36 +    Node v4=G.addNode();
    1.37 +    Node t=G.addNode();
    1.38    
    1.39 -  Edge e1 = G.addEdge(s, v1);
    1.40 -  Edge e2 = G.addEdge(s, v2);
    1.41 -  Edge e3 = G.addEdge(v1, v2);
    1.42 -  Edge e4 = G.addEdge(v2, v1);
    1.43 -  Edge e5 = G.addEdge(v1, v3);
    1.44 -  Edge e6 = G.addEdge(v3, v2);
    1.45 -  Edge e7 = G.addEdge(v2, v4);
    1.46 -  Edge e8 = G.addEdge(v4, v3);
    1.47 -  Edge e9 = G.addEdge(v3, t);
    1.48 -  Edge e10 = G.addEdge(v4, t);
    1.49 +    Edge e1 = G.addEdge(s, v1);
    1.50 +    Edge e2 = G.addEdge(s, v2);
    1.51 +    Edge e3 = G.addEdge(v1, v2);
    1.52 +    Edge e4 = G.addEdge(v2, v1);
    1.53 +    Edge e5 = G.addEdge(v1, v3);
    1.54 +    Edge e6 = G.addEdge(v3, v2);
    1.55 +    Edge e7 = G.addEdge(v2, v4);
    1.56 +    Edge e8 = G.addEdge(v4, v3);
    1.57 +    Edge e9 = G.addEdge(v3, t);
    1.58 +    Edge e10 = G.addEdge(v4, t);
    1.59  
    1.60 -  bool rc;
    1.61 +    bool rc;
    1.62  
    1.63 -  {
    1.64 -    cout << "DynamicPath tesztelese...\n";
    1.65 +    {
    1.66 +      cout << "\n\n\nDirPath tesztelese...\n";
    1.67  
    1.68 -    cout << "Ures path letrehozasa" << endl;
    1.69 -    typedef DynamicPath<ListGraph> LPath;
    1.70 -    LPath P(G);
    1.71  
    1.72 -    cout << "P.length() == " << P.length() << endl;
    1.73 -    check(P.length() == 0);
    1.74 +      cout << "Ures path letrehozasa" << endl;
    1.75 +      typedef DirPath<ListGraph> DPath;
    1.76 +      DPath P(G);
    1.77  
    1.78 -    cout << "P.from() valid? " << G.valid(P.from()) << endl;
    1.79 -    check(! G.valid(P.from()));
    1.80 +      cout << "P.length() == " << P.length() << endl;
    1.81 +      check(P.length() == 0);
    1.82  
    1.83 -    cout << "Hozzaadunk ket elet..." << endl;
    1.84 -    check(P.pushBack(e1));
    1.85 -    check(P.pushBack(e3));
    1.86 -    cout << "P.length() == " << P.length() << endl;
    1.87 -    check(P.length() == 2);
    1.88 +      cout << "P.from() valid? " << G.valid(P.from()) << endl;
    1.89 +      check(! G.valid(P.from()));
    1.90  
    1.91 -    cout << "P.from() valid? " << G.valid(P.from()) << endl;
    1.92 -    check(G.valid(P.from()));
    1.93 -  
    1.94 -    cout << "P.from()==s ? " << (P.from()==s) << endl;
    1.95 -    check(P.from() == s);
    1.96 +      {
    1.97 +	cout << "Builder objektum letrehozasa" << endl;
    1.98 +	DPath::Builder B(P);
    1.99  
   1.100 -    cout << "Hozzaadunk egy nem illeszkedo elt." << endl;
   1.101 -    rc = P.pushBack(e8);
   1.102 -    cout << "Sukerult: " << rc << endl;
   1.103 -    check(!rc);
   1.104 +	cout << "Hozzaadunk az elejehez ket elet..." << endl;
   1.105 +	B.pushFront(e6);
   1.106 +	B.pushFront(e5);
   1.107 +	cout << "P.length() == " << P.length() << endl;
   1.108 +	check(P.length() == 0);
   1.109 +      
   1.110 +	cout << "Commitolunk..." << endl;
   1.111 +	B.commit();
   1.112  
   1.113 -    cout << "Meg 3 el hozzaadasa, nem mind elore iranyu..." << endl;
   1.114 -    check(P.pushBack(e6));
   1.115 -    check(P.pushBack(e8));
   1.116 -    check(P.pushBack(e10));
   1.117 +	cout << "P.length() == " << P.length() << endl;
   1.118 +	check(P.length() == 2);
   1.119 +	cout << "P.from() valid? " << G.valid(P.from()) << endl;
   1.120 +	check(G.valid(P.from()));
   1.121 +	cout << "P.from()==v1 ? " << (P.from()==v1) << endl;
   1.122 +	check(P.from() == v1);
   1.123  
   1.124 -    cout << "P.length() == " << P.length() << endl;
   1.125 -    check(P.length() == 5);
   1.126 +	// Na ja, ez igy nem igazi, mindket esetet le kene tesztelni,
   1.127 +	// de legalabb valami:
   1.128 +#ifdef DEBUG
   1.129 +	cout << "Hozzaadunk az elejehez egy nem illeszkedo elet..." << endl;
   1.130 +	rc = false;
   1.131 +	try {
   1.132 +	  B.pushFront(e3);
   1.133 +	}
   1.134 +	catch(const Exception &e) {
   1.135 +	  cout << "E: " << e.what() << endl;
   1.136 +	  rc = true;
   1.137 +	}
   1.138 +	check(rc);
   1.139 +#endif
   1.140  
   1.141 -    cout << "P.from()==s ? " << (P.from()==s) << endl;
   1.142 -    check(P.from() == s);
   1.143 -    cout << "P.to()==t ? " << (P.to()==t) << endl;
   1.144 -    check(P.to() == t);
   1.145 +	cout << "Hozzaadunk a vegehez ket elet..." << endl;
   1.146 +	B.pushBack(e7);
   1.147 +	B.pushBack(e8);
   1.148 +	cout << "P.length() == " << P.length() << endl;
   1.149 +	check(P.length() == 2);
   1.150 +      
   1.151 +	cout << "Es commitolunk...\n";
   1.152 +	B.commit();
   1.153 +      }
   1.154 +      cout << "P.length() == " << P.length() << endl;
   1.155 +      check(P.length() == 4);
   1.156 +      cout << "P.to()==v3 ? " << (P.to()==v3) << endl;
   1.157 +      check(P.to() == v3);
   1.158  
   1.159 -    cout << "Vegpont bellitasa: " << endl;
   1.160 -    rc = P.setTo(v2);
   1.161 -    cout << "Hibasra: " << rc << endl;
   1.162 -    check(!rc);
   1.163 -    rc = P.setTo(t);
   1.164 -    cout << "Helyesre: " << rc << endl;
   1.165 -    check(rc);
   1.166 +      cout << "Vegigiteralunk az eleken." << endl;
   1.167 +      typedef DPath::NodeIt NodeIt;
   1.168 +      typedef DPath::EdgeIt EdgeIt;
   1.169 +      EdgeIt e;
   1.170 +      int i=1;
   1.171 +      for(P.first(e); P.valid(e); P.next(e), ++i) {
   1.172 +	cout << i << ". el: " << e << endl;
   1.173 +      }
   1.174  
   1.175 -    cout << "Elek iranyitasanak ellenorzese." << endl;
   1.176 -    cout << "El: " << e1 << ", G.tail(el): " << G.head(e1) << endl;
   1.177 -    check(G.tail(e1)==s);
   1.178  
   1.179 -    cout << "Vegigiteralunk az eleken." << endl;
   1.180 -    typedef LPath::NodeIt NodeIt;
   1.181 -    typedef LPath::EdgeIt EdgeIt;
   1.182 -    EdgeIt e = P.first<EdgeIt>();
   1.183 -    int i=1;
   1.184 -    for(; P.valid(e); P.next(e), ++i) {
   1.185 -      cout << i << ". el: " << P.graphEdge(e)
   1.186 -	   << ", elore el? " << P.isForward(e) << endl;
   1.187 -      if(i>=3 && i<5) 
   1.188 -	check(!P.isForward(e));
   1.189 -      else
   1.190 -	check(P.isForward(e));
   1.191 +      // Na ja, ez igy nem igazi, mindket esetet le kene tesztelni,
   1.192 +      // de legalabb valami:
   1.193 +      rc = false;
   1.194 +      try {
   1.195 +	cout << "Setting an edgeiter to a nonexistant edge." << endl;
   1.196 +	P.nth(e,134);
   1.197 +	rc = !debug;
   1.198 +      }
   1.199 +      catch(const Exception &e) {
   1.200 +	cout << "E: " << e.what() << endl;
   1.201 +	rc = debug;
   1.202 +      }
   1.203 +      check(rc);
   1.204      }
   1.205  
   1.206 -    {
   1.207 -      cout << "Reszut letrehozasa: [2. el, 4. el)..." << endl;
   1.208 -      LPath P2(P, P.nth<EdgeIt>(1), P.nth<EdgeIt>(3));
   1.209 -
   1.210 -      cout << "P2.length() == " << P2.length() << endl;
   1.211 -      check(P2.length() == 2);
   1.212 -    
   1.213 -      cout << "P2.from()==v1 ? " << (P2.from()==v1) << endl;
   1.214 -      check(P2.from() == v1);
   1.215 -      cout << "P2.to()==v3 ? " << (P2.to()==v3) << endl;
   1.216 -      check(P2.to() == v3);
   1.217 -    }
   1.218 -    {
   1.219 -      cout << "Reszut letrehozasa: [1. el, 6. el)..." << endl;
   1.220 -      LPath P2(P, P.nth<EdgeIt>(0), P.nth<EdgeIt>(5));
   1.221 -
   1.222 -      cout << "P2.length() == " << P2.length() << endl;
   1.223 -      check(P2.length() == 5);
   1.224 -    
   1.225 -      cout << "P2.from()==s ? " << (P2.from()==s) << endl;
   1.226 -      check(P2.from() == s);
   1.227 -      cout << "P2.to()==t ? " << (P2.to()==t) << endl;
   1.228 -      check(P2.to() == t);
   1.229 -    }
   1.230 -
   1.231 -    {
   1.232 -      cout << "Ket pont altal megadott reszut letrehozasa: [2. pont, 4. pont]..."
   1.233 -	   << endl;
   1.234 -      LPath P2(P, P.nth<NodeIt>(1), P.nth<NodeIt>(3));
   1.235 -
   1.236 -      cout << "P2.length() == " << P2.length() << endl;
   1.237 -      check(P2.length() == 2);
   1.238 -    
   1.239 -      cout << "P2.from()==v1 ? " << (P2.from()==v1) << endl;
   1.240 -      check(P2.from() == v1);
   1.241 -      cout << "P2.to()==v3 ? " << (P2.to()==v3) << endl;
   1.242 -      check(P2.to() == v3);
   1.243 -    }
   1.244 -    {
   1.245 -      cout << "Egy pontu reszut letrehozasa: [4. pont, 4. pont]..."
   1.246 -	   << endl;
   1.247 -      LPath P2(P, P.nth<NodeIt>(3), P.nth<NodeIt>(3));
   1.248 -
   1.249 -      cout << "P2.length() == " << P2.length() << endl;
   1.250 -      check(P2.length() == 0);
   1.251 -    
   1.252 -      cout << "P2.from()==v3 ? " << (P2.from()==v3) << endl;
   1.253 -      check(P2.from() == v3);
   1.254 -      cout << "P2.to()==v3 ? " << (P2.to()==v3) << endl;
   1.255 -      check(P2.to() == v3);
   1.256 -    }
   1.257 -    {
   1.258 -      cout << "Forditott ut letrehozasa: [6. pont, 1. pont]..."
   1.259 -	   << endl;
   1.260 -      LPath P2(P, P.nth<NodeIt>(5), P.nth<NodeIt>(0));
   1.261 -
   1.262 -      cout << "P2.length() == " << P2.length() << endl;
   1.263 -      check(P2.length() == 5);
   1.264 -    
   1.265 -      cout << "P2.from()==t ? " << (P2.from()==t) << endl;
   1.266 -      check(P2.from() == t);
   1.267 -      cout << "P2.to()==s ? " << (P2.to()==s) << endl;
   1.268 -      check(P2.to() == s);
   1.269 -    }
   1.270  
   1.271    }
   1.272 +  catch(const std::exception &e) {
   1.273 +    cout << "Uncaught exception: " << e.what() << endl;
   1.274 +    return 1;
   1.275 +  }
   1.276 +  catch(...) {
   1.277 +    cout << "Something horrible happened: an exception which isn't "
   1.278 +	 << "std::exception" << endl;
   1.279 +    return 2;
   1.280 +  }
   1.281  
   1.282 -  {
   1.283 -    cout << "\n\n\nDirPath tesztelese...\n";
   1.284 -
   1.285 -
   1.286 -    cout << "Ures path letrehozasa" << endl;
   1.287 -    typedef DirPath<ListGraph> DPath;
   1.288 -    DPath P(G);
   1.289 -
   1.290 -    cout << "P.length() == " << P.length() << endl;
   1.291 -    check(P.length() == 0);
   1.292 -
   1.293 -    cout << "P.from() valid? " << G.valid(P.from()) << endl;
   1.294 -    check(! G.valid(P.from()));
   1.295 -
   1.296 -    {
   1.297 -      cout << "Builder objektum letrehozasa" << endl;
   1.298 -      DPath::Builder B(P);
   1.299 -
   1.300 -      cout << "Hozzaadunk az elejehez ket elet..." << endl;
   1.301 -      check(B.pushFront(e6));
   1.302 -      check(B.pushFront(e5));
   1.303 -      cout << "P.length() == " << P.length() << endl;
   1.304 -      check(P.length() == 0);
   1.305 -      
   1.306 -      cout << "Commitolunk..." << endl;
   1.307 -      B.commit();
   1.308 -
   1.309 -      cout << "P.length() == " << P.length() << endl;
   1.310 -      check(P.length() == 2);
   1.311 -      cout << "P.from() valid? " << G.valid(P.from()) << endl;
   1.312 -      check(G.valid(P.from()));
   1.313 -      cout << "P.from()==v1 ? " << (P.from()==v1) << endl;
   1.314 -      check(P.from() == v1);
   1.315 -
   1.316 -      cout << "Hozzaadunk az elejehez egy nem illeszkedo elet..." << endl;
   1.317 -      check(!B.pushFront(e3));
   1.318 -    
   1.319 -      cout << "Hozzaadunk a vegehez ket elet..." << endl;
   1.320 -      check(B.pushBack(e7));
   1.321 -      check(B.pushBack(e8));
   1.322 -      cout << "P.length() == " << P.length() << endl;
   1.323 -      check(P.length() == 4);
   1.324 -
   1.325 -      cout << "Hozzaadunk az elejehez meg egy elet..." << endl;
   1.326 -      check(B.pushFront(e4));
   1.327 -      cout << "P.length() == " << P.length() << endl;
   1.328 -      check(P.length() == 4);
   1.329 -      
   1.330 -      cout << "Es megvarjuk, amig megszunik a Builder...\n";
   1.331 -    }
   1.332 -    cout << "P.length() == " << P.length() << endl;
   1.333 -    check(P.length() == 5);
   1.334 -    cout << "P.from()==v2 ? " << (P.from()==v2) << endl;
   1.335 -    check(P.from() == v2);
   1.336 -
   1.337 -    cout << "Vegigiteralunk az eleken." << endl;
   1.338 -    typedef DPath::NodeIt NodeIt;
   1.339 -    typedef DPath::EdgeIt EdgeIt;
   1.340 -    EdgeIt e;
   1.341 -    int i=1;
   1.342 -    for(P.first(e); P.valid(e); P.next(e), ++i) {
   1.343 -      cout << i << ". el: " << e << endl;
   1.344 -    }
   1.345 -  }
   1.346  
   1.347    cout << (passed ? "All tests passed." : "Some of the tests failed!!!")
   1.348         << endl;