src/test/graph_test.cc
changeset 565 18787f6db0db
parent 550 9e7613fa6d27
child 567 efaa79ee8d14
equal deleted inserted replaced
4:b214fb62ac29 5:70bdc65e269f
     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<../work/alpar/list_graph.h>
     4 //#include<../work/alpar/list_graph.h>
     5 
     5 
     6 /*
     6 /*
     7 This test makes consistency checks of list graph structures.
     7 This test makes consistency checks of list graph structures.
     8 
     8 
   170     m=dm; //Copy to another type
   170     m=dm; //Copy to another type
   171   }
   171   }
   172   
   172   
   173 }
   173 }
   174 
   174 
   175 
   175 template<class Graph> struct PetNodes
   176 
       
   177 template<class Graph> void addPetersen(Graph &G)
       
   178 {
   176 {
   179   std::vector<typename Graph::Node> outer, inner;
   177   std::vector<typename Graph::Node> outer, inner;
   180   
   178   std::vector<typename Graph::Edge> outcir, incir, cons;
   181   for(int i=0;i<5;i++) {
   179 };
   182     outer.push_back(G.addNode());
   180 
   183     inner.push_back(G.addNode());
   181 template<class Graph> PetNodes<Graph> addPetersen(Graph &G,int num=5)
   184   }
   182 {
   185 
   183   //std::vector<typename Graph::Node> outer, inner;
   186  for(int i=0;i<5;i++) {
   184   
   187     G.addEdge(outer[i],inner[i]);
   185   PetNodes<Graph> n;
   188     G.addEdge(outer[i],outer[(i+1)%5]);
   186 
   189     G.addEdge(inner[i],inner[(i+2)%5]);
   187   for(int i=0;i<num;i++) {
   190   }
   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;
   191 }
   198 }
   192 
   199 
   193 template<class Graph> void checkNodeList(Graph &G, int nn)
   200 template<class Graph> void checkNodeList(Graph &G, int nn)
   194 {
   201 {
   195   typename Graph::NodeIt n(G);
   202   typename Graph::NodeIt n(G);
   267     checkOutEdgeList(G,n,3);
   274     checkOutEdgeList(G,n,3);
   268     G.next(n);
   275     G.next(n);
   269   }  
   276   }  
   270 }
   277 }
   271 
   278 
   272 //template void checkCompile<GraphSkeleton>(GraphSkeleton &);
   279 template void checkCompile<GraphSkeleton>(GraphSkeleton &);
   273 template void checkCompile<SmartGraph>(SmartGraph &);
   280 template void checkCompile<SmartGraph>(SmartGraph &);
   274 template void checkCompile<SymSmartGraph>(SymSmartGraph &);
   281 template void checkCompile<SymSmartGraph>(SymSmartGraph &);
   275 //template void checkCompile<ListGraph>(ListGraph &);
   282 //template void checkCompile<ListGraph>(ListGraph &);
   276 //template void checkCompile<SymListGraph>(SymListGraph &);
   283 //template void checkCompile<SymListGraph>(SymListGraph &);
   277 
   284 
   284     SmartGraph G;
   291     SmartGraph G;
   285     addPetersen(G);
   292     addPetersen(G);
   286     bidirPetersen(G);
   293     bidirPetersen(G);
   287     checkPetersen(G);
   294     checkPetersen(G);
   288   }
   295   }
   289   {
   296 //   {
   290     ListGraph G;
   297 //     ListGraph G;
   291     addPetersen(G);
   298 //     addPetersen(G);
   292     bidirPetersen(G);
   299 //     bidirPetersen(G);
   293     checkPetersen(G);
   300 //     checkPetersen(G);
   294   }
   301 //   }
   295   {
   302   {
   296     SymSmartGraph G;
   303     SymSmartGraph G;
   297     addPetersen(G);
   304     addPetersen(G);
   298     checkPetersen(G);
   305     checkPetersen(G);
   299   }
   306   }
   300   {
   307 //   {
   301     SymListGraph G;
   308 //     SymListGraph G;
   302     addPetersen(G);
   309 //     addPetersen(G);
   303     checkPetersen(G);
   310 //     checkPetersen(G);
   304   }
   311 //   }
   305 
   312 
   306   //\todo map tests.
   313   //\todo map tests.
   307   //\todo copy constr tests.
   314   //\todo copy constr tests.
   308 
   315 
   309   std::cout << __FILE__ ": All tests passed.\n";
   316   std::cout << __FILE__ ": All tests passed.\n";