1
+ #include < catch2/catch_test_macros.hpp>
2
+ #include < catch2/catch_template_test_macros.hpp>
3
+ #include " csv_routes.hpp"
4
+ #include " graph/graph.hpp"
5
+ #include " graph/algorithm/connected_components.hpp"
6
+ #include " graph/container/dynamic_graph.hpp"
7
+ #include " graph/views/incidence.hpp"
8
+ #ifdef _MSC_VER
9
+ # include " Windows.h"
10
+ #endif
11
+
12
+ #define TEST_OPTION_OUTPUT (1 ) // output tests for visual inspection
13
+ #define TEST_OPTION_GEN (2 ) // generate unit test code to be pasted into this file
14
+ #define TEST_OPTION_TEST (3 ) // run unit tests
15
+ #define TEST_OPTION TEST_OPTION_TEST
16
+
17
+ using std::cout;
18
+ using std::endl;
19
+
20
+ using std::graph::vertex_t ;
21
+ using std::graph::vertex_id_t ;
22
+ using std::graph::vertex_reference_t ;
23
+ using std::graph::vertex_iterator_t ;
24
+ using std::graph::vertex_edge_range_t ;
25
+ using std::graph::edge_t ;
26
+
27
+ using std::graph::vertices;
28
+ using std::graph::edges;
29
+ using std::graph::vertex_value;
30
+ using std::graph::target_id;
31
+ using std::graph::target;
32
+ using std::graph::edge_value;
33
+ using std::graph::find_vertex;
34
+ using std::graph::vertex_id;
35
+
36
+ using routes_vol_graph_traits = std::graph::container::vol_graph_traits<double , std::string, std::string>;
37
+ using routes_vol_graph_type = std::graph::container::dynamic_adjacency_graph<routes_vol_graph_traits>;
38
+
39
+ #if 1
40
+ TEST_CASE (" strongly connected components test" , " [strong cc]" ) {
41
+ init_console ();
42
+
43
+ using G = routes_vol_graph_type;
44
+ auto && g = load_ordered_graph<G>(TEST_DATA_ROOT_DIR " cc_directed.csv" , name_order_policy::alphabetical);
45
+ G gt;
46
+
47
+ std::vector<std::tuple<vertex_id_t <G>,vertex_id_t <G>,double >> reverse;
48
+ vertex_id_t <G> vid = 0 ;
49
+ for ( auto && u : vertices (g) ) {
50
+ for ( auto && v : edges (g, u)) {
51
+ reverse.push_back (std::make_tuple (target_id (g,v), vid, edge_value (g,v)));
52
+ }
53
+ ++vid;
54
+ }
55
+
56
+
57
+ using value = std::ranges::range_value_t <decltype (reverse)>;
58
+
59
+ vertex_id_t <G> N = size (vertices (g));
60
+ using edge_desc = std::graph::edge_descriptor<vertex_id_t <G>, true , void , double >;
61
+ auto edge_proj = [](const value& val) -> edge_desc {
62
+ return edge_desc{std::get<0 >(val), std::get<1 >(val), std::get<2 >(val)};
63
+ };
64
+
65
+ gt.load_edges (reverse, edge_proj, N);
66
+
67
+ std::vector<size_t > component (size (vertices (g)));
68
+ std::graph::kosaraju (g, gt, component);
69
+
70
+ REQUIRE ( *std::ranges::max_element ( component ) == 2 );
71
+ }
72
+ #endif
73
+
74
+ TEST_CASE (" connected components test" , " [cc]" ) {
75
+ init_console ();
76
+
77
+ using G = routes_vol_graph_type;
78
+ auto && g = load_ordered_graph<G>(TEST_DATA_ROOT_DIR " cc_undirected.csv" , name_order_policy::alphabetical);
79
+
80
+ std::vector<size_t > component (size (vertices (g)));
81
+ std::graph::connected_components (g, component);
82
+
83
+ REQUIRE ( *std::ranges::max_element ( component ) == 2 );
84
+ }
0 commit comments