test/graph_utils_test.cc
branch1.0
changeset 320 12626fc94ccf
parent 220 a5d8c039f218
equal deleted inserted replaced
4:b036c89bb785 5:b0ff80081e22
    33 void checkFindArcs() {
    33 void checkFindArcs() {
    34   TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
    34   TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
    35 
    35 
    36   {
    36   {
    37     Digraph digraph;
    37     Digraph digraph;
       
    38     typename Digraph::template NodeMap<int> nodes(digraph);
       
    39     std::vector<Node> invNodes;
    38     for (int i = 0; i < 10; ++i) {
    40     for (int i = 0; i < 10; ++i) {
    39       digraph.addNode();
    41       invNodes.push_back(digraph.addNode());
    40     }
    42       nodes[invNodes.back()]=invNodes.size()-1;
    41     DescriptorMap<Digraph, Node> nodes(digraph);
    43     }
    42     typename DescriptorMap<Digraph, Node>::InverseMap invNodes(nodes);
       
    43     for (int i = 0; i < 100; ++i) {
    44     for (int i = 0; i < 100; ++i) {
    44       int src = rnd[invNodes.size()];
    45       int src = rnd[invNodes.size()];
    45       int trg = rnd[invNodes.size()];
    46       int trg = rnd[invNodes.size()];
    46       digraph.addArc(invNodes[src], invNodes[trg]);
    47       digraph.addArc(invNodes[src], invNodes[trg]);
    47     }
    48     }
    48     typename Digraph::template ArcMap<bool> found(digraph, false);
    49     typename Digraph::template ArcMap<bool> found(digraph, false);
    49     DescriptorMap<Digraph, Arc> arcs(digraph);
       
    50     for (NodeIt src(digraph); src != INVALID; ++src) {
    50     for (NodeIt src(digraph); src != INVALID; ++src) {
    51       for (NodeIt trg(digraph); trg != INVALID; ++trg) {
    51       for (NodeIt trg(digraph); trg != INVALID; ++trg) {
    52         for (ConArcIt<Digraph> con(digraph, src, trg); con != INVALID; ++con) {
    52         for (ConArcIt<Digraph> con(digraph, src, trg); con != INVALID; ++con) {
    53           check(digraph.source(con) == src, "Wrong source.");
    53           check(digraph.source(con) == src, "Wrong source.");
    54           check(digraph.target(con) == trg, "Wrong target.");
    54           check(digraph.target(con) == trg, "Wrong target.");
   108 
   108 
   109 template <typename Graph>
   109 template <typename Graph>
   110 void checkFindEdges() {
   110 void checkFindEdges() {
   111   TEMPLATE_GRAPH_TYPEDEFS(Graph);
   111   TEMPLATE_GRAPH_TYPEDEFS(Graph);
   112   Graph graph;
   112   Graph graph;
       
   113   typename Graph::template NodeMap<int> nodes(graph);
       
   114   std::vector<Node> invNodes;
   113   for (int i = 0; i < 10; ++i) {
   115   for (int i = 0; i < 10; ++i) {
   114     graph.addNode();
   116     invNodes.push_back(graph.addNode());
   115   }
   117     nodes[invNodes.back()]=invNodes.size()-1;
   116   DescriptorMap<Graph, Node> nodes(graph);
   118   }
   117   typename DescriptorMap<Graph, Node>::InverseMap invNodes(nodes);
       
   118   for (int i = 0; i < 100; ++i) {
   119   for (int i = 0; i < 100; ++i) {
   119     int src = rnd[invNodes.size()];
   120     int src = rnd[invNodes.size()];
   120     int trg = rnd[invNodes.size()];
   121     int trg = rnd[invNodes.size()];
   121     graph.addEdge(invNodes[src], invNodes[trg]);
   122     graph.addEdge(invNodes[src], invNodes[trg]);
   122   }
   123   }
   123   typename Graph::template EdgeMap<int> found(graph, 0);
   124   typename Graph::template EdgeMap<int> found(graph, 0);
   124   DescriptorMap<Graph, Edge> edges(graph);
       
   125   for (NodeIt src(graph); src != INVALID; ++src) {
   125   for (NodeIt src(graph); src != INVALID; ++src) {
   126     for (NodeIt trg(graph); trg != INVALID; ++trg) {
   126     for (NodeIt trg(graph); trg != INVALID; ++trg) {
   127       for (ConEdgeIt<Graph> con(graph, src, trg); con != INVALID; ++con) {
   127       for (ConEdgeIt<Graph> con(graph, src, trg); con != INVALID; ++con) {
   128         check( (graph.u(con) == src && graph.v(con) == trg) ||
   128         check( (graph.u(con) == src && graph.v(con) == trg) ||
   129                (graph.v(con) == src && graph.u(con) == trg),
   129                (graph.v(con) == src && graph.u(con) == trg),