test/bpgraph_test.cc
changeset 1024 b84e68af8248
parent 1020 5ef0ab7b61cd
child 1025 c8fa41fcc4a7
equal deleted inserted replaced
2:f8027b3b5079 3:06f6199470e0
    15  * purpose.
    15  * purpose.
    16  *
    16  *
    17  */
    17  */
    18 
    18 
    19 #include <lemon/concepts/bpgraph.h>
    19 #include <lemon/concepts/bpgraph.h>
    20 //#include <lemon/list_graph.h>
    20 #include <lemon/list_graph.h>
    21 #include <lemon/smart_graph.h>
    21 #include <lemon/smart_graph.h>
    22 #include <lemon/full_graph.h>
    22 #include <lemon/full_graph.h>
    23 
    23 
    24 #include "test_tools.h"
    24 #include "test_tools.h"
    25 #include "graph_test.h"
    25 #include "graph_test.h"
   105   checkGraphBlueMap(G);
   105   checkGraphBlueMap(G);
   106   checkGraphArcMap(G);
   106   checkGraphArcMap(G);
   107   checkGraphEdgeMap(G);
   107   checkGraphEdgeMap(G);
   108 }
   108 }
   109 
   109 
   110 template <class Graph>
   110 template <class BpGraph>
       
   111 void checkBpGraphErase() {
       
   112   TEMPLATE_BPGRAPH_TYPEDEFS(BpGraph);
       
   113 
       
   114   BpGraph G;
       
   115   Node
       
   116     n1 = G.addRedNode(), n2 = G.addBlueNode(),
       
   117     n3 = G.addBlueNode(), n4 = G.addRedNode();
       
   118   Edge
       
   119     e1 = G.addEdge(n1, n2), e2 = G.addEdge(n1, n3),
       
   120     e3 = G.addEdge(n4, n2), e4 = G.addEdge(n4, n3);
       
   121 
       
   122   // Check edge deletion
       
   123   G.erase(e2);
       
   124 
       
   125   checkGraphNodeList(G, 4);
       
   126   checkGraphRedNodeList(G, 2);
       
   127   checkGraphBlueNodeList(G, 2);
       
   128   checkGraphEdgeList(G, 3);
       
   129   checkGraphArcList(G, 6);
       
   130 
       
   131   checkGraphIncEdgeArcLists(G, n1, 1);
       
   132   checkGraphIncEdgeArcLists(G, n2, 2);
       
   133   checkGraphIncEdgeArcLists(G, n3, 1);
       
   134   checkGraphIncEdgeArcLists(G, n4, 2);
       
   135 
       
   136   checkGraphConEdgeList(G, 3);
       
   137   checkGraphConArcList(G, 6);
       
   138 
       
   139   // Check node deletion
       
   140   G.erase(n3);
       
   141 
       
   142   checkGraphNodeList(G, 3);
       
   143   checkGraphRedNodeList(G, 2);
       
   144   checkGraphBlueNodeList(G, 1);
       
   145   checkGraphEdgeList(G, 2);
       
   146   checkGraphArcList(G, 4);
       
   147 
       
   148   checkGraphIncEdgeArcLists(G, n1, 1);
       
   149   checkGraphIncEdgeArcLists(G, n2, 2);
       
   150   checkGraphIncEdgeArcLists(G, n4, 1);
       
   151 
       
   152   checkGraphConEdgeList(G, 2);
       
   153   checkGraphConArcList(G, 4);
       
   154 
       
   155 }
       
   156 
       
   157 template <class BpGraph>
       
   158 void checkBpGraphAlter() {
       
   159   TEMPLATE_BPGRAPH_TYPEDEFS(BpGraph);
       
   160 
       
   161   BpGraph G;
       
   162   Node
       
   163     n1 = G.addRedNode(), n2 = G.addBlueNode(),
       
   164     n3 = G.addBlueNode(), n4 = G.addRedNode();
       
   165   Edge
       
   166     e1 = G.addEdge(n1, n2), e2 = G.addEdge(n1, n3),
       
   167     e3 = G.addEdge(n4, n2), e4 = G.addEdge(n4, n3);
       
   168 
       
   169   G.changeRed(e2, n4);
       
   170   check(G.redNode(e2) == n4, "Wrong red node");
       
   171   check(G.blueNode(e2) == n3, "Wrong blue node");
       
   172 
       
   173   checkGraphNodeList(G, 4);
       
   174   checkGraphRedNodeList(G, 2);
       
   175   checkGraphBlueNodeList(G, 2);
       
   176   checkGraphEdgeList(G, 4);
       
   177   checkGraphArcList(G, 8);
       
   178 
       
   179   checkGraphIncEdgeArcLists(G, n1, 1);
       
   180   checkGraphIncEdgeArcLists(G, n2, 2);
       
   181   checkGraphIncEdgeArcLists(G, n3, 2);
       
   182   checkGraphIncEdgeArcLists(G, n4, 3);
       
   183 
       
   184   checkGraphConEdgeList(G, 4);
       
   185   checkGraphConArcList(G, 8);
       
   186 
       
   187   G.changeBlue(e2, n2);
       
   188   check(G.redNode(e2) == n4, "Wrong red node");
       
   189   check(G.blueNode(e2) == n2, "Wrong blue node");
       
   190 
       
   191   checkGraphNodeList(G, 4);
       
   192   checkGraphRedNodeList(G, 2);
       
   193   checkGraphBlueNodeList(G, 2);
       
   194   checkGraphEdgeList(G, 4);
       
   195   checkGraphArcList(G, 8);
       
   196 
       
   197   checkGraphIncEdgeArcLists(G, n1, 1);
       
   198   checkGraphIncEdgeArcLists(G, n2, 3);
       
   199   checkGraphIncEdgeArcLists(G, n3, 1);
       
   200   checkGraphIncEdgeArcLists(G, n4, 3);
       
   201 
       
   202   checkGraphConEdgeList(G, 4);
       
   203   checkGraphConArcList(G, 8);
       
   204 }
       
   205 
       
   206 
       
   207 template <class BpGraph>
   111 void checkBpGraphSnapshot() {
   208 void checkBpGraphSnapshot() {
   112   TEMPLATE_BPGRAPH_TYPEDEFS(Graph);
   209   TEMPLATE_BPGRAPH_TYPEDEFS(BpGraph);
   113 
   210 
   114   Graph G;
   211   BpGraph G;
   115   Node 
   212   Node 
   116     n1 = G.addRedNode(),
   213     n1 = G.addRedNode(),
   117     n2 = G.addBlueNode(),
   214     n2 = G.addBlueNode(),
   118     n3 = G.addBlueNode();
   215     n3 = G.addBlueNode();
   119   Edge 
   216   Edge 
   124   checkGraphRedNodeList(G, 1);
   221   checkGraphRedNodeList(G, 1);
   125   checkGraphBlueNodeList(G, 2);
   222   checkGraphBlueNodeList(G, 2);
   126   checkGraphEdgeList(G, 2);
   223   checkGraphEdgeList(G, 2);
   127   checkGraphArcList(G, 4);
   224   checkGraphArcList(G, 4);
   128 
   225 
   129   typename Graph::Snapshot snapshot(G);
   226   typename BpGraph::Snapshot snapshot(G);
   130 
   227 
   131   Node n4 = G.addRedNode();
   228   Node n4 = G.addRedNode();
   132   G.addEdge(n4, n2);
   229   G.addEdge(n4, n2);
   133   G.addEdge(n4, n3);
   230   G.addEdge(n4, n3);
   134 
   231 
   188   checkGraphBlueNodeList(G, 2);
   285   checkGraphBlueNodeList(G, 2);
   189   checkGraphEdgeList(G, 2);
   286   checkGraphEdgeList(G, 2);
   190   checkGraphArcList(G, 4);
   287   checkGraphArcList(G, 4);
   191 }
   288 }
   192 
   289 
   193 template <typename Graph>
   290 template <typename BpGraph>
   194 void checkBpGraphValidity() {
   291 void checkBpGraphValidity() {
   195   TEMPLATE_GRAPH_TYPEDEFS(Graph);
   292   TEMPLATE_BPGRAPH_TYPEDEFS(BpGraph);
   196   Graph g;
   293   BpGraph g;
   197 
   294 
   198   Node
   295   Node
   199     n1 = g.addRedNode(),
   296     n1 = g.addRedNode(),
   200     n2 = g.addBlueNode(),
   297     n2 = g.addBlueNode(),
   201     n3 = g.addBlueNode();
   298     n3 = g.addBlueNode();
   323   }
   420   }
   324 
   421 
   325 }
   422 }
   326 
   423 
   327 void checkGraphs() {
   424 void checkGraphs() {
       
   425   { // Checking ListGraph
       
   426     checkBpGraphBuild<ListBpGraph>();
       
   427     checkBpGraphErase<ListBpGraph>();
       
   428     checkBpGraphAlter<ListBpGraph>();
       
   429     checkBpGraphSnapshot<ListBpGraph>();
       
   430     checkBpGraphValidity<ListBpGraph>();
       
   431   }
   328   { // Checking SmartGraph
   432   { // Checking SmartGraph
   329     checkBpGraphBuild<SmartBpGraph>();
   433     checkBpGraphBuild<SmartBpGraph>();
   330     checkBpGraphSnapshot<SmartBpGraph>();
   434     checkBpGraphSnapshot<SmartBpGraph>();
   331     checkBpGraphValidity<SmartBpGraph>();
   435     checkBpGraphValidity<SmartBpGraph>();
   332   }
   436   }