COIN-OR::LEMON - Graph Library

Changeset 228:b6732e0d38c5 in lemon for test/dfs_test.cc


Ignore:
Timestamp:
07/21/08 16:30:28 (11 years ago)
Author:
Balazs Dezso <deba@…>
Branch:
default
Children:
229:aebc0161f6e5, 230:af4e8ba94294
Phase:
public
Message:

Reworking graph testing

  • The graph tests check more graph functionality.
  • The petersen graph is too regular, therefore special graphs are used.
  • The graph_test.h contains just general tools to test graphs.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • test/dfs_test.cc

    r209 r228  
    2020#include <lemon/smart_graph.h>
    2121#include <lemon/list_graph.h>
     22#include <lemon/lgf_reader.h>
     23
    2224#include <lemon/dfs.h>
    2325#include <lemon/path.h>
     
    2729
    2830using namespace lemon;
     31
     32char test_lgf[] =
     33  "@nodes\n"
     34  "label\n"
     35  "0\n"
     36  "1\n"
     37  "2\n"
     38  "3\n"
     39  "4\n"
     40  "5\n"
     41  "6\n"
     42  "@arcs\n"
     43  "     label\n"
     44  "0 1  0\n"
     45  "1 2  1\n"
     46  "2 3  2\n"
     47  "1 4  3\n"
     48  "4 2  4\n"
     49  "4 5  5\n"
     50  "5 0  6\n"
     51  "6 3  7\n"
     52  "@attributes\n"
     53  "source 0\n"
     54  "target 5\n";
    2955
    3056void checkDfsCompile()
     
    4066  DType::DistMap d(G);
    4167  DType::PredMap p(G);
    42   //  DType::PredNodeMap pn(G);
    4368
    4469  DType dfs_test(G);
     
    5176  d  = dfs_test.distMap();
    5277  p  = dfs_test.predMap();
    53   //  pn = dfs_test.predNodeMap();
    5478  b  = dfs_test.reached(n);
    5579
     
    81105  Digraph G;
    82106  Node s, t;
    83   PetStruct<Digraph> ps = addPetersen(G, 5);
    84107
    85   s=ps.outer[2];
    86   t=ps.inner[0];
     108  std::istringstream input(test_lgf);
     109  digraphReader(input, G).
     110    node("source", s).
     111    node("target", t).
     112    run();
    87113
    88114  Dfs<Digraph> dfs_test(G);
     
    96122
    97123  for(NodeIt v(G); v!=INVALID; ++v) {
    98     check(dfs_test.reached(v),"Each node should be reached.");
    99     if ( dfs_test.predArc(v)!=INVALID ) {
    100       Arc e=dfs_test.predArc(v);
    101       Node u=G.source(e);
    102       check(u==dfs_test.predNode(v),"Wrong tree.");
    103       check(dfs_test.dist(v) - dfs_test.dist(u) == 1,
    104             "Wrong distance. (" << dfs_test.dist(u) << "->"
    105             <<dfs_test.dist(v) << ')');
     124    if (dfs_test.reached(v)) {
     125      check(v==s || dfs_test.predArc(v)!=INVALID, "Wrong tree.");
     126      if (dfs_test.predArc(v)!=INVALID ) {
     127        Arc e=dfs_test.predArc(v);
     128        Node u=G.source(e);
     129        check(u==dfs_test.predNode(v),"Wrong tree.");
     130        check(dfs_test.dist(v) - dfs_test.dist(u) == 1,
     131              "Wrong distance. (" << dfs_test.dist(u) << "->"
     132              <<dfs_test.dist(v) << ')');
     133      }
    106134    }
    107135  }
Note: See TracChangeset for help on using the changeset viewer.