src/test/graph_test.cc
changeset 571 9632ea8be6ca
parent 564 f84611a14a33
child 578 159f1cbf8a45
equal deleted inserted replaced
5:70bdc65e269f 6:54de831ab9b4
     1 #include<iostream>
     1 #include<iostream>
     2 #include<hugo/smart_graph.h>
     2 #include<hugo/smart_graph.h>
     3 #include<hugo/skeletons/graph.h>
     3 #include<hugo/skeletons/graph.h>
       
     4 #include"test_tools.h"
       
     5 
     4 //#include<../work/alpar/list_graph.h>
     6 //#include<../work/alpar/list_graph.h>
     5 
     7 
     6 /*
     8 /*
     7 This test makes consistency checks of list graph structures.
     9 This test makes consistency checks of list graph structures.
     8 
    10 
     9 G.addNode(), G.addEdge(), G.valid(), G.tail(), G.head()
    11 G.addNode(), G.addEdge(), G.valid(), G.tail(), G.head()
    10 
    12 
    11 */
    13 */
    12 
    14 
    13 using namespace hugo;
    15 using namespace hugo;
    14 
       
    15 // void check(bool rc, const char *msg) {
       
    16 //   if(!rc) {
       
    17 //     std::cerr << msg << std::endl;
       
    18 //     exit(1);
       
    19 //   }
       
    20 // }
       
    21 
       
    22 #define check(rc, msg) \
       
    23   if(!rc) { \
       
    24     std::cerr << __FILE__ ":" << __LINE__ << ": error: " << msg << std::endl; \
       
    25     exit(1); \
       
    26   } else { } \
       
    27 
       
    28 
    16 
    29 template<class Graph> void checkCompile(Graph &G) 
    17 template<class Graph> void checkCompile(Graph &G) 
    30 {
    18 {
    31   typedef typename Graph::Node Node;
    19   typedef typename Graph::Node Node;
    32   typedef typename Graph::NodeIt NodeIt;
    20   typedef typename Graph::NodeIt NodeIt;
   170     m=dm; //Copy to another type
   158     m=dm; //Copy to another type
   171   }
   159   }
   172   
   160   
   173 }
   161 }
   174 
   162 
   175 template<class Graph> struct PetNodes
       
   176 {
       
   177   std::vector<typename Graph::Node> outer, inner;
       
   178   std::vector<typename Graph::Edge> outcir, incir, cons;
       
   179 };
       
   180 
       
   181 template<class Graph> PetNodes<Graph> addPetersen(Graph &G,int num=5)
       
   182 {
       
   183   //std::vector<typename Graph::Node> outer, inner;
       
   184   
       
   185   PetNodes<Graph> n;
       
   186 
       
   187   for(int i=0;i<num;i++) {
       
   188     n.outer.push_back(G.addNode());
       
   189     n.inner.push_back(G.addNode());
       
   190   }
       
   191 
       
   192  for(int i=0;i<num;i++) {
       
   193    n.cons.push_back(G.addEdge(n.outer[i],n.inner[i]));
       
   194    n.outcir.push_back(G.addEdge(n.outer[i],n.outer[(i+1)%5]));
       
   195    n.incir.push_back(G.addEdge(n.inner[i],n.inner[(i+2)%5]));
       
   196   }
       
   197  return n;
       
   198 }
       
   199 
       
   200 template<class Graph> void checkNodeList(Graph &G, int nn)
   163 template<class Graph> void checkNodeList(Graph &G, int nn)
   201 {
   164 {
   202   typename Graph::NodeIt n(G);
   165   typename Graph::NodeIt n(G);
   203   for(int i=0;i<nn;i++) {
   166   for(int i=0;i<nn;i++) {
   204     check(G.valid(n),"Wrong Node list linking.");
   167     check(G.valid(n),"Wrong Node list linking.");