Created minlengthpaths_test.cc. Compiles with: g++-3.0 -Wall -I. -I../{klao,jacint,marci} -I.. -I../../include minlengthpaths_test.cc -o min | & less
authorathos
Tue, 04 May 2004 09:33:21 +0000
changeset 520e4a6300616f9
parent 519 474f5508e9a2
child 521 c360666e10e4
Created minlengthpaths_test.cc. Compiles with: g++-3.0 -Wall -I. -I../{klao,jacint,marci} -I.. -I../../include minlengthpaths_test.cc -o min | & less
src/work/athos/minlengthpaths.h
src/work/athos/minlengthpaths_test.cc
     1.1 --- a/src/work/athos/minlengthpaths.h	Tue May 04 09:03:00 2004 +0000
     1.2 +++ b/src/work/athos/minlengthpaths.h	Tue May 04 09:33:21 2004 +0000
     1.3 @@ -187,7 +187,7 @@
     1.4        typename DirPath::Builder B(p);
     1.5        for(typename std::vector<Edge>::iterator i=paths[j].begin(); 
     1.6  	  i!=paths[j].end(); ++i ){
     1.7 -	B.pushBack(*j);
     1.8 +	B.pushBack(*i);
     1.9        }
    1.10  
    1.11        B.commit();
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/src/work/athos/minlengthpaths_test.cc	Tue May 04 09:33:21 2004 +0000
     2.3 @@ -0,0 +1,92 @@
     2.4 +#include <iostream>
     2.5 +#include <list_graph.h>
     2.6 +#include <minlengthpaths.h>
     2.7 +#include <path.h>
     2.8 +
     2.9 +using namespace std;
    2.10 +using namespace hugo;
    2.11 +
    2.12 +
    2.13 +
    2.14 +bool passed = true;
    2.15 +
    2.16 +void check(bool rc, char *msg="") {
    2.17 +  passed = passed && rc;
    2.18 +  if(!rc) {
    2.19 +    std::cerr << "Test failed! ("<< msg << ")" << std::endl; \
    2.20 + 
    2.21 +
    2.22 +  }
    2.23 +}
    2.24 +
    2.25 +
    2.26 +
    2.27 +int main()
    2.28 +{
    2.29 +
    2.30 +  typedef ListGraph::Node Node;
    2.31 +  typedef ListGraph::Edge Edge;
    2.32 +
    2.33 +  ListGraph graph;
    2.34 +
    2.35 +  //Ahuja könyv példája
    2.36 +
    2.37 +  Node s=graph.addNode();
    2.38 +  Node v1=graph.addNode();  
    2.39 +  Node v2=graph.addNode();
    2.40 +  Node v3=graph.addNode();
    2.41 +  Node v4=graph.addNode();
    2.42 +  Node v5=graph.addNode();
    2.43 +  Node t=graph.addNode();
    2.44 +
    2.45 +  Edge s_v1=graph.addEdge(s, v1);
    2.46 +  Edge v1_v2=graph.addEdge(v1, v2);
    2.47 +  Edge s_v3=graph.addEdge(s, v3);
    2.48 +  Edge v2_v4=graph.addEdge(v2, v4);
    2.49 +  Edge v2_v5=graph.addEdge(v2, v5);
    2.50 +  Edge v3_v5=graph.addEdge(v3, v5);
    2.51 +  Edge v4_t=graph.addEdge(v4, t);
    2.52 +  Edge v5_t=graph.addEdge(v5, t);
    2.53 +  
    2.54 +
    2.55 +  ListGraph::EdgeMap<int> length(graph);
    2.56 +
    2.57 +  length.set(s_v1, 6);
    2.58 +  length.set(v1_v2, 4);
    2.59 +  length.set(s_v3, 10);
    2.60 +  length.set(v2_v4, 5);
    2.61 +  length.set(v2_v5, 1);
    2.62 +  length.set(v3_v5, 5);
    2.63 +  length.set(v4_t, 8);
    2.64 +  length.set(v5_t, 8);
    2.65 +
    2.66 +  std::cout << "Minlengthpaths algorithm test..." << std::endl;
    2.67 +
    2.68 +  
    2.69 +  int k=3;
    2.70 +  MinLengthPaths< ListGraph, ListGraph::EdgeMap<int> >
    2.71 +    surb_test(graph, length);
    2.72 +
    2.73 +  check(  surb_test.run(s,t,k) == 2 && surb_test.totalLength() == 46,"Two paths, total length should be 46");
    2.74 +
    2.75 +  typedef DirPath<ListGraph> DPath;
    2.76 +  DPath P(graph);
    2.77 +
    2.78 +  surb_test.getPath(P,0);
    2.79 +  check(P.length() == 4, "First path should contain 4 edges.");  
    2.80 +
    2.81 +  surb_test.getPath(P,1);
    2.82 +  check(P.length() == 3, "Second path: 3 edges.");
    2.83 +  
    2.84 +  k=1;
    2.85 +  check(  surb_test.run(s,t,k) == 1 && surb_test.totalLength() == 19,"One path, total length should be 19");
    2.86 + 
    2.87 +  surb_test.getPath(P,0);
    2.88 +  check(P.length() == 4, "First path should contain 4 edges.");  
    2.89 +
    2.90 +  cout << (passed ? "All tests passed." : "Some of the tests failed!!!")
    2.91 +       << endl;
    2.92 +
    2.93 +  return passed ? 0 : 1;
    2.94 +
    2.95 +}