src/test/minlengthpaths_test.cc
changeset 521 c360666e10e4
parent 517 1380377682ab
equal deleted inserted replaced
0:1569dada717b -1:000000000000
     1 #include <iostream>
       
     2 #include <list_graph.h>
       
     3 #include <minlengthpaths.h>
       
     4 using namespace std;
       
     5 using namespace hugo;
       
     6 
       
     7 
       
     8 
       
     9 int main()
       
    10 {
       
    11 
       
    12   
       
    13 
       
    14 bool passed = true;
       
    15 
       
    16 void check(bool rc, char *msg="") {
       
    17   passed = passed && rc;
       
    18   if(!rc) {
       
    19     std::cerr << "Test failed! ("<< msg << ")" << std::endl; \
       
    20  
       
    21 
       
    22   }
       
    23 }
       
    24 
       
    25 
       
    26 
       
    27 int main()
       
    28 {
       
    29 
       
    30   typedef ListGraph::Node Node;
       
    31   typedef ListGraph::Edge Edge;
       
    32 
       
    33   ListGraph graph;
       
    34 
       
    35   //Ahuja könyv példája
       
    36 
       
    37   Node s=graph.addNode();
       
    38   Node v2=graph.addNode();
       
    39   Node v3=graph.addNode();
       
    40   Node v4=graph.addNode();
       
    41   Node v5=graph.addNode();
       
    42   Node t=graph.addNode();
       
    43 
       
    44   Edge s_v2=graph.addEdge(s, v2);
       
    45   Edge s_v3=graph.addEdge(s, v3);
       
    46   Edge v2_v4=graph.addEdge(v2, v4);
       
    47   Edge v2_v5=graph.addEdge(v2, v5);
       
    48   Edge v3_v5=graph.addEdge(v3, v5);
       
    49   Edge v4_t=graph.addEdge(v4, t);
       
    50   Edge v5_t=graph.addEdge(v5, t);
       
    51   
       
    52 
       
    53   ListGraph::EdgeMap<int> length(graph);
       
    54 
       
    55   length.set(s_v2, 10);
       
    56   length.set(s_v3, 10);
       
    57   length.set(v2_v4, 5);
       
    58   length.set(v2_v5, 1);
       
    59   length.set(v3_v5, 5);
       
    60   length.set(v4_t, 8);
       
    61   length.set(v5_t, 8);
       
    62 
       
    63   std::cout << "Minlengthpaths algorithm test..." << std::endl;
       
    64 
       
    65   
       
    66   int k=3;
       
    67   MinLengthPaths<ListGraph, ListGraph::EdgeMap<int> >
       
    68     surb_test(graph, length);
       
    69 
       
    70   check(  surb_test.run(s,t,k) == 2 && suurb_test.totalLength == 46,"Two paths, total length should be 46");
       
    71 
       
    72   k=1;
       
    73   check(  surb_test.run(s,t,k) == 1 && suurb_test.totalLength == 19,"One path, total length should be 19");
       
    74 
       
    75   cout << (passed ? "All tests passed." : "Some of the tests failed!!!")
       
    76        << endl;
       
    77 
       
    78   return passed ? 0 : 1;
       
    79 
       
    80 }