test/digraph_test.cc
changeset 782 ceb2756dea2a
parent 777 5764dd9b6e18
parent 740 819ca5b50de0
child 877 141f9c0db4a3
     1.1 --- a/test/digraph_test.cc	Mon Sep 28 15:53:20 2009 +0200
     1.2 +++ b/test/digraph_test.cc	Thu Nov 05 10:27:17 2009 +0100
     1.3 @@ -19,6 +19,7 @@
     1.4  #include <lemon/concepts/digraph.h>
     1.5  #include <lemon/list_graph.h>
     1.6  #include <lemon/smart_graph.h>
     1.7 +#include <lemon/static_graph.h>
     1.8  #include <lemon/full_graph.h>
     1.9  
    1.10  #include "test_tools.h"
    1.11 @@ -35,6 +36,9 @@
    1.12    checkGraphNodeList(G, 0);
    1.13    checkGraphArcList(G, 0);
    1.14  
    1.15 +  G.reserveNode(3);
    1.16 +  G.reserveArc(4);
    1.17 +
    1.18    Node
    1.19      n1 = G.addNode(),
    1.20      n2 = G.addNode(),
    1.21 @@ -283,6 +287,14 @@
    1.22    G.addArc(G.addNode(), G.addNode());
    1.23  
    1.24    snapshot.restore();
    1.25 +  snapshot.save(G);
    1.26 +
    1.27 +  checkGraphNodeList(G, 4);
    1.28 +  checkGraphArcList(G, 4);
    1.29 +
    1.30 +  G.addArc(G.addNode(), G.addNode());
    1.31 +
    1.32 +  snapshot.restore();
    1.33  
    1.34    checkGraphNodeList(G, 4);
    1.35    checkGraphArcList(G, 4);
    1.36 @@ -317,6 +329,10 @@
    1.37      checkConcept<ExtendableDigraphComponent<>, SmartDigraph>();
    1.38      checkConcept<ClearableDigraphComponent<>, SmartDigraph>();
    1.39    }
    1.40 +  { // Checking StaticDigraph
    1.41 +    checkConcept<Digraph, StaticDigraph>();
    1.42 +    checkConcept<ClearableDigraphComponent<>, StaticDigraph>();
    1.43 +  }
    1.44    { // Checking FullDigraph
    1.45      checkConcept<Digraph, FullDigraph>();
    1.46    }
    1.47 @@ -372,10 +388,122 @@
    1.48    check(!g.valid(g.arcFromId(-1)), "Wrong validity check");
    1.49  }
    1.50  
    1.51 +void checkStaticDigraph() {
    1.52 +  SmartDigraph g;
    1.53 +  SmartDigraph::NodeMap<StaticDigraph::Node> nref(g);
    1.54 +  SmartDigraph::ArcMap<StaticDigraph::Arc> aref(g);
    1.55 +  
    1.56 +  StaticDigraph G;
    1.57 +  
    1.58 +  checkGraphNodeList(G, 0);
    1.59 +  checkGraphArcList(G, 0);
    1.60 +
    1.61 +  G.build(g, nref, aref);
    1.62 +
    1.63 +  checkGraphNodeList(G, 0);
    1.64 +  checkGraphArcList(G, 0);
    1.65 +
    1.66 +  SmartDigraph::Node
    1.67 +    n1 = g.addNode(),
    1.68 +    n2 = g.addNode(),
    1.69 +    n3 = g.addNode();
    1.70 +
    1.71 +  G.build(g, nref, aref);
    1.72 +
    1.73 +  checkGraphNodeList(G, 3);
    1.74 +  checkGraphArcList(G, 0);
    1.75 +
    1.76 +  SmartDigraph::Arc a1 = g.addArc(n1, n2);
    1.77 +
    1.78 +  G.build(g, nref, aref);
    1.79 +
    1.80 +  check(G.source(aref[a1]) == nref[n1] && G.target(aref[a1]) == nref[n2],
    1.81 +        "Wrong arc or wrong references");
    1.82 +  checkGraphNodeList(G, 3);
    1.83 +  checkGraphArcList(G, 1);
    1.84 +
    1.85 +  checkGraphOutArcList(G, nref[n1], 1);
    1.86 +  checkGraphOutArcList(G, nref[n2], 0);
    1.87 +  checkGraphOutArcList(G, nref[n3], 0);
    1.88 +
    1.89 +  checkGraphInArcList(G, nref[n1], 0);
    1.90 +  checkGraphInArcList(G, nref[n2], 1);
    1.91 +  checkGraphInArcList(G, nref[n3], 0);
    1.92 +
    1.93 +  checkGraphConArcList(G, 1);
    1.94 +
    1.95 +  SmartDigraph::Arc
    1.96 +    a2 = g.addArc(n2, n1),
    1.97 +    a3 = g.addArc(n2, n3),
    1.98 +    a4 = g.addArc(n2, n3);
    1.99 +
   1.100 +  digraphCopy(g, G).nodeRef(nref).run();
   1.101 +
   1.102 +  checkGraphNodeList(G, 3);
   1.103 +  checkGraphArcList(G, 4);
   1.104 +
   1.105 +  checkGraphOutArcList(G, nref[n1], 1);
   1.106 +  checkGraphOutArcList(G, nref[n2], 3);
   1.107 +  checkGraphOutArcList(G, nref[n3], 0);
   1.108 +
   1.109 +  checkGraphInArcList(G, nref[n1], 1);
   1.110 +  checkGraphInArcList(G, nref[n2], 1);
   1.111 +  checkGraphInArcList(G, nref[n3], 2);
   1.112 +
   1.113 +  checkGraphConArcList(G, 4);
   1.114 +
   1.115 +  std::vector<std::pair<int,int> > arcs;
   1.116 +  arcs.push_back(std::make_pair(0,1));
   1.117 +  arcs.push_back(std::make_pair(0,2));
   1.118 +  arcs.push_back(std::make_pair(1,3));
   1.119 +  arcs.push_back(std::make_pair(1,2));
   1.120 +  arcs.push_back(std::make_pair(3,0));
   1.121 +  arcs.push_back(std::make_pair(3,3));
   1.122 +  arcs.push_back(std::make_pair(4,2));
   1.123 +  arcs.push_back(std::make_pair(4,3));
   1.124 +  arcs.push_back(std::make_pair(4,1));
   1.125 +
   1.126 +  G.build(6, arcs.begin(), arcs.end());
   1.127 +  
   1.128 +  checkGraphNodeList(G, 6);
   1.129 +  checkGraphArcList(G, 9);
   1.130 +
   1.131 +  checkGraphOutArcList(G, G.node(0), 2);
   1.132 +  checkGraphOutArcList(G, G.node(1), 2);
   1.133 +  checkGraphOutArcList(G, G.node(2), 0);
   1.134 +  checkGraphOutArcList(G, G.node(3), 2);
   1.135 +  checkGraphOutArcList(G, G.node(4), 3);
   1.136 +  checkGraphOutArcList(G, G.node(5), 0);
   1.137 +
   1.138 +  checkGraphInArcList(G, G.node(0), 1);
   1.139 +  checkGraphInArcList(G, G.node(1), 2);
   1.140 +  checkGraphInArcList(G, G.node(2), 3);
   1.141 +  checkGraphInArcList(G, G.node(3), 3);
   1.142 +  checkGraphInArcList(G, G.node(4), 0);
   1.143 +  checkGraphInArcList(G, G.node(5), 0);
   1.144 +
   1.145 +  checkGraphConArcList(G, 9);
   1.146 +
   1.147 +  checkNodeIds(G);
   1.148 +  checkArcIds(G);
   1.149 +  checkGraphNodeMap(G);
   1.150 +  checkGraphArcMap(G);
   1.151 +  
   1.152 +  int n = G.nodeNum();
   1.153 +  int m = G.arcNum();
   1.154 +  check(G.index(G.node(n-1)) == n-1, "Wrong index.");
   1.155 +  check(G.index(G.arc(m-1)) == m-1, "Wrong index.");
   1.156 +}
   1.157 +
   1.158  void checkFullDigraph(int num) {
   1.159    typedef FullDigraph Digraph;
   1.160    DIGRAPH_TYPEDEFS(Digraph);
   1.161 +
   1.162    Digraph G(num);
   1.163 +  check(G.nodeNum() == num && G.arcNum() == num * num, "Wrong size");
   1.164 +
   1.165 +  G.resize(num);
   1.166 +  check(G.nodeNum() == num && G.arcNum() == num * num, "Wrong size");
   1.167  
   1.168    checkGraphNodeList(G, num);
   1.169    checkGraphArcList(G, num * num);
   1.170 @@ -419,6 +547,9 @@
   1.171      checkDigraphSnapshot<SmartDigraph>();
   1.172      checkDigraphValidity<SmartDigraph>();
   1.173    }
   1.174 +  { // Checking StaticDigraph
   1.175 +    checkStaticDigraph();
   1.176 +  }
   1.177    { // Checking FullDigraph
   1.178      checkFullDigraph(8);
   1.179    }