1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/test/dfs_test.cc Thu Mar 20 12:12:24 2008 +0000
1.3 @@ -0,0 +1,130 @@
1.4 +/* -*- C++ -*-
1.5 + *
1.6 + * This file is a part of LEMON, a generic C++ optimization library
1.7 + *
1.8 + * Copyright (C) 2003-2008
1.9 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
1.10 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
1.11 + *
1.12 + * Permission to use, modify and distribute this software is granted
1.13 + * provided that this copyright notice appears in all copies. For
1.14 + * precise terms see the accompanying LICENSE file.
1.15 + *
1.16 + * This software is provided "AS IS" with no warranty of any kind,
1.17 + * express or implied, and with no claim as to its suitability for any
1.18 + * purpose.
1.19 + *
1.20 + */
1.21 +
1.22 +#include "test_tools.h"
1.23 +// #include <lemon/smart_graph.h>
1.24 +#include <lemon/list_graph.h>
1.25 +#include <lemon/dfs.h>
1.26 +#include <lemon/path.h>
1.27 +#include <lemon/concepts/digraph.h>
1.28 +
1.29 +using namespace lemon;
1.30 +
1.31 +const int PET_SIZE =5;
1.32 +
1.33 +
1.34 +void check_Dfs_SmartDigraph_Compile()
1.35 +{
1.36 + typedef concepts::Digraph Digraph;
1.37 +
1.38 + typedef Digraph::Arc Arc;
1.39 + typedef Digraph::Node Node;
1.40 + typedef Digraph::ArcIt ArcIt;
1.41 + typedef Digraph::NodeIt NodeIt;
1.42 +
1.43 + typedef Dfs<Digraph> DType;
1.44 +
1.45 + Digraph G;
1.46 + Node n;
1.47 + Arc e;
1.48 + int l;
1.49 + bool b;
1.50 + DType::DistMap d(G);
1.51 + DType::PredMap p(G);
1.52 + // DType::PredNodeMap pn(G);
1.53 +
1.54 + DType dfs_test(G);
1.55 +
1.56 + dfs_test.run(n);
1.57 +
1.58 + l = dfs_test.dist(n);
1.59 + e = dfs_test.predArc(n);
1.60 + n = dfs_test.predNode(n);
1.61 + d = dfs_test.distMap();
1.62 + p = dfs_test.predMap();
1.63 + // pn = dfs_test.predNodeMap();
1.64 + b = dfs_test.reached(n);
1.65 +
1.66 + Path<Digraph> pp = dfs_test.path(n);
1.67 +}
1.68 +
1.69 +
1.70 +void check_Dfs_Function_Compile()
1.71 +{
1.72 + typedef int VType;
1.73 + typedef concepts::Digraph Digraph;
1.74 +
1.75 + typedef Digraph::Arc Arc;
1.76 + typedef Digraph::Node Node;
1.77 + typedef Digraph::ArcIt ArcIt;
1.78 + typedef Digraph::NodeIt NodeIt;
1.79 + typedef concepts::ReadMap<Arc,VType> LengthMap;
1.80 +
1.81 + Digraph g;
1.82 + dfs(g,Node()).run();
1.83 + dfs(g).source(Node()).run();
1.84 + dfs(g)
1.85 + .predMap(concepts::WriteMap<Node,Arc>())
1.86 + .distMap(concepts::WriteMap<Node,VType>())
1.87 + .reachedMap(concepts::ReadWriteMap<Node,bool>())
1.88 + .processedMap(concepts::WriteMap<Node,bool>())
1.89 + .run(Node());
1.90 +
1.91 +}
1.92 +
1.93 +int main()
1.94 +{
1.95 +
1.96 + // typedef SmartDigraph Digraph;
1.97 + typedef ListDigraph Digraph;
1.98 +
1.99 + typedef Digraph::Arc Arc;
1.100 + typedef Digraph::Node Node;
1.101 + typedef Digraph::ArcIt ArcIt;
1.102 + typedef Digraph::NodeIt NodeIt;
1.103 + typedef Digraph::ArcMap<int> LengthMap;
1.104 +
1.105 + Digraph G;
1.106 + Node s, t;
1.107 + PetStruct<Digraph> ps = addPetersen(G,PET_SIZE);
1.108 +
1.109 + s=ps.outer[2];
1.110 + t=ps.inner[0];
1.111 +
1.112 + Dfs<Digraph> dfs_test(G);
1.113 + dfs_test.run(s);
1.114 +
1.115 + Path<Digraph> p = dfs_test.path(t);
1.116 + check(p.length()==dfs_test.dist(t),"path() found a wrong path.");
1.117 + check(checkPath(G, p),"path() found a wrong path.");
1.118 + check(pathSource(G, p) == s,"path() found a wrong path.");
1.119 + check(pathTarget(G, p) == t,"path() found a wrong path.");
1.120 +
1.121 + for(NodeIt v(G); v!=INVALID; ++v) {
1.122 + check(dfs_test.reached(v),"Each node should be reached.");
1.123 + if ( dfs_test.predArc(v)!=INVALID ) {
1.124 + Arc e=dfs_test.predArc(v);
1.125 + Node u=G.source(e);
1.126 + check(u==dfs_test.predNode(v),"Wrong tree.");
1.127 + check(dfs_test.dist(v) - dfs_test.dist(u) == 1,
1.128 + "Wrong distance. (" << dfs_test.dist(u) << "->"
1.129 + <<dfs_test.dist(v) << ')');
1.130 + }
1.131 + }
1.132 +}
1.133 +