-
Notifications
You must be signed in to change notification settings - Fork 234
Expand file tree
/
Copy pathdfv_test.cpp
More file actions
96 lines (78 loc) · 2.54 KB
/
Copy pathdfv_test.cpp
File metadata and controls
96 lines (78 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//=======================================================================
// Copyright 2022 Ralf Kohrt
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//=======================================================================
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/depth_first_search.hpp>
#include <boost/core/lightweight_test.hpp>
using namespace boost;
// Set up the vertex names
enum vertex_id_t { u, v, w, x, y, z, N };
struct counting_dfs_visitor
{
template<typename Vertex, typename Graph>
void initialize_vertex(Vertex v, const Graph& g)
{
++vertex_events;
}
template<typename Vertex, typename Graph>
void start_vertex(Vertex v, const Graph& g)
{
++vertex_events;
}
template<typename Vertex, typename Graph>
void discover_vertex(Vertex v, const Graph& g)
{
++vertex_events;
}
template<typename Edge, typename Graph>
void examine_edge(Edge e, const Graph& g)
{
++seen_edges;
}
template<typename Edge, typename Graph>
void tree_edge(Edge e, const Graph& g)
{}
template<typename Edge, typename Graph>
void back_edge(Edge e, const Graph& g)
{}
template<typename Edge, typename Graph>
void forward_or_cross_edge(Edge e, const Graph& g)
{}
template<typename Vertex, typename Graph>
void finish_vertex(Vertex v, const Graph& g)
{
++vertex_events;
}
size_t vertex_events = 0;
size_t seen_edges = 0;
};
void
test_dfv_returns_copied_visitor()
{
typedef adjacency_list<listS,
vecS,
undirectedS,
// Vertex properties
property<vertex_color_t, default_color_type> >
Graph;
typedef typename boost::property_map< Graph, boost::vertex_color_t >::type
ColorMap;
// Specify the edges in the graph
typedef std::pair<int, int> E;
E edge_array[] = { E(u, v), E(u, w), E(u, x), E(x, v), E(y, x),
E(v, y), E(w, y), E(w, z), E(z, z) };
Graph g(edge_array, edge_array + sizeof(edge_array) / sizeof(E), N);
ColorMap color = get(boost::vertex_color, g);
counting_dfs_visitor visitor_copy = depth_first_visit(g, vertex(u, g), counting_dfs_visitor(), color);
BOOST_TEST(visitor_copy.vertex_events == 6u*2u + 1u); // discover_vertex + finish_vertex for each vertex and once start_vertex
BOOST_TEST(visitor_copy.seen_edges == 2u*9u);
}
int
main(int argc, char* argv[])
{
test_dfv_returns_copied_visitor();
return boost::report_errors();
}