diff --git a/boost_graph_cookbook_1/create_all_direct_neighbour_bundled_edges_and_vertices_subgraphs.impl b/boost_graph_cookbook_1/create_all_direct_neighbour_bundled_edges_and_vertices_subgraphs.impl index 04fd6114..ec2021cd 100644 --- a/boost_graph_cookbook_1/create_all_direct_neighbour_bundled_edges_and_vertices_subgraphs.impl +++ b/boost_graph_cookbook_1/create_all_direct_neighbour_bundled_edges_and_vertices_subgraphs.impl @@ -2,15 +2,24 @@ #include template std::vector -create_all_direct_neighbour_bundled_edges_and_vertices_subgraphs(const graph g) +create_all_direct_neighbour_bundled_edges_and_vertices_subgraphs( + const graph g, + const bool connect_neighours = false +) { using vd = typename graph::vertex_descriptor; std::vector v; v.resize(boost::num_vertices(g)); const auto vip = vertices(g); - std::transform(vip.first, vip.second, std::begin(v), [&g](const vd& d) { - return create_direct_neighbour_bundled_edges_and_vertices_subgraph(d, g); + std::transform( + vip.first, + vip.second, + std::begin(v), + [&g, connect_neighours](const vd& d) { + return create_direct_neighbour_bundled_edges_and_vertices_subgraph( + d, g, connect_neighours + ); }); return v; } diff --git a/boost_graph_cookbook_1/create_all_direct_neighbour_bundled_edges_and_vertices_subgraphs_test.cpp b/boost_graph_cookbook_1/create_all_direct_neighbour_bundled_edges_and_vertices_subgraphs_test.cpp index 012ddddc..19504460 100644 --- a/boost_graph_cookbook_1/create_all_direct_neighbour_bundled_edges_and_vertices_subgraphs_test.cpp +++ b/boost_graph_cookbook_1/create_all_direct_neighbour_bundled_edges_and_vertices_subgraphs_test.cpp @@ -30,11 +30,13 @@ BOOST_AUTO_TEST_CASE( { const auto v = create_all_direct_neighbour_bundled_edges_and_vertices_subgraphs( - create_bundled_edges_and_vertices_k3_graph()); + create_bundled_edges_and_vertices_k3_graph(), + true // connect the neighbours + ); BOOST_CHECK(v.size() == 3); - for (const auto g : v) { - BOOST_CHECK(boost::num_vertices(g) == 3); - BOOST_CHECK(boost::num_edges(g) == 3); + for (const auto& g : v) { + BOOST_CHECK_EQUAL(3, boost::num_vertices(g)); + BOOST_CHECK_EQUAL(3, boost::num_edges(g)); const my_bundled_vertex va("Red", "Not green", 1.0, 2.0); const my_bundled_vertex vb("Light red", "Not dark", 3.0, 4.0); const my_bundled_vertex vc("Orange", "Orangy", 5.0, 6.0); diff --git a/boost_graph_cookbook_1/create_direct_neighbour_bundled_edges_and_vertices_subgraph_test.cpp b/boost_graph_cookbook_1/create_direct_neighbour_bundled_edges_and_vertices_subgraph_test.cpp index caf4e11d..506a30be 100644 --- a/boost_graph_cookbook_1/create_direct_neighbour_bundled_edges_and_vertices_subgraph_test.cpp +++ b/boost_graph_cookbook_1/create_direct_neighbour_bundled_edges_and_vertices_subgraph_test.cpp @@ -41,9 +41,12 @@ BOOST_AUTO_TEST_CASE( const auto j = vip.second; for (auto i = vip.first; i != j; ++i) { const auto h - = create_direct_neighbour_bundled_edges_and_vertices_subgraph(*i, g); - BOOST_CHECK(boost::num_vertices(h) == 3); - BOOST_CHECK(boost::num_edges(h) == 3); + = create_direct_neighbour_bundled_edges_and_vertices_subgraph( + *i, g, + true // connect the neighbours + ); + BOOST_CHECK_EQUAL(3, boost::num_vertices(h)); + BOOST_CHECK_EQUAL(3, boost::num_edges(h)); const auto v = get_my_bundled_vertexes(h); std::set vertexes(std::begin(v), std::end(v)); const auto e = get_my_bundled_edges(h); @@ -54,12 +57,12 @@ BOOST_AUTO_TEST_CASE( const my_bundled_edge ea("Oxygen", "Air", 1.0, 2.0); const my_bundled_edge eb("Helium", "From tube", 3.0, 4.0); const my_bundled_edge ec("Stable temperature", "Here", 5.0, 6.0); - BOOST_CHECK(vertexes.count(va) == 1); - BOOST_CHECK(vertexes.count(vb) == 1); - BOOST_CHECK(vertexes.count(vc) == 1); - BOOST_CHECK(edges.count(ea) == 1); - BOOST_CHECK(edges.count(eb) == 1); - BOOST_CHECK(edges.count(ec) == 1); + BOOST_CHECK_EQUAL(1, vertexes.count(va)); + BOOST_CHECK_EQUAL(1, vertexes.count(vb)); + BOOST_CHECK_EQUAL(1, vertexes.count(vc)); + BOOST_CHECK_EQUAL(1, edges.count(ea)); + BOOST_CHECK_EQUAL(1, edges.count(eb)); + BOOST_CHECK_EQUAL(1, edges.count(ec)); } } // Path graph diff --git a/boost_graph_cookbook_1/title_graph.png b/boost_graph_cookbook_1/title_graph.png index 881eb9c3..f6d15dec 100644 Binary files a/boost_graph_cookbook_1/title_graph.png and b/boost_graph_cookbook_1/title_graph.png differ