athos@520: #include <iostream>
athos@520: #include <list_graph.h>
athos@520: #include <minlengthpaths.h>
athos@520: #include <path.h>
athos@520: 
athos@520: using namespace std;
athos@520: using namespace hugo;
athos@520: 
athos@520: 
athos@520: 
athos@520: bool passed = true;
athos@520: 
athos@520: void check(bool rc, char *msg="") {
athos@520:   passed = passed && rc;
athos@520:   if(!rc) {
athos@520:     std::cerr << "Test failed! ("<< msg << ")" << std::endl; \
athos@520:  
athos@520: 
athos@520:   }
athos@520: }
athos@520: 
athos@520: 
athos@520: 
athos@520: int main()
athos@520: {
athos@520: 
athos@520:   typedef ListGraph::Node Node;
athos@520:   typedef ListGraph::Edge Edge;
athos@520: 
athos@520:   ListGraph graph;
athos@520: 
athos@520:   //Ahuja könyv példája
athos@520: 
athos@520:   Node s=graph.addNode();
athos@520:   Node v1=graph.addNode();  
athos@520:   Node v2=graph.addNode();
athos@520:   Node v3=graph.addNode();
athos@520:   Node v4=graph.addNode();
athos@520:   Node v5=graph.addNode();
athos@520:   Node t=graph.addNode();
athos@520: 
athos@520:   Edge s_v1=graph.addEdge(s, v1);
athos@520:   Edge v1_v2=graph.addEdge(v1, v2);
athos@520:   Edge s_v3=graph.addEdge(s, v3);
athos@520:   Edge v2_v4=graph.addEdge(v2, v4);
athos@520:   Edge v2_v5=graph.addEdge(v2, v5);
athos@520:   Edge v3_v5=graph.addEdge(v3, v5);
athos@520:   Edge v4_t=graph.addEdge(v4, t);
athos@520:   Edge v5_t=graph.addEdge(v5, t);
athos@520:   
athos@520: 
athos@520:   ListGraph::EdgeMap<int> length(graph);
athos@520: 
athos@520:   length.set(s_v1, 6);
athos@520:   length.set(v1_v2, 4);
athos@520:   length.set(s_v3, 10);
athos@520:   length.set(v2_v4, 5);
athos@520:   length.set(v2_v5, 1);
athos@520:   length.set(v3_v5, 5);
athos@520:   length.set(v4_t, 8);
athos@520:   length.set(v5_t, 8);
athos@520: 
athos@520:   std::cout << "Minlengthpaths algorithm test..." << std::endl;
athos@520: 
athos@520:   
athos@520:   int k=3;
athos@520:   MinLengthPaths< ListGraph, ListGraph::EdgeMap<int> >
athos@520:     surb_test(graph, length);
athos@520: 
athos@520:   check(  surb_test.run(s,t,k) == 2 && surb_test.totalLength() == 46,"Two paths, total length should be 46");
athos@520: 
athos@520:   typedef DirPath<ListGraph> DPath;
athos@520:   DPath P(graph);
athos@520: 
athos@520:   surb_test.getPath(P,0);
athos@520:   check(P.length() == 4, "First path should contain 4 edges.");  
athos@520: 
athos@520:   surb_test.getPath(P,1);
athos@520:   check(P.length() == 3, "Second path: 3 edges.");
athos@520:   
athos@520:   k=1;
athos@520:   check(  surb_test.run(s,t,k) == 1 && surb_test.totalLength() == 19,"One path, total length should be 19");
athos@520:  
athos@520:   surb_test.getPath(P,0);
athos@520:   check(P.length() == 4, "First path should contain 4 edges.");  
athos@520: 
athos@520:   cout << (passed ? "All tests passed." : "Some of the tests failed!!!")
athos@520:        << endl;
athos@520: 
athos@520:   return passed ? 0 : 1;
athos@520: 
athos@520: }