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