COIN-OR::LEMON - Graph Library

source: lemon-main/test/dfs_test.cc @ 203:215bfc30b14f

Last change on this file since 203:215bfc30b14f was 171:02f4d5d9bfd7, checked in by Peter Kovacs <kpeter@…>, 16 years ago

Improve and redesign test programs + unify their output (ticket #25)

  • Move graph related utilities form test_tools.h to graph_test.h.
  • Move the contents of graph_utils_test.h to graph_utils_test.cc.
  • Rename map_test.h -> graph_maps_test.h.
  • Rename digraph_test.h -> graph_test.h.
  • Many improvements in the following files:
    • digraph_test.cc
    • graph_test.cc
    • graph_test.h
    • graph_maps_test.h
    • graph_utils_test.cc
    • bfs_test.cc
    • dfs_test.cc
    • counter_test.cc
  • Test programs print messages only if it really seems necessary.
  • Remove \file commands form .cc test files.
File size: 2.8 KB
RevLine 
[100]1/* -*- C++ -*-
2 *
3 * This file is a part of LEMON, a generic C++ optimization library
4 *
5 * Copyright (C) 2003-2008
6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 *
9 * Permission to use, modify and distribute this software is granted
10 * provided that this copyright notice appears in all copies. For
11 * precise terms see the accompanying LICENSE file.
12 *
13 * This software is provided "AS IS" with no warranty of any kind,
14 * express or implied, and with no claim as to its suitability for any
15 * purpose.
16 *
17 */
18
[171]19#include <lemon/concepts/digraph.h>
20#include <lemon/smart_graph.h>
[100]21#include <lemon/list_graph.h>
22#include <lemon/dfs.h>
23#include <lemon/path.h>
[171]24
25#include "graph_test.h"
26#include "test_tools.h"
[100]27
28using namespace lemon;
29
[171]30void checkDfsCompile()
[100]31{
32  typedef concepts::Digraph Digraph;
33  typedef Dfs<Digraph> DType;
34 
35  Digraph G;
[171]36  Digraph::Node n;
37  Digraph::Arc e;
[100]38  int l;
39  bool b;
40  DType::DistMap d(G);
41  DType::PredMap p(G);
42  //  DType::PredNodeMap pn(G);
43 
44  DType dfs_test(G);
45 
46  dfs_test.run(n);
47 
48  l  = dfs_test.dist(n);
49  e  = dfs_test.predArc(n);
50  n  = dfs_test.predNode(n);
51  d  = dfs_test.distMap();
52  p  = dfs_test.predMap();
53  //  pn = dfs_test.predNodeMap();
54  b  = dfs_test.reached(n);
55
56  Path<Digraph> pp = dfs_test.path(n);
57}
58
[171]59void checkDfsFunctionCompile()
[100]60{
61  typedef int VType;
62  typedef concepts::Digraph Digraph;
63  typedef Digraph::Arc Arc;
64  typedef Digraph::Node Node;
65   
66  Digraph g;
67  dfs(g,Node()).run();
68  dfs(g).source(Node()).run();
69  dfs(g)
70    .predMap(concepts::WriteMap<Node,Arc>())
71    .distMap(concepts::WriteMap<Node,VType>())
72    .reachedMap(concepts::ReadWriteMap<Node,bool>())
73    .processedMap(concepts::WriteMap<Node,bool>())
[171]74    .run(Node());
[100]75}
76
[171]77template <class Digraph>
78void checkDfs() {
79  TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
[100]80
81  Digraph G;
82  Node s, t;
[171]83  PetStruct<Digraph> ps = addPetersen(G, 5);
[100]84   
85  s=ps.outer[2];
86  t=ps.inner[0];
87 
88  Dfs<Digraph> dfs_test(G);
89  dfs_test.run(s); 
90 
91  Path<Digraph> p = dfs_test.path(t);
[171]92  check(p.length() == dfs_test.dist(t),"path() found a wrong path.");
[100]93  check(checkPath(G, p),"path() found a wrong path.");
94  check(pathSource(G, p) == s,"path() found a wrong path.");
95  check(pathTarget(G, p) == t,"path() found a wrong path.");
96 
97  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) << ')');
106    }
107  }
108}
109
[171]110int main()
111{
112  checkDfs<ListDigraph>();
113  checkDfs<SmartDigraph>();
114  return 0;
115}
Note: See TracBrowser for help on using the repository browser.