test/path_test.cc
changeset 2251 37fa5f83251e
parent 1956 a055123339d5
child 2260 4274224f8a7d
equal deleted inserted replaced
3:95dbae8e3339 4:149868ce1bf3
    16  *
    16  *
    17  */
    17  */
    18 
    18 
    19 #include <string>
    19 #include <string>
    20 #include <iostream>
    20 #include <iostream>
       
    21 
    21 #include <lemon/concept/path.h>
    22 #include <lemon/concept/path.h>
       
    23 #include <lemon/concept/graph.h>
       
    24 
    22 #include <lemon/path.h>
    25 #include <lemon/path.h>
    23 #include <lemon/list_graph.h>
    26 #include <lemon/list_graph.h>
    24 
    27 
       
    28 #include "test_tools.h"
       
    29 
    25 using namespace std;
    30 using namespace std;
    26 using namespace lemon;
    31 using namespace lemon;
    27 using namespace lemon::concept;
       
    28 
    32 
    29 template<class Path> void checkCompilePath(Path &P) 
    33 void check_concepts() {
    30 {
    34   checkConcept<concept::Path<concept::Graph>, 
    31   typedef typename Path::EdgeIt EdgeIt;
    35     concept::Path<concept::Graph> >();
    32   typedef typename Path::NodeIt NodeIt;
    36   checkConcept<concept::Path<concept::Graph>, 
    33   typedef typename Path::GraphNode GraphNode;
    37     Path<concept::Graph> >();
    34   typedef typename Path::GraphEdge GraphEdge;
    38   checkConcept<concept::Path<ListGraph>, Path<ListGraph> >();
    35   //typedef typename Path::Builder Builder;
       
    36   //??? ha csinalok ilyet es siman Builderrel peldanyositok, akkor warningol. Talan friend miatt? De ki az?
       
    37 
       
    38   EdgeIt ei;
       
    39   NodeIt ni;
       
    40   GraphNode gn;
       
    41   GraphEdge ge;
       
    42 
       
    43   size_t st;
       
    44   bool b;
       
    45 
       
    46   //Path(const Graph &_G) {}      //the constructor has been already called
       
    47 
       
    48   st=P.length();                  //size_t length() const {return 0;}
       
    49   b=P.empty();                    //bool empty() const {}
       
    50   P.clear();                      //void clear() {}
       
    51 
       
    52   gn=P.target();                    //GraphNode/*It*/ target() const {return INVALID;}
       
    53   gn=P.source();                    //GraphNode/*It*/ source() const {return INVALID;}
       
    54 
       
    55   ei=P.first(ei);                 //It& first(It &i) const { return i=It(*this); }
       
    56 
       
    57   ni=P.target(ei);                  //NodeIt target(const EdgeIt& e) const {}
       
    58   ni=P.source(ei);                  //NodeIt source(const EdgeIt& e) const {}
       
    59 
       
    60 
       
    61   ListGraph lg;
       
    62   Path p(lg);
       
    63 
       
    64   EdgeIt i;	                  //EdgeIt() {}
       
    65   EdgeIt j(INVALID);	          //EdgeIt(Invalid) {}
       
    66   EdgeIt k(p);	                  //EdgeIt(const Path &_p) {}
       
    67 
       
    68   i=++j;	                  //EdgeIt& operator++() {}
       
    69   ++k;
       
    70   b=(i==j);	                  //bool operator==(const EdgeIt& e) const {return true;}
       
    71   b=(i!=j);	                  //bool operator!=(const EdgeIt& e) const {return true;}
       
    72 
       
    73 
       
    74   NodeIt l;                       //NodeIt() {}
       
    75   NodeIt m(INVALID);	          //NodeIt(Invalid) {}
       
    76   NodeIt n(p);	                  //NodeIt(const Path &_p) {}
       
    77 
       
    78   l=++m;                          //NodeIt& operator++() {}
       
    79   b=(m==n);                       //bool operator==(const NodeIt& e) const {}
       
    80   b=(m!=n);                   	  //bool operator!=(const NodeIt& e) const {}
       
    81 
       
    82   typename Path::Builder builder(p);     //Builder(Path &_P) : P(_P) {}
       
    83   builder.setStartNode(gn);     	 //void setStartNode(const GraphNode &) {}
       
    84   builder.pushFront(ge);	         //void pushFront(const GraphEdge& e) {}
       
    85   builder.pushBack(ge);	                 //void pushBack(const GraphEdge& e) {}
       
    86   builder.commit();	                 //void commit() {}
       
    87   builder.reserveFront(st);	         //void reserveFront(size_t r) {}
       
    88   builder.reserveBack(st);	         //void reserveBack(size_t r) {}
       
    89 
       
    90 }
    39 }
    91 
    40 
    92 template void checkCompilePath< concept::Path<ListGraph> >(concept::Path<ListGraph> &);
    41 int main() {
    93 template void checkCompilePath< DirPath<ListGraph> >(DirPath<ListGraph> &);
    42   check_concepts();
    94 template void checkCompilePath< UPath<ListGraph> >(UPath<ListGraph> &);
    43   
       
    44   ListGraph g;
       
    45   
       
    46   ListGraph::Node n1 = g.addNode();
       
    47   ListGraph::Node n2 = g.addNode();
       
    48   ListGraph::Node n3 = g.addNode();
       
    49   ListGraph::Node n4 = g.addNode();
       
    50   ListGraph::Node n5 = g.addNode();
       
    51  
       
    52   ListGraph::Edge e1 = g.addEdge(n1, n2);
       
    53   ListGraph::Edge e2 = g.addEdge(n2, n3);
       
    54   ListGraph::Edge e3 = g.addEdge(n3, n4);
       
    55   ListGraph::Edge e4 = g.addEdge(n4, n5);
       
    56   ListGraph::Edge e5 = g.addEdge(n5, n1);
    95 
    57 
    96 int main() 
    58   {
    97 {
    59     Path<ListGraph> p(g);
       
    60 
       
    61     check(p.empty(), "Wrong Path");
       
    62     check(p.length() == 0, "Wrong Path");
       
    63     
       
    64     {
       
    65       Path<ListGraph>::Builder b(p);
       
    66       b.setStartNode(n3);
       
    67       b.commit();
       
    68     }
       
    69 
       
    70     check(!p.empty(), "Wrong Path");
       
    71     check(p.length() == 0, "Wrong Path");
       
    72     check(p.source() == n3, "Wrong Path");
       
    73     check(p.target() == n3, "Wrong Path");
       
    74 
       
    75     {
       
    76       Path<ListGraph>::Builder b(p);
       
    77       b.pushBack(e3);
       
    78       b.pushBack(e4);
       
    79       b.pushFront(e2);
       
    80       b.commit();
       
    81     }
       
    82 
       
    83     check(!p.empty(), "Wrong Path");
       
    84     check(p.length() == 3, "Wrong Path");
       
    85     check(p.source() == n2, "Wrong Path");
       
    86     check(p.target() == n5, "Wrong Path");
       
    87     
       
    88     {
       
    89       Path<ListGraph>::NodeIt it(p);
       
    90       check((ListGraph::Node)it == n2, "Wrong Path"); ++it;
       
    91       check((ListGraph::Node)it == n3, "Wrong Path"); ++it;
       
    92       check((ListGraph::Node)it == n4, "Wrong Path"); ++it;
       
    93       check((ListGraph::Node)it == n5, "Wrong Path"); ++it;
       
    94       check((ListGraph::Node)it == INVALID, "Wrong Path");
       
    95     }
       
    96 
       
    97     {
       
    98       Path<ListGraph>::EdgeIt it(p);
       
    99       check((ListGraph::Edge)it == e2, "Wrong Path"); ++it;
       
   100       check((ListGraph::Edge)it == e3, "Wrong Path"); ++it;
       
   101       check((ListGraph::Edge)it == e4, "Wrong Path"); ++it;
       
   102       check((ListGraph::Edge)it == INVALID, "Wrong Path");
       
   103     }
       
   104     
       
   105   }
       
   106   
       
   107   return 0;
    98 }
   108 }