diff --git a/CMakePresets.json b/CMakePresets.json index fae0f9e..7a179c2 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -15,7 +15,8 @@ "CMAKE_CXX_STANDARD": "20", "CMAKE_CXX_STANDARD_REQUIRED": "ON", "CMAKE_CXX_EXTENSIONS": "OFF", - "CMAKE_EXPORT_COMPILE_COMMANDS": "ON" + "CMAKE_EXPORT_COMPILE_COMMANDS": "ON", + "WARNINGS_AS_ERRORS": "ON" } }, { diff --git a/benchmark/CMakeLists.txt b/benchmark/CMakeLists.txt index 254507a..46ce39b 100644 --- a/benchmark/CMakeLists.txt +++ b/benchmark/CMakeLists.txt @@ -33,7 +33,8 @@ target_link_libraries(graph_benchmarks # Register benchmarks with CTest add_test(NAME graph_benchmarks - COMMAND graph_benchmarks --benchmark_min_time=0.1) + COMMAND graph_benchmarks --benchmark_min_time=0.1s) # Add algorithm benchmarks subdirectory add_subdirectory(algorithms) + \ No newline at end of file diff --git a/benchmark/algorithms/CMakeLists.txt b/benchmark/algorithms/CMakeLists.txt index 8883b0f..0dc9275 100644 --- a/benchmark/algorithms/CMakeLists.txt +++ b/benchmark/algorithms/CMakeLists.txt @@ -108,4 +108,4 @@ endif() # Register with CTest using a short minimum time so CI stays fast. # For proper baseline capture use: ./benchmark_dijkstra --benchmark_min_time=1.0 add_test(NAME benchmark_dijkstra - COMMAND benchmark_dijkstra --benchmark_min_time=0.1) + COMMAND benchmark_dijkstra --benchmark_min_time=0.1s) diff --git a/benchmark/algorithms/dijkstra_fixtures.hpp b/benchmark/algorithms/dijkstra_fixtures.hpp index ad4bc7c..3bba782 100644 --- a/benchmark/algorithms/dijkstra_fixtures.hpp +++ b/benchmark/algorithms/dijkstra_fixtures.hpp @@ -25,7 +25,6 @@ #include #include -#include #include namespace graph::benchmark { @@ -83,16 +82,16 @@ inline edge_list path_graph(vertex_id_t n, uint64_t seed = 42, // --------------------------------------------------------------------------- /// Build a compressed_graph (CSR) from a pre-sorted edge list. -inline csr_graph_t make_csr(const edge_list& edges, vertex_id_t num_vertices) { +inline csr_graph_t make_csr(const edge_list& edge_list_data, vertex_id_t vertex_count) { csr_graph_t g; - g.load_edges(edges, std::identity{}, num_vertices); + g.load_edges(edge_list_data, std::identity{}, vertex_count); return g; } /// Build a vov dynamic_graph from an edge list (order does not matter). -inline vov_graph_t make_vov(const edge_list& edges, vertex_id_t num_vertices) { +inline vov_graph_t make_vov(const edge_list& edge_list_data, vertex_id_t vertex_count) { vov_graph_t g; - g.load_edges(edges, std::identity{}, num_vertices); + g.load_edges(edge_list_data, std::identity{}, vertex_count); return g; } diff --git a/benchmark/benchmark_views.cpp b/benchmark/benchmark_views.cpp index f8023c5..6ab78c1 100644 --- a/benchmark/benchmark_views.cpp +++ b/benchmark/benchmark_views.cpp @@ -21,15 +21,17 @@ using namespace graph::views::adaptors; using TestGraph = std::vector>; // Create a random directed graph -TestGraph create_random_graph(size_t num_vertices, size_t avg_degree) { - TestGraph g(num_vertices); +TestGraph create_random_graph(size_t vertex_count, size_t mean_degree) { + TestGraph g(vertex_count); std::mt19937 rng(42); // Fixed seed for reproducibility - std::uniform_int_distribution dist(0, num_vertices - 1); + std::uniform_int_distribution dist(0, vertex_count - 1); - for (size_t u = 0; u < num_vertices; ++u) { - size_t degree = std::poisson_distribution(avg_degree)(rng); - for (size_t i = 0; i < degree; ++i) { + std::poisson_distribution degree_dist(static_cast(mean_degree)); + + for (size_t u = 0; u < vertex_count; ++u) { + auto sampled_degree = static_cast(degree_dist(rng)); + for (size_t i = 0; i < sampled_degree; ++i) { size_t v = dist(rng); if (v != u) { // Avoid self-loops g[u].push_back(static_cast(v)); @@ -41,19 +43,19 @@ TestGraph create_random_graph(size_t num_vertices, size_t avg_degree) { } // Create a path graph (0 -> 1 -> 2 -> ... -> n-1) -TestGraph create_path_graph(size_t num_vertices) { - TestGraph g(num_vertices); - for (size_t i = 0; i + 1 < num_vertices; ++i) { +TestGraph create_path_graph(size_t vertex_count) { + TestGraph g(vertex_count); + for (size_t i = 0; i + 1 < vertex_count; ++i) { g[i].push_back(static_cast(i + 1)); } return g; } // Create a complete graph (all vertices connected) -TestGraph create_complete_graph(size_t num_vertices) { - TestGraph g(num_vertices); - for (size_t u = 0; u < num_vertices; ++u) { - for (size_t v = 0; v < num_vertices; ++v) { +TestGraph create_complete_graph(size_t vertex_count) { + TestGraph g(vertex_count); + for (size_t u = 0; u < vertex_count; ++u) { + for (size_t v = 0; v < vertex_count; ++v) { if (u != v) { g[u].push_back(static_cast(v)); } @@ -63,11 +65,11 @@ TestGraph create_complete_graph(size_t num_vertices) { } // Create a DAG (directed acyclic graph) for topological sort -TestGraph create_dag(size_t num_vertices) { - TestGraph g(num_vertices); - for (size_t u = 0; u < num_vertices; ++u) { +TestGraph create_dag(size_t vertex_count) { + TestGraph g(vertex_count); + for (size_t u = 0; u < vertex_count; ++u) { // Connect to next few vertices only (maintains DAG property) - for (size_t v = u + 1; v < std::min(u + 5, num_vertices); ++v) { + for (size_t v = u + 1; v < std::min(u + 5, vertex_count); ++v) { g[u].push_back(static_cast(v)); } } @@ -98,7 +100,7 @@ BENCHMARK(BM_Vertexlist_Iteration)->RangeMultiplier(2)->Range(100, 10000)->Compl // Benchmark: vertexlist with value function static void BM_Vertexlist_WithValueFunction(benchmark::State& state) { auto g = create_random_graph(state.range(0), 5); - auto vvf = [](const auto& g, auto v) { return vertex_id(g, v); }; + auto vvf = [](const auto& gr, auto v) { return vertex_id(gr, v); }; for (auto _ : state) { size_t sum = 0; diff --git a/cmake/CompilerWarnings.cmake b/cmake/CompilerWarnings.cmake index 22fe3ce..a33e257 100644 --- a/cmake/CompilerWarnings.cmake +++ b/cmake/CompilerWarnings.cmake @@ -1,6 +1,6 @@ # Comprehensive compiler warning configuration function(set_project_warnings target_name) - option(WARNINGS_AS_ERRORS "Treat compiler warnings as errors" OFF) + option(WARNINGS_AS_ERRORS "Treat compiler warnings as errors" ON) set(MSVC_WARNINGS /W4 # High warning level @@ -26,31 +26,72 @@ function(set_project_warnings target_name) /permissive- # standards conformance mode ) + # The -Wno-* options are used to suppress specific warnings that are either not relevant or too noisy for this project. + # Further adjustments may be necessary based on the specific codebase and compiler versions used. set(CLANG_WARNINGS -Wall -Wextra -Wpedantic - -Wshadow -Wnon-virtual-dtor -Wold-style-cast -Wcast-align -Wunused -Woverloaded-virtual - -Wconversion - -Wsign-conversion -Wnull-dereference -Wdouble-promotion -Wformat=2 -Wimplicit-fallthrough + -Wshadow + #-Wconversion + #-Wsign-conversion + -Wno-unused-parameter + -Wno-unused-variable + -Wno-mismatched-tags + -Wno-ignored-qualifiers + -Wno-deprecated-declarations + -Wno-unqualified-std-cast-call + -Wno-unused-lambda-capture + -Wno-unused-local-typedef + -Wno-self-assign-overloaded + -Wno-unneeded-internal-declaration + -Wno-unused-but-set-variable + -Wno-sign-compare + -Wno-old-style-cast + -Wno-double-promotion + -Wno-conversion + -Wno-sign-conversion ) set(GCC_WARNINGS - ${CLANG_WARNINGS} + -Wall + -Wextra + -Wpedantic + -Wnon-virtual-dtor + -Wold-style-cast + -Wcast-align + -Wunused + -Woverloaded-virtual + -Wnull-dereference + -Wdouble-promotion + -Wformat=2 + -Wimplicit-fallthrough + -Wshadow + #-Wconversion + #-Wsign-conversion -Wmisleading-indentation -Wduplicated-cond - -Wduplicated-branches -Wlogical-op -Wuseless-cast + -Wno-useless-cast + -Wno-old-style-cast + -Wno-unused-local-typedefs + -Wno-unused-but-set-variable + -Wno-sign-compare + -Wno-comment + -Wno-null-dereference + -Wno-deprecated-declarations + -Wno-conversion + -Wno-sign-conversion ) if(WARNINGS_AS_ERRORS) @@ -69,5 +110,20 @@ function(set_project_warnings target_name) message(WARNING "No compiler warnings set for '${CMAKE_CXX_COMPILER_ID}' compiler.") endif() + # clang-cl (MSVC ABI): MSVC_WARNINGS are already applied above via if(MSVC), + # but /W4 in clang-cl maps to Clang warning groups which fire on things the + # project intentionally suppresses. Apply all -Wno-* from CLANG_WARNINGS plus + # clang-cl-specific suppressions. + if(MSVC AND CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + foreach(w ${CLANG_WARNINGS}) + if(w MATCHES "^-Wno-") + list(APPEND PROJECT_WARNINGS ${w}) + endif() + endforeach() + list(APPEND PROJECT_WARNINGS + -Wno-unknown-attributes # [[no_unique_address]] unsupported in MSVC ABI mode + ) + endif() + target_compile_options(${target_name} INTERFACE ${PROJECT_WARNINGS}) endfunction() diff --git a/cmake/StandardProjectSettings.cmake b/cmake/StandardProjectSettings.cmake index 095936c..6065148 100644 --- a/cmake/StandardProjectSettings.cmake +++ b/cmake/StandardProjectSettings.cmake @@ -15,8 +15,8 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON) # Enable folder organization in IDEs set_property(GLOBAL PROPERTY USE_FOLDERS ON) -# Enable parallel compilation for MSVC -if(MSVC) +# Enable parallel compilation for MSVC (cl.exe only; clang-cl doesn't support /MP) +if(MSVC AND NOT CMAKE_CXX_COMPILER_ID STREQUAL "Clang") # Use /MP to enable parallel compilation with all available cores add_compile_options(/MP) message(STATUS "MSVC parallel compilation enabled with /MP") diff --git a/docs/user-guide/containers.md b/docs/user-guide/containers.md index e82da6f..5d5a9cd 100644 --- a/docs/user-guide/containers.md +++ b/docs/user-guide/containers.md @@ -40,9 +40,8 @@ template > + class Traits = vofl_graph_traits> class dynamic_graph; } ``` @@ -64,7 +63,7 @@ incoming-edge list, enabling the `in_edges`, `in_degree`, `find_in_edge`, and |----------|-------| | Vertex ID assignment | Contiguous (0 .. N-1) for `v`/`d` traits; sparse user-defined keys for `m`/`u` traits | | Vertex range | Random access (`v`/`d`), bidirectional (`m`), forward (`u`) | -| Edge range per vertex | Random access (`v`/`d`), forward (`fl`/`us`), bidirectional (`l`/`s`/`em`) | +| Edge range per vertex | Random access (`v`/`d`), forward (`fl`/`us`), bidirectional (`l`/`s`/`m`) | | Partitions | No | | Append vertices/edges | Yes | @@ -105,7 +104,6 @@ Complexity depends on the vertex container, the edge container, or neither. | `VV` | `void` | Vertex value type (`void` → no vertex values) | | `GV` | `void` | Graph value type (`void` → no graph value) | | `VId` | `uint32_t` | Vertex ID type (integral for indexed traits, any ordered/hashable type for map-based traits) | -| `Sourced` | `false` | When `true`, each edge stores a source vertex ID. This does not affect the ability to use `source_id(g,uv)`. | | `Bidirectional` | `false` | When `true`, each vertex maintains an incoming-edge list, enabling `in_edges(g,u)`, `in_degree(g,u)`, `find_in_edge(g,...)`, and `contains_in_edge(g,...)`. Satisfies `bidirectional_adjacency_list`. | | `Traits` | `vofl_graph_traits<…>` | Trait struct that defines the vertex and edge container types | @@ -127,7 +125,19 @@ G g; ``` The `dynamic_adjacency_graph` alias extracts `EV`, `VV`, `GV`, `VId`, -and `Sourced` from the traits struct, so you only need one template argument. +and `Bidirectional` from the traits struct, so you only need one template argument. + +Each traits header also provides a convenience graph alias that matches how tests +are written (for example, `dod_graph` in `test_dynamic_graph_dod.cpp`): + +```cpp +#include + +using namespace graph::container; + +using G0 = dod_graph<>; // EV=VV=GV=void +using G1 = dod_graph; // bidirectional +``` ### Trait combinations @@ -197,13 +207,13 @@ All trait structs share the same template parameters: ```cpp template + class VId = uint32_t, bool Bidirectional = false> struct vov_graph_traits { ... }; ``` Each defines: - `edge_value_type`, `vertex_value_type`, `graph_value_type`, `vertex_id_type` -- `static constexpr bool sourced` +- `static constexpr bool bidirectional` - `edge_type`, `vertex_type`, `graph_type` - `vertices_type` (e.g., `std::vector`) - `edges_type` (e.g., `std::vector`) @@ -240,25 +250,25 @@ the type aliases and constant shown below: namespace myapp { -// Forward declarations required by dynamic_edge / dynamic_vertex / dynamic_graph +// Forward declarations required by dynamic_out_edge / dynamic_vertex / dynamic_graph using namespace graph::container; template + class VId = uint32_t, bool Bidirectional = false> struct flat_map_small_vec_traits { // --- Required type aliases --- using edge_value_type = EV; using vertex_value_type = VV; using graph_value_type = GV; using vertex_id_type = VId; - static constexpr bool sourced = Sourced; + static constexpr bool bidirectional = Bidirectional; // --- Edge, vertex, and graph types (always use dynamic_*) --- - using edge_type = dynamic_edge; - using vertex_type = dynamic_vertex; + using vertex_type = dynamic_vertex; - using graph_type = dynamic_graph; // --- Storage types (your custom containers) --- diff --git a/examples/BGLWorkshop2026/CMakeLists.txt b/examples/BGLWorkshop2026/CMakeLists.txt index 6c18243..0592074 100644 --- a/examples/BGLWorkshop2026/CMakeLists.txt +++ b/examples/BGLWorkshop2026/CMakeLists.txt @@ -36,14 +36,16 @@ if(_bglws_bgl_inc) message(STATUS "BGLWorkshop2026: BGL headers at ${_bglws_bgl_inc}") add_executable(bglws_bacon_bgl bacon_bgl.cpp) target_link_libraries(bglws_bacon_bgl PRIVATE graph3) - target_include_directories(bglws_bacon_bgl PRIVATE ${BGLWS_INCLUDE_DIRS} ${_bglws_bgl_inc}) + target_include_directories(bglws_bacon_bgl PRIVATE ${BGLWS_INCLUDE_DIRS}) + target_include_directories(bglws_bacon_bgl SYSTEM PRIVATE ${_bglws_bgl_inc}) target_compile_features(bglws_bacon_bgl PRIVATE cxx_std_20) target_compile_definitions(bglws_bacon_bgl PRIVATE BGLWS_OUTPUT_DIR="${CMAKE_CURRENT_SOURCE_DIR}/output") add_executable(bglws_france_routes_bgl france_routes_bgl.cpp) target_link_libraries(bglws_france_routes_bgl PRIVATE graph3) - target_include_directories(bglws_france_routes_bgl PRIVATE ${BGLWS_INCLUDE_DIRS} ${_bglws_bgl_inc}) + target_include_directories(bglws_france_routes_bgl PRIVATE ${BGLWS_INCLUDE_DIRS}) + target_include_directories(bglws_france_routes_bgl SYSTEM PRIVATE ${_bglws_bgl_inc}) target_compile_features(bglws_france_routes_bgl PRIVATE cxx_std_20) target_compile_definitions(bglws_france_routes_bgl PRIVATE BGLWS_DATA_DIR="${CMAKE_CURRENT_SOURCE_DIR}/graphs" diff --git a/examples/BGLWorkshop2026/bacon_gv3.cpp b/examples/BGLWorkshop2026/bacon_gv3.cpp index c0da611..936e367 100644 --- a/examples/BGLWorkshop2026/bacon_gv3.cpp +++ b/examples/BGLWorkshop2026/bacon_gv3.cpp @@ -1,7 +1,6 @@ #include "graph/graph.hpp" #include "graph/algorithm/breadth_first_search.hpp" #include "graph/views/bfs.hpp" -#include "graph/container/dynamic_graph.hpp" #include "graph/container/traits/uol_graph_traits.hpp" #include "graph/container/traits/mol_graph_traits.hpp" #include "imdb-graph.hpp" diff --git a/examples/BGLWorkshop2026/france_routes_gv3.cpp b/examples/BGLWorkshop2026/france_routes_gv3.cpp index 83c2b02..6c192cc 100644 --- a/examples/BGLWorkshop2026/france_routes_gv3.cpp +++ b/examples/BGLWorkshop2026/france_routes_gv3.cpp @@ -7,7 +7,6 @@ // - Reconstructing and printing shortest paths to each city #include "graph/algorithm/dijkstra_shortest_paths.hpp" -#include "graph/container/dynamic_graph.hpp" #include "graph/container/traits/vom_graph_traits.hpp" #include @@ -76,8 +75,8 @@ load_result load(const string& filename) { if (std::regex_search(content, cm, cities_re)) { string cities_block = cm[1].str(); for (auto it = std::sregex_iterator(cities_block.begin(), cities_block.end(), name_re), - end = std::sregex_iterator{}; - it != end; ++it) { + it_end = std::sregex_iterator{}; + it != it_end; ++it) { string name = (*it)[1].str(); city_id[name] = city_names.size(); city_names.push_back(name); @@ -100,19 +99,19 @@ load_result load(const string& filename) { R"re(\{\s*"from"\s*:\s*"([^"]+)"\s*,\s*"to"\s*:\s*"([^"]+)"\s*,\s*"distance_km"\s*:\s*(\d+)\s*,\s*"route"\s*:\s*"([^"]+)"\s*\})re"); using edge_data = copyable_edge_t; // target vertex id + route info - vector edges; + vector edge_list; for (auto it = std::sregex_iterator(content.begin(), content.end(), route_re), - end = std::sregex_iterator{}; - it != end; ++it) { + it_end = std::sregex_iterator{}; + it != it_end; ++it) { auto& m = *it; vid_t src = city_id.at(m[1].str()); vid_t tgt = city_id.at(m[2].str()); dist_t dist = std::stoi(m[3].str()); - edges.push_back({src, tgt, route_t{dist, m[4].str()}}); + edge_list.push_back({src, tgt, route_t{dist, m[4].str()}}); } - g.load_edges(edges); + g.load_edges(edge_list); return {std::move(g), std::move(city_id)}; } @@ -131,14 +130,14 @@ void run(const string& filename) { }; // ── Evaluate shortest paths from source ──────────────────────────────────── - const vid_t source_id = city_id.at("Paris"); + const vid_t source_city_id = city_id.at("Paris"); // Distance and predecessor vectors indexed by vertex id. vector distances(num_vertices(g)); vector predecessors(num_vertices(g)); init_shortest_paths(g, distances, predecessors); - dijkstra_shortest_paths(g, source_id, + dijkstra_shortest_paths(g, source_city_id, container_value_fn(distances), container_value_fn(predecessors), route_distance); @@ -148,12 +147,12 @@ void run(const string& filename) { vector> by_dist; by_dist.reserve(num_vertices(g)); for (vid_t uid = 0; uid < num_vertices(g); ++uid) { - if (uid != source_id) + if (uid != source_city_id) by_dist.emplace_back(distances[uid], uid); } std::ranges::sort(by_dist); // sort by (distance, uid) — default pair comparison - cout << "Shortest road distances from " << city_name(g, source_id) << ":\n"; + cout << "Shortest road distances from " << city_name(g, source_city_id) << ":\n"; for (auto& [d, uid] : by_dist) { if (d == infinite_distance()) cout << " " << city_name(g, uid) << ": unreachable\n"; @@ -165,17 +164,17 @@ void run(const string& filename) { // ── Reconstruct shortest path from Paris to Nice ──────────────────────────── { const vid_t dest_id = city_id.at("Nice"); - cout << "\nShortest path: " << city_name(g, source_id) << " -> " << city_name(g, dest_id) << "\n"; + cout << "\nShortest path: " << city_name(g, source_city_id) << " -> " << city_name(g, dest_id) << "\n"; vector path; - for (vid_t cur = dest_id; cur != source_id; cur = predecessors[cur]) { + for (vid_t cur = dest_id; cur != source_city_id; cur = predecessors[cur]) { if (path.size() >= num_vertices(g)) { cout << " (no path found)\n"; return; } path.push_back(cur); } - path.push_back(source_id); + path.push_back(source_city_id); std::ranges::reverse(path); for (size_t i = 0; i + 1 < path.size(); ++i) { diff --git a/examples/CppCon2021/CMakeLists.txt b/examples/CppCon2021/CMakeLists.txt index 85de257..0a1847e 100644 --- a/examples/CppCon2021/CMakeLists.txt +++ b/examples/CppCon2021/CMakeLists.txt @@ -4,18 +4,32 @@ set(CPPCON21_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/graphs) +set(CPPCON21_WARNING_SUPPRESSIONS) +if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + list(APPEND CPPCON21_WARNING_SUPPRESSIONS + -Wno-old-style-cast + -Wno-useless-cast) +elseif(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang") + list(APPEND CPPCON21_WARNING_SUPPRESSIONS + -Wno-old-style-cast) +endif() + add_executable(cppcon21_graphs examples/graphs.cpp) target_link_libraries(cppcon21_graphs PRIVATE graph3) target_include_directories(cppcon21_graphs PRIVATE ${CPPCON21_INCLUDE_DIRS}) +target_compile_options(cppcon21_graphs PRIVATE ${CPPCON21_WARNING_SUPPRESSIONS}) add_executable(cppcon21_bacon examples/bacon.cpp) target_link_libraries(cppcon21_bacon PRIVATE graph3) target_include_directories(cppcon21_bacon PRIVATE ${CPPCON21_INCLUDE_DIRS}) +target_compile_options(cppcon21_bacon PRIVATE ${CPPCON21_WARNING_SUPPRESSIONS}) add_executable(cppcon21_ospf examples/ospf.cpp) target_link_libraries(cppcon21_ospf PRIVATE graph3) target_include_directories(cppcon21_ospf PRIVATE ${CPPCON21_INCLUDE_DIRS}) +target_compile_options(cppcon21_ospf PRIVATE ${CPPCON21_WARNING_SUPPRESSIONS}) add_executable(cppcon21_imdb examples/imdb.cpp) target_link_libraries(cppcon21_imdb PRIVATE graph3) target_include_directories(cppcon21_imdb PRIVATE ${CPPCON21_INCLUDE_DIRS}) +target_compile_options(cppcon21_imdb PRIVATE ${CPPCON21_WARNING_SUPPRESSIONS}) diff --git a/examples/CppCon2021/examples/imdb.cpp b/examples/CppCon2021/examples/imdb.cpp index 7729c13..b1f50d4 100644 --- a/examples/CppCon2021/examples/imdb.cpp +++ b/examples/CppCon2021/examples/imdb.cpp @@ -65,7 +65,6 @@ int main() { // Iterate through all actors (other than Kevin Bacon) for (size_t i = 0; i < actors.size(); ++i) { if (i != kevin_bacon) { - auto bacon_number = distance[i]; std::cout << actors[i] << " has a bacon number of " << distance[i] << std::endl; auto k = i; diff --git a/examples/CppCon2021/include/utilities.hpp b/examples/CppCon2021/include/utilities.hpp index 65ee0cd..994558a 100644 --- a/examples/CppCon2021/include/utilities.hpp +++ b/examples/CppCon2021/include/utilities.hpp @@ -36,8 +36,6 @@ auto graph_edge(std::tuple t) { */ template void push_back_plain_fill(const EdgeList& edge_list, Adjacency& adj, bool directed, size_t idx) { - const size_t jdx = (idx + 1) % 2; - for (auto&& e : edge_list) { if (idx == 0) { @@ -59,8 +57,6 @@ void push_back_plain_fill(const EdgeList& edge_list, Adjacency& adj, bool direct */ template void push_back_fill(const EdgeList& edge_list, Adjacency& adj, bool directed, size_t idx) { - const size_t jdx = (idx + 1) % 2; - for (auto&& e : edge_list) { if (idx == 0) { @@ -102,7 +98,7 @@ auto make_plain_edges(M& map, const E& edges) { EdgeList index_edges; for (auto&& e : edges) { - std::apply([&](auto&& u, auto&& v, auto... props_) { index_edges.push_back(std::make_tuple(map[u], map[v])); }, e); + std::apply([&](auto&& u, auto&& v, [[maybe_unused]] auto... props_) { index_edges.push_back(std::make_tuple(map[u], map[v])); }, e); } return index_edges; diff --git a/examples/CppCon2022/rr_adaptor.hpp b/examples/CppCon2022/rr_adaptor.hpp index 2ff45dd..8a89706 100644 --- a/examples/CppCon2022/rr_adaptor.hpp +++ b/examples/CppCon2022/rr_adaptor.hpp @@ -119,18 +119,18 @@ class rr_adaptor { // ── Private helpers ─────────────────────────────────────────────────────── template - vertex_id_type max_vertex_id(const ERng& erng, const EProj& eproj) const { + vertex_id_type max_vertex_id(const ERng& erng, const EProj& /*eproj*/) const { vertex_id_type max_vid = 0; for (auto&& e : erng) max_vid = std::max(max_vid, std::max(e.source_id, e.target_id)); return max_vid; } - void push(edges_range& edges, const edge_type& val) { + void push(edges_range& edge_store, const edge_type& val) { if constexpr (graph::container::has_push_back) - edges.push_back(val); + edge_store.push_back(val); else if constexpr (graph::container::has_push_front) - edges.push_front(val); + edge_store.push_front(val); } // ── v3 graph CPO free functions ─────────────────────────────────────────── @@ -143,12 +143,12 @@ class rr_adaptor { // find_vertex(g, uid) — construct a vertex_descriptor_view iterator // directly from the index. For random-access backing the iterator stores // just a size_t, so it is safe to return from a temporary view. - friend auto find_vertex(graph_type& g, vertex_id_type uid) { + friend auto find_vertex(graph_type& /*g*/, vertex_id_type uid) { using Iter = std::ranges::iterator_t; using VDV = graph::adj_list::vertex_descriptor_view; return typename VDV::iterator{static_cast(uid)}; } - friend auto find_vertex(const graph_type& g, vertex_id_type uid) { + friend auto find_vertex(const graph_type& /*g*/, vertex_id_type uid) { using Iter = std::ranges::iterator_t; using VDV = graph::adj_list::vertex_descriptor_view; return typename VDV::iterator{static_cast(uid)}; @@ -171,7 +171,7 @@ class rr_adaptor { // target_id(g, uv) — uv is an edge_descriptor; *uv.value() is the raw edge. template - friend auto target_id(const graph_type& g, const EDesc& uv) noexcept + friend auto target_id(const graph_type& /*g*/, const EDesc& uv) noexcept -> decltype(static_cast(std::get<0>(to_tuple(*uv.value())))) { return static_cast(std::get<0>(to_tuple(*uv.value()))); } @@ -188,14 +188,15 @@ class rr_adaptor { // edge_value(g, uv) — uv is an edge_descriptor; *uv.value() is the raw edge. template - friend auto edge_value(graph_type& g, const EDesc& uv) - -> decltype(std::get<1>(to_tuple(*uv.value()))) { - return std::get<1>(to_tuple(*uv.value())); + using edge_value_ret_t = std::remove_cvref_t(to_tuple(*std::declval().value())))>; + + template + friend edge_value_ret_t edge_value(graph_type& g, const EDesc& uv) { + return static_cast>(std::get<1>(to_tuple(*uv.value()))); } template - friend auto edge_value(const graph_type& g, const EDesc& uv) - -> decltype(std::get<1>(to_tuple(*uv.value()))) { - return std::get<1>(to_tuple(*uv.value())); + friend edge_value_ret_t edge_value(const graph_type& /*g*/, const EDesc& uv) { + return static_cast>(std::get<1>(to_tuple(*uv.value()))); } }; diff --git a/examples/dijkstra_clrs.hpp b/examples/dijkstra_clrs.hpp index ddfa45e..e43fe55 100644 --- a/examples/dijkstra_clrs.hpp +++ b/examples/dijkstra_clrs.hpp @@ -4,6 +4,7 @@ #include "graph/views/incidence.hpp" #include #include +#include namespace graph { @@ -31,16 +32,16 @@ class _null_range_type : public std::vector { public: _null_range_type() noexcept(noexcept(Allocator())) = default; - explicit _null_range_type(const Allocator& alloc) noexcept {} - _null_range_type(Base::size_type count, const T& value, const Allocator& alloc = Allocator()) {} - explicit _null_range_type(Base::size_type count, const Allocator& alloc = Allocator()) {} + explicit _null_range_type(const Allocator& /*alloc*/) noexcept {} + _null_range_type(Base::size_type /*count*/, const T& /*value*/, const Allocator& /*alloc*/ = Allocator()) {} + explicit _null_range_type(Base::size_type /*count*/, const Allocator& /*alloc*/ = Allocator()) {} template - _null_range_type(InputIt first, InputIt last, const Allocator& alloc = Allocator()) {} - _null_range_type(const _null_range_type& other) : Base() {} - _null_range_type(const _null_range_type& other, const Allocator& alloc) {} - _null_range_type(_null_range_type&& other) noexcept {} - _null_range_type(_null_range_type&& other, const Allocator& alloc) {} - _null_range_type(std::initializer_list init, const Allocator& alloc = Allocator()) {} + _null_range_type(InputIt /*first*/, InputIt /*last*/, const Allocator& /*alloc*/ = Allocator()) {} + _null_range_type(const _null_range_type& /*other*/) : Base() {} + _null_range_type(const _null_range_type& /*other*/, const Allocator& /*alloc*/) {} + _null_range_type(_null_range_type&& /*other*/) noexcept {} + _null_range_type(_null_range_type&& /*other*/, const Allocator& /*alloc*/) {} + _null_range_type(std::initializer_list /*init*/, const Allocator& /*alloc*/ = Allocator()) {} }; inline static _null_range_type null_predecessors; @@ -96,10 +97,11 @@ void dijkstra_clrs( { using id_type = vertex_id_t; using weight_type = invoke_result_t&, edge_t>; + using pred_id_type = range_value_t; // Remark(Andrew): Do we want to allow null distance? What about if both are null? Still run algorithm at all? - size_t N(num_vertices(g)); + [[maybe_unused]] size_t N(num_vertices(g)); assert(seed < N && seed >= 0); std::ranges::fill(distance, std::numeric_limits::max()); @@ -127,7 +129,7 @@ void dijkstra_clrs( if (distance[uid] + w < distance[vid]) { distance[vid] = distance[uid] + w; if constexpr (!is_same_v) - predecessor[vid] = uid; + predecessor[vid] = static_cast(uid); Q.push({vid, distance[vid]}); } } diff --git a/examples/dijkstra_clrs_example.cpp b/examples/dijkstra_clrs_example.cpp index d6b4c45..53b5ec3 100644 --- a/examples/dijkstra_clrs_example.cpp +++ b/examples/dijkstra_clrs_example.cpp @@ -12,7 +12,6 @@ #include #include #include "graph/graph.hpp" -#include "graph/container/dynamic_graph.hpp" #include "graph/container/traits/vol_graph_traits.hpp" #include "dijkstra_clrs.hpp" @@ -27,26 +26,26 @@ using Graph = container::dynamic_graph>; -void print_path(const vector& predecessor, unsigned source, unsigned target) { - if (target == source) { - cout << target; +void print_path(const vector& predecessor, unsigned src, unsigned dst) { + if (dst == src) { + cout << dst; return; } - if (predecessor[target] == numeric_limits::max()) { + if (predecessor[dst] == numeric_limits::max()) { cout << "No path exists"; return; } // Build path in reverse vector path; - unsigned current = target; - while (current != source) { + unsigned current = dst; + while (current != src) { path.push_back(current); current = predecessor[current]; } - path.push_back(source); + path.push_back(src); - // Print path from source to target + // Print path from src to dst for (auto it = path.rbegin(); it != path.rend(); ++it) { cout << *it; if (it + 1 != path.rend()) @@ -85,27 +84,27 @@ int main() { cout << "Graph created with " << num_vertices(g) << " vertices\n\n"; // Run Dijkstra's algorithm from vertex 0 - unsigned source = 0; + unsigned src = 0; vector distance(num_vertices(g)); vector predecessor(num_vertices(g)); // Weight function extracts the edge value - auto weight_fn = [](const auto& g, const auto& edge_desc) -> double { return edge_value(g, edge_desc); }; + auto weight_fn = [](const auto& gr, const auto& edge_desc) -> double { return edge_value(gr, edge_desc); }; - dijkstra_clrs(g, source, distance, predecessor, weight_fn); + dijkstra_clrs(g, src, distance, predecessor, weight_fn); // Print results - cout << "Shortest paths from vertex " << source << ":\n"; + cout << "Shortest paths from vertex " << src << ":\n"; cout << string(50, '-') << "\n"; - for (unsigned target = 0; target < num_vertices(g); ++target) { - cout << "To vertex " << target << ": "; + for (unsigned dst = 0; dst < num_vertices(g); ++dst) { + cout << "To vertex " << dst << ": "; - if (distance[target] == numeric_limits::max()) { + if (distance[dst] == numeric_limits::max()) { cout << "unreachable\n"; } else { - cout << "distance = " << distance[target] << ", path = "; - print_path(predecessor, source, target); + cout << "distance = " << distance[dst] << ", path = "; + print_path(predecessor, src, dst); cout << "\n"; } } @@ -114,31 +113,31 @@ int main() { // Example: Find specific path unsigned destination = 3; - cout << "\nShortest path from " << source << " to " << destination << ":\n"; + cout << "\nShortest path from " << src << " to " << destination << ":\n"; cout << "Distance: " << distance[destination] << "\n"; cout << "Path: "; - print_path(predecessor, source, destination); + print_path(predecessor, src, destination); cout << "\n"; // Run from a different source cout << "\n" << string(50, '=') << "\n\n"; - source = 2; + src = 2; fill(distance.begin(), distance.end(), 0.0); fill(predecessor.begin(), predecessor.end(), numeric_limits::max()); - dijkstra_clrs(g, source, distance, predecessor, weight_fn); + dijkstra_clrs(g, src, distance, predecessor, weight_fn); - cout << "Shortest paths from vertex " << source << ":\n"; + cout << "Shortest paths from vertex " << src << ":\n"; cout << string(50, '-') << "\n"; - for (unsigned target = 0; target < num_vertices(g); ++target) { - cout << "To vertex " << target << ": "; + for (unsigned dst = 0; dst < num_vertices(g); ++dst) { + cout << "To vertex " << dst << ": "; - if (distance[target] == numeric_limits::max()) { + if (distance[dst] == numeric_limits::max()) { cout << "unreachable\n"; } else { - cout << "distance = " << distance[target] << ", path = "; - print_path(predecessor, source, target); + cout << "distance = " << distance[dst] << ", path = "; + print_path(predecessor, src, dst); cout << "\n"; } } diff --git a/examples/mst_usage_example.cpp b/examples/mst_usage_example.cpp index c96847a..6f0e8d3 100644 --- a/examples/mst_usage_example.cpp +++ b/examples/mst_usage_example.cpp @@ -68,7 +68,7 @@ int main() { // Example 4: Prim's algorithm with validation std::cout << "\n=== Prim's Algorithm Example ===\n\n"; - using Graph = container::dynamic_graph>; + using Graph = container::vov_graph; // Create undirected weighted graph Graph g({{0, 1, 4}, {1, 0, 4}, {1, 2, 8}, {2, 1, 8}, {2, 0, 11}, {0, 2, 11}, {0, 2, 2}, {2, 0, 2}}); diff --git a/include/graph/adaptors/filtered_graph.hpp b/include/graph/adaptors/filtered_graph.hpp index 7a52e31..2b61271 100644 --- a/include/graph/adaptors/filtered_graph.hpp +++ b/include/graph/adaptors/filtered_graph.hpp @@ -98,8 +98,8 @@ class filtering_iterator { using reference = std::iter_reference_t; filtering_iterator() = default; - filtering_iterator(BaseIter begin, BaseIter end, Pred pred) - : current_(begin), end_(end), pred_(std::move(pred)) { + filtering_iterator(BaseIter begin_it, BaseIter end_it, Pred pred) + : current_(begin_it), end_(end_it), pred_(std::move(pred)) { advance_to_valid(); } diff --git a/include/graph/adj_list/detail/graph_cpo.hpp b/include/graph/adj_list/detail/graph_cpo.hpp index c8ed0af..beb36e5 100644 --- a/include/graph/adj_list/detail/graph_cpo.hpp +++ b/include/graph/adj_list/detail/graph_cpo.hpp @@ -450,7 +450,9 @@ namespace _cpo_impls { if constexpr (_has_member) { return {_St::_member, noexcept(std::declval().find_vertex(std::declval()))}; } else if constexpr (_has_adl) { - return {_St::_adl, noexcept(find_vertex(std::declval(), std::declval()))}; + // Avoid probing ADL noexcept with a potentially convertible VId type, + // which can trigger MSVC conversion warnings under /WX. + return {_St::_adl, false}; } else if constexpr (_has_associative) { constexpr bool no_throw_find = noexcept(std::declval().find(std::declval())); // Note: We directly construct iterator from map iterator @@ -2070,8 +2072,8 @@ namespace _cpo_impls { return {_St_uid::_member, noexcept(std::declval().find_vertex_edge(std::declval(), std::declval()))}; } else if constexpr (_has_adl_uid) { - return {_St_uid::_adl, - noexcept(find_vertex_edge(std::declval(), std::declval(), std::declval()))}; + // Avoid probing ADL noexcept with potentially narrowing ID conversions under /WX. + return {_St_uid::_adl, false}; } else if constexpr (_has_default_uid) { return {_St_uid::_default, false}; } else { @@ -2172,16 +2174,34 @@ namespace _cpo_impls { using _G = std::remove_cvref_t; using _U = std::remove_cvref_t; using _VId = std::remove_cvref_t; + using _GVId = vertex_id_t<_G>; if constexpr (_Choice_uid<_G, _U, _VId>._Strategy == _St_uid::_member) { return g.find_vertex_edge(u, vid); } else if constexpr (_Choice_uid<_G, _U, _VId>._Strategy == _St_uid::_adl) { - return find_vertex_edge(g, u, vid); + if constexpr (std::integral<_VId> && std::integral<_GVId> && (sizeof(_VId) > sizeof(_GVId))) { + auto edge_range = edges(std::forward(g), u); + using _CmpId = std::common_type_t<_GVId, _VId>; + auto it = std::ranges::find_if(edge_range, [&](const auto& e) { + return static_cast<_CmpId>(target_id(std::forward(g), e)) == static_cast<_CmpId>(vid); + }); + return *it; + } else if constexpr (std::integral<_U>) { + return find_vertex_edge(g, static_cast<_GVId>(u), static_cast<_GVId>(vid)); + } else { + auto edge_range = edges(std::forward(g), u); + using _CmpId = std::common_type_t<_GVId, _VId>; + auto it = std::ranges::find_if(edge_range, [&](const auto& e) { + return static_cast<_CmpId>(target_id(std::forward(g), e)) == static_cast<_CmpId>(vid); + }); + return *it; + } } else if constexpr (_Choice_uid<_G, _U, _VId>._Strategy == _St_uid::_default) { // Default: iterate edges(g,u) and find edge with matching target_id auto edge_range = edges(std::forward(g), u); + using _CmpId = std::common_type_t<_GVId, _VId>; auto it = std::ranges::find_if(edge_range, [&](const auto& e) { - return static_cast>(target_id(std::forward(g), e)) == static_cast>(vid); + return static_cast<_CmpId>(target_id(std::forward(g), e)) == static_cast<_CmpId>(vid); }); // Not found - return end as an edge descriptor return *it; diff --git a/include/graph/adj_list/edge_descriptor_view.hpp b/include/graph/adj_list/edge_descriptor_view.hpp index 9d44fec..1a0f188 100644 --- a/include/graph/adj_list/edge_descriptor_view.hpp +++ b/include/graph/adj_list/edge_descriptor_view.hpp @@ -42,8 +42,8 @@ class edge_descriptor_view : public std::ranges::view_interface(std::distance(begin_val, end_val)); } /** * @brief Construct view from non-const edge container and source vertex (per-vertex adjacency) * @param container The underlying edge container - * @param source The source vertex for all edges in this container + * @param src_vertex The source vertex for all edges in this container */ template requires requires(Container& c) { { c.begin() } -> std::convertible_to; { c.end() } -> std::convertible_to; } - constexpr edge_descriptor_view(Container& container, vertex_desc source) noexcept : source_(source) { + constexpr edge_descriptor_view(Container& container, vertex_desc src_vertex) noexcept : source_(src_vertex) { begin_ = container.begin(); end_ = container.end(); if constexpr(std::ranges::sized_range) { @@ -113,7 +113,7 @@ class edge_descriptor_view : public std::ranges::view_interface std::convertible_to; { c.end() } -> std::convertible_to; } - constexpr edge_descriptor_view(const Container& container, vertex_desc source) noexcept : source_(source) { + constexpr edge_descriptor_view(const Container& container, vertex_desc src_vertex) noexcept : source_(src_vertex) { begin_ = container.begin(); end_ = container.end(); if constexpr(std::ranges::sized_range) { diff --git a/include/graph/algorithm/articulation_points.hpp b/include/graph/algorithm/articulation_points.hpp index 87874e3..912d396 100644 --- a/include/graph/algorithm/articulation_points.hpp +++ b/include/graph/algorithm/articulation_points.hpp @@ -120,7 +120,12 @@ using adj_list::find_vertex; template > requires std::output_iterator> void articulation_points(G&& g, Iter cut_vertices, const Alloc& alloc = Alloc()) { - using vid_t = vertex_id_t; + using vid_t = typename std::remove_cvref_t::vertex_id_type; + using iter_t = std::remove_cvref_t; + using out_t = std::conditional_t< + requires { typename iter_t::container_type::value_type; }, + typename iter_t::container_type::value_type, + vid_t>; const size_t N = num_vertices(g); if (N == 0) { @@ -161,13 +166,14 @@ void articulation_points(G&& g, Iter cut_vertices, const Alloc& alloc = Alloc()) // Outer loop: handle disconnected graphs for (auto [start] : views::basic_vertexlist(g)) { - if (disc[start] != UNVISITED) { + const vid_t start_id = static_cast(start); + if (disc[start_id] != UNVISITED) { continue; } - disc[start] = low[start] = timer++; - auto start_edges = edges(g, start); - stk.push({start, std::ranges::begin(start_edges), + disc[start_id] = low[start_id] = timer++; + auto start_edges = edges(g, start_id); + stk.push({start_id, std::ranges::begin(start_edges), std::ranges::end(start_edges), false}); while (!stk.empty()) { @@ -187,7 +193,7 @@ void articulation_points(G&& g, Iter cut_vertices, const Alloc& alloc = Alloc()) if (parent[par_uid].has_value()) { // Non-root rule: child v has low[v] >= disc[u] if (low[uid] >= disc[par_uid] && !emitted[par_uid]) { - *cut_vertices++ = par_uid; + *cut_vertices++ = static_cast(par_uid); emitted[par_uid] = true; } } @@ -195,7 +201,7 @@ void articulation_points(G&& g, Iter cut_vertices, const Alloc& alloc = Alloc()) continue; } - vid_t vid = target_id(g, *it); + vid_t vid = static_cast(target_id(g, *it)); ++it; // advance stored iterator for next resume // Skip self-loops @@ -223,9 +229,9 @@ void articulation_points(G&& g, Iter cut_vertices, const Alloc& alloc = Alloc()) } // Root rule: root is an articulation point iff it has >= 2 DFS children - if (child_count[start] >= 2 && !emitted[start]) { - *cut_vertices++ = start; - emitted[start] = true; + if (child_count[start_id] >= 2 && !emitted[start_id]) { + *cut_vertices++ = static_cast(start_id); + emitted[start_id] = true; } } } diff --git a/include/graph/algorithm/bellman_ford_shortest_paths.hpp b/include/graph/algorithm/bellman_ford_shortest_paths.hpp index 8b911c5..2d6508e 100644 --- a/include/graph/algorithm/bellman_ford_shortest_paths.hpp +++ b/include/graph/algorithm/bellman_ford_shortest_paths.hpp @@ -57,7 +57,7 @@ using adj_list::target_id; */ template requires output_iterator> -void find_negative_cycle(G& g, +void find_negative_cycle(G& /*g*/, const Predecessors& predecessor, const optional>& cycle_vertex_id, OutputIterator out_cycle) { @@ -230,7 +230,7 @@ requires distance_fn_for && // DistanceFn&& distance, PredecessorFn&& predecessor, WF&& weight = - [](const auto&, const edge_t& uv) { + [](const auto&, const edge_t&) { return distance_fn_value_t(1); }, // default weight(g, uv) -> 1 Visitor&& visitor = empty_visitor(), @@ -248,7 +248,7 @@ requires distance_fn_for && // // relaxing the target is the function of reducing the distance from the source to the target auto relax_target = [&g, &predecessor, &distance, &compare, &combine] // (const edge_t& e, const vertex_id_t& uid, const weight_type& w_e) -> bool { - const id_type vid = target_id(g, e); + const id_type vid = static_cast(target_id(g, e)); const DistanceValue d_u = distance(g, uid); if (d_u == infinite) return false; // Cannot relax via unreachable vertex (also guards against overflow) @@ -348,17 +348,17 @@ requires distance_fn_for && // basic_edge_weight_function, Compare, Combine> [[nodiscard]] constexpr optional> bellman_ford_shortest_paths( G&& g, - const vertex_id_t& source, + const vertex_id_t& start_vertex_id, DistanceFn&& distance, PredecessorFn&& predecessor, WF&& weight = - [](const auto&, const edge_t& uv) { + [](const auto&, const edge_t&) { return distance_fn_value_t(1); }, // default weight(g, uv) -> 1 Visitor&& visitor = empty_visitor(), Compare&& compare = less>(), Combine&& combine = plus>()) { - return bellman_ford_shortest_paths(g, subrange(&source, (&source + 1)), distance, predecessor, weight, + return bellman_ford_shortest_paths(g, subrange(&start_vertex_id, (&start_vertex_id + 1)), distance, predecessor, weight, forward(visitor), forward(compare), forward(combine)); } @@ -411,7 +411,7 @@ requires distance_fn_for && // const Sources& sources, DistanceFn&& distance, WF&& weight = - [](const auto&, const edge_t& uv) { + [](const auto&, const edge_t&) { return distance_fn_value_t(1); }, // default weight(g, uv) -> 1 Visitor&& visitor = empty_visitor(), @@ -443,16 +443,16 @@ requires distance_fn_for && // basic_edge_weight_function, Compare, Combine> [[nodiscard]] constexpr optional> bellman_ford_shortest_distances( G&& g, - const vertex_id_t& source, + const vertex_id_t& start_vertex_id, DistanceFn&& distance, WF&& weight = - [](const auto&, const edge_t& uv) { + [](const auto&, const edge_t&) { return distance_fn_value_t(1); }, // default weight(g, uv) -> 1 Visitor&& visitor = empty_visitor(), Compare&& compare = less>(), Combine&& combine = plus>()) { - return bellman_ford_shortest_paths(g, subrange(&source, (&source + 1)), distance, _null_predecessor, + return bellman_ford_shortest_paths(g, subrange(&start_vertex_id, (&start_vertex_id + 1)), distance, _null_predecessor, forward(weight), forward(visitor), forward(compare), forward(combine)); } diff --git a/include/graph/algorithm/biconnected_components.hpp b/include/graph/algorithm/biconnected_components.hpp index 96b13e7..4ce80eb 100644 --- a/include/graph/algorithm/biconnected_components.hpp +++ b/include/graph/algorithm/biconnected_components.hpp @@ -203,7 +203,11 @@ void biconnected_components(G&& g, OuterContainer& components, const Alloc& allo break; } } - inner_type comp(vset.begin(), vset.end()); + inner_type comp; + comp.reserve(vset.size()); + for (const auto vv : vset) { + comp.push_back(static_cast(vv)); + } components.push_back(std::move(comp)); }; diff --git a/include/graph/algorithm/breadth_first_search.hpp b/include/graph/algorithm/breadth_first_search.hpp index 2813990..4099af5 100644 --- a/include/graph/algorithm/breadth_first_search.hpp +++ b/include/graph/algorithm/breadth_first_search.hpp @@ -272,11 +272,11 @@ void breadth_first_search(G&& g, // graph */ template > void breadth_first_search(G&& g, // graph - const vertex_id_t& source, // starting vertex_id + const vertex_id_t& start_vertex_id, // starting vertex_id Visitor&& visitor = empty_visitor(), const Alloc& alloc = Alloc()) { // Wrap single source in array and delegate to multi-source version - std::array, 1> sources{source}; + std::array, 1> sources{start_vertex_id}; breadth_first_search(std::forward(g), sources, std::forward(visitor), alloc); } diff --git a/include/graph/algorithm/connected_components.hpp b/include/graph/algorithm/connected_components.hpp index b3ef327..05556f6 100644 --- a/include/graph/algorithm/connected_components.hpp +++ b/include/graph/algorithm/connected_components.hpp @@ -209,7 +209,7 @@ void kosaraju(G&& g, // graph // Each DFS tree in this pass corresponds to exactly one SCC using gt_vertex_desc = vertex_t>; using GtVDescAlloc = typename std::allocator_traits::template rebind_alloc; - size_t cid = 0; + CT cid = 0; std::ranges::reverse_view reverse{order}; for (auto& uid : reverse) { if (component(g, uid) == std::numeric_limits::max()) { @@ -355,7 +355,7 @@ void kosaraju(G&& g, // bidirectional graph // Second pass: DFS on reverse edges (via in_edges) in reverse finish order. // Each DFS tree corresponds to exactly one SCC. - size_t cid = 0; + CT cid = 0; std::ranges::reverse_view reverse{order}; for (auto& u : reverse) { auto uid = vertex_id(g_ref, u); @@ -559,7 +559,7 @@ static void link(vertex_id_t u, vertex_id_t v, Component& component) { if (p_high == high) { // high is a root (points to itself) if (component[high] == high) { - component[high] = low; // Link high root to low + component[high] = static_cast>(low); // Link high root to low break; } else { // Race condition: another thread changed it; retry with low diff --git a/include/graph/algorithm/depth_first_search.hpp b/include/graph/algorithm/depth_first_search.hpp index 96daffe..5e7c8b3 100644 --- a/include/graph/algorithm/depth_first_search.hpp +++ b/include/graph/algorithm/depth_first_search.hpp @@ -165,7 +165,7 @@ using adj_list::find_vertex; template > void depth_first_search(G&& g, // graph - const vertex_id_t& source, // starting vertex_id + const vertex_id_t& start_vertex_id, // starting vertex_id Visitor&& visitor = empty_visitor(), const Alloc& alloc = Alloc()) { using id_type = vertex_id_t; @@ -188,23 +188,23 @@ void depth_first_search(G&& g, // graph // Initialize source vertex if constexpr (has_on_initialize_vertex) { - visitor.on_initialize_vertex(g, *find_vertex(g, source)); + visitor.on_initialize_vertex(g, *find_vertex(g, start_vertex_id)); } else if constexpr (has_on_initialize_vertex_id) { - visitor.on_initialize_vertex(g, source); + visitor.on_initialize_vertex(g, start_vertex_id); } // Notify visitor that we're starting from this source if constexpr (has_on_start_vertex) { - auto src_vertex = *find_vertex(g, source); + auto src_vertex = *find_vertex(g, start_vertex_id); visitor.on_start_vertex(g, src_vertex); } else if constexpr (has_on_start_vertex_id) { - visitor.on_start_vertex(g, source); + visitor.on_start_vertex(g, start_vertex_id); } // Each stack frame stores a vertex and iterators into its incidence range, // simulating the call stack of recursive DFS for correct edge classification. - using inc_range_t = decltype(views::incidence(g, *find_vertex(g, source))); + using inc_range_t = decltype(views::incidence(g, *find_vertex(g, start_vertex_id))); using inc_iterator_t = std::ranges::iterator_t; using inc_sentinel_t = std::ranges::sentinel_t; @@ -215,18 +215,18 @@ void depth_first_search(G&& g, // graph }; // Discover source and push its stack frame - color[source] = Color::Gray; + color[start_vertex_id] = Color::Gray; if constexpr (has_on_discover_vertex) { - visitor.on_discover_vertex(g, *find_vertex(g, source)); + visitor.on_discover_vertex(g, *find_vertex(g, start_vertex_id)); } else if constexpr (has_on_discover_vertex_id) { - visitor.on_discover_vertex(g, source); + visitor.on_discover_vertex(g, start_vertex_id); } using FrameAlloc = typename std::allocator_traits::template rebind_alloc; std::stack> S{std::deque(FrameAlloc(alloc))}; { - auto inc = views::incidence(g, *find_vertex(g, source)); - S.push({source, std::ranges::begin(inc), std::ranges::end(inc)}); + auto inc = views::incidence(g, *find_vertex(g, start_vertex_id)); + S.push({start_vertex_id, std::ranges::begin(inc), std::ranges::end(inc)}); } while (!S.empty()) { @@ -272,19 +272,19 @@ void depth_first_search(G&& g, // graph } auto inc = views::incidence(g, *find_vertex(g, vid)); S.push({vid, std::ranges::begin(inc), std::ranges::end(inc)}); - } else if (target_color == Color::Gray) { - // Back edge: target is an ancestor still being processed (cycle) - if constexpr (has_on_back_edge) { - visitor.on_back_edge(g, uv); - } - if constexpr (has_on_finish_edge) { - visitor.on_finish_edge(g, uv); - } } else { - // Forward or cross edge: target is already finished (Black) - if constexpr (has_on_forward_or_cross_edge) { - visitor.on_forward_or_cross_edge(g, uv); + if (target_color == Color::Gray) { + // Back edge: target is an ancestor still being processed (cycle) + if constexpr (has_on_back_edge) { + visitor.on_back_edge(g, uv); + } + } else { + // Forward or cross edge: target is already finished (Black) + if constexpr (has_on_forward_or_cross_edge) { + visitor.on_forward_or_cross_edge(g, uv); + } } + if constexpr (has_on_finish_edge) { visitor.on_finish_edge(g, uv); } diff --git a/include/graph/algorithm/dijkstra_shortest_paths.hpp b/include/graph/algorithm/dijkstra_shortest_paths.hpp index 4df527c..db11f33 100644 --- a/include/graph/algorithm/dijkstra_shortest_paths.hpp +++ b/include/graph/algorithm/dijkstra_shortest_paths.hpp @@ -237,6 +237,7 @@ constexpr void dijkstra_shortest_paths( const Alloc& alloc = Alloc()) { using graph_type = std::remove_reference_t; using id_type = vertex_id_t; + using pred_id_type = predecessor_fn_value_t; using distance_type = distance_fn_value_t; using weight_type = invoke_result_t>; @@ -246,7 +247,7 @@ constexpr void dijkstra_shortest_paths( // relaxing the target is the function of reducing the distance from the source to the target auto relax_target = [&g, &predecessor, &distance, &compare, &combine, &weight] // (const edge_t& uv, const vertex_id_t& uid) -> bool { - const id_type vid = target_id(g, uv); + const id_type vid = static_cast(target_id(g, uv)); const distance_type d_u = distance(g, uid); const distance_type d_v = distance(g, vid); const weight_type w_uv = weight(g, uv); @@ -266,7 +267,7 @@ constexpr void dijkstra_shortest_paths( if (compare(combine(d_u, w_uv), d_v)) { distance(g, vid) = combine(d_u, w_uv); if constexpr (!is_null_predecessor_fn_v) { - predecessor(g, vid) = uid; + predecessor(g, vid) = static_cast(uid); } return true; } @@ -555,11 +556,11 @@ requires distance_fn_for && // basic_edge_weight_function, Compare, Combine> constexpr void dijkstra_shortest_paths( G&& g, - const vertex_id_t& source, + const vertex_id_t& start_vertex_id, DistanceFn&& distance, PredecessorFn&& predecessor, WF&& weight = - [](const auto&, const edge_t& uv) { + [](const auto&, const edge_t&) { return distance_fn_value_t(1); }, // default weight(g, uv) -> 1 Visitor&& visitor = empty_visitor(), @@ -567,7 +568,7 @@ constexpr void dijkstra_shortest_paths( Combine&& combine = plus>(), Heap heap_tag = Heap{}, const Alloc& alloc = Alloc()) { - dijkstra_shortest_paths(g, subrange(&source, (&source + 1)), distance, predecessor, weight, + dijkstra_shortest_paths(g, subrange(&start_vertex_id, (&start_vertex_id + 1)), distance, predecessor, weight, forward(visitor), forward(compare), forward(combine), heap_tag, alloc); } @@ -624,7 +625,7 @@ constexpr void dijkstra_shortest_distances( const Sources& sources, DistanceFn&& distance, WF&& weight = - [](const auto&, const edge_t& uv) { + [](const auto&, const edge_t&) { return distance_fn_value_t(1); }, // default weight(g, uv) -> 1 Visitor&& visitor = empty_visitor(), @@ -662,10 +663,10 @@ requires distance_fn_for && basic_edge_weight_function, Compare, Combine> constexpr void dijkstra_shortest_distances( G&& g, - const vertex_id_t& source, + const vertex_id_t& start_vertex_id, DistanceFn&& distance, WF&& weight = - [](const auto&, const edge_t& uv) { + [](const auto&, const edge_t&) { return distance_fn_value_t(1); }, // default weight(g, uv) -> 1 Visitor&& visitor = empty_visitor(), @@ -673,7 +674,7 @@ constexpr void dijkstra_shortest_distances( Combine&& combine = plus>(), Heap heap_tag = Heap{}, const Alloc& alloc = Alloc()) { - dijkstra_shortest_paths(g, subrange(&source, (&source + 1)), distance, _null_predecessor, forward(weight), + dijkstra_shortest_paths(g, subrange(&start_vertex_id, (&start_vertex_id + 1)), distance, _null_predecessor, forward(weight), forward(visitor), forward(compare), forward(combine), heap_tag, alloc); } diff --git a/include/graph/algorithm/jaccard.hpp b/include/graph/algorithm/jaccard.hpp index 66fe1a1..b24b733 100644 --- a/include/graph/algorithm/jaccard.hpp +++ b/include/graph/algorithm/jaccard.hpp @@ -113,9 +113,13 @@ using adj_list::num_vertices; * ``` */ template -requires std::invocable, vertex_id_t, edge_t&, T> +requires std::invocable::vertex_id_type, + typename std::remove_cvref_t::vertex_id_type, + edge_t&, + T> void jaccard_coefficient(G&& g, OutOp out) { - using vid_t = vertex_id_t; + using vid_t = typename std::remove_cvref_t::vertex_id_type; if (num_vertices(g) == 0) { return; @@ -128,8 +132,10 @@ void jaccard_coefficient(G&& g, OutOp out) { using nbr_set = std::unordered_set; auto nbrs = make_vertex_property_map, nbr_set>(g, nbr_set{}); - for (auto [uid] : views::basic_vertexlist(g)) { - for (auto [tid] : views::basic_incidence(g, uid)) { + for (auto&& [uid_raw] : views::basic_vertexlist(g)) { + const vid_t uid = static_cast(uid_raw); + for (auto&& [tid_raw] : views::basic_incidence(g, uid)) { + const vid_t tid = static_cast(tid_raw); if (tid != uid) { // skip self-loops nbrs[uid].insert(tid); } @@ -139,8 +145,10 @@ void jaccard_coefficient(G&& g, OutOp out) { // ============================================================================ // Phase 2: For every directed edge, compute and report the Jaccard coefficient // ============================================================================ - for (auto&& [uid, u] : views::vertexlist(g)) { - for (auto&& [vid, uv] : views::incidence(g, u)) { + for (auto&& [uid_raw, u] : views::vertexlist(g)) { + const vid_t uid = static_cast(uid_raw); + for (auto&& [vid_raw, uv] : views::incidence(g, u)) { + const vid_t vid = static_cast(vid_raw); // Skip self-loops if (vid == uid) { continue; @@ -162,7 +170,7 @@ void jaccard_coefficient(G&& g, OutOp out) { T val = (union_size == 0) ? T{0} : static_cast(intersect_size) / static_cast(union_size); - out(uid, vid, uv, val); + out(static_cast(uid), static_cast(vid), uv, val); } } } diff --git a/include/graph/algorithm/mis.hpp b/include/graph/algorithm/mis.hpp index b6ab5c1..9626103 100755 --- a/include/graph/algorithm/mis.hpp +++ b/include/graph/algorithm/mis.hpp @@ -1,10 +1,16 @@ /** * @file mis.hpp - * +requires output_iterator> * @brief Maximal Independent Set (MIS) algorithm for graphs. * * @copyright Copyright (c) 2024 * + using graph_vid_t = typename std::remove_cvref_t::vertex_id_type; + using iter_t = std::remove_cvref_t; + using out_vid_t = std::conditional_t< + requires { typename iter_t::container_type::value_type; }, + typename iter_t::container_type::value_type, + graph_vid_t>; * SPDX-License-Identifier: BSL-1.0 * * @authors @@ -120,6 +126,9 @@ size_t maximal_independent_set(G&& g, // graph Iter mis, // out: maximal independent set const vertex_id_t& seed = 0 // seed vtx ) { + using graph_vid_t = typename std::remove_cvref_t::vertex_id_type; + using out_vid_t = graph_vid_t; + size_t N = num_vertices(g); if (N == 0) { return 0; @@ -132,7 +141,7 @@ size_t maximal_independent_set(G&& g, // graph auto removed_vertices = make_vertex_property_map(g, uint8_t{0}); // Mark seed vertex as removed - removed_vertices[seed] = 1; + removed_vertices[static_cast(seed)] = 1; // Check if seed vertex has a self-loop bool seed_has_self_loop = false; @@ -145,22 +154,22 @@ size_t maximal_independent_set(G&& g, // graph // Only add seed to MIS if it has no self-loop if (!seed_has_self_loop) { - *mis++ = seed; + *mis++ = static_cast(seed); ++count; // Mark neighbors as removed for (auto uv : edges(g, *seed_vit)) { - removed_vertices[target_id(g, uv)] = 1; + removed_vertices[static_cast(target_id(g, uv))] = 1; } } for (auto u : vertices(g)) { - vertex_id_t uid = vertex_id(g, u); + graph_vid_t uid = static_cast(vertex_id(g, u)); if (!removed_vertices[uid]) { - *mis++ = uid; + *mis++ = static_cast(uid); ++count; removed_vertices[uid] = 1; for (auto uv : edges(g, u)) { - removed_vertices[target_id(g, uv)] = 1; + removed_vertices[static_cast(target_id(g, uv))] = 1; } } } diff --git a/include/graph/algorithm/mst.hpp b/include/graph/algorithm/mst.hpp index 84638a3..82bfbc1 100644 --- a/include/graph/algorithm/mst.hpp +++ b/include/graph/algorithm/mst.hpp @@ -983,7 +983,7 @@ auto prim(G&& g, // graph auto wf_ref = std::ref(weight_fn); auto guarded_weight_fn = [&finalized, wf_ref]( const GraphT& gr, const edge_t& uv) -> edge_value_type { - const id_type vid = target_id(gr, uv); + const id_type vid = static_cast(target_id(gr, uv)); if (finalized[static_cast(vid)]) { return infinite_distance(); } @@ -1010,7 +1010,7 @@ auto prim(G&& g, // graph auto wf_ref = std::ref(weight_fn); auto guarded_weight_fn = [&finalized, wf_ref]( const GraphT& gr, const edge_t& uv) -> edge_value_type { - const id_type vid = target_id(gr, uv); + const id_type vid = static_cast(target_id(gr, uv)); if (finalized.contains(vid)) { return infinite_distance(); } diff --git a/include/graph/algorithm/topological_sort.hpp b/include/graph/algorithm/topological_sort.hpp index 9432783..6da659b 100644 --- a/include/graph/algorithm/topological_sort.hpp +++ b/include/graph/algorithm/topological_sort.hpp @@ -174,7 +174,7 @@ namespace detail { */ template void topological_sort_dfs_visit(const G& g, - const vertex_id_t& source, + const vertex_id_t& start_vertex_id, ColorMap& color, auto& finish_order, bool& has_cycle, @@ -183,7 +183,7 @@ namespace detail { using Color = TopoColor; using id_type = vertex_id_t; using namespace graph::views; - using inc_range_t = decltype(basic_incidence(g, source)); + using inc_range_t = decltype(basic_incidence(g, start_vertex_id)); using inc_iterator_t = std::ranges::iterator_t; using inc_sentinel_t = std::ranges::sentinel_t; @@ -194,13 +194,13 @@ namespace detail { }; // Discover source and push its stack frame - color[source] = Color::Gray; + color[start_vertex_id] = Color::Gray; using FrameAlloc = typename std::allocator_traits::template rebind_alloc; std::stack> S{std::deque(FrameAlloc(alloc))}; { - auto inc = basic_incidence(g, source); - S.push({source, std::ranges::begin(inc), std::ranges::end(inc)}); + auto inc = basic_incidence(g, start_vertex_id); + S.push({start_vertex_id, std::ranges::begin(inc), std::ranges::end(inc)}); } while (!S.empty() && !has_cycle) { @@ -318,6 +318,11 @@ bool topological_sort(const G& g, const Sources& sources, OutputIterator result, const Alloc& alloc = Alloc()) { using id_type = vertex_id_t; using Color = detail::TopoColor; + using out_iter_t = std::remove_cvref_t; + using out_id_type = std::conditional_t< + requires { typename out_iter_t::container_type::value_type; }, + typename out_iter_t::container_type::value_type, + id_type>; // Lazy init: index graphs get a sized vector (value-init → White=0), // mapped graphs get an empty reserved map (absent key → White via get). @@ -329,9 +334,9 @@ bool topological_sort(const G& g, const Sources& sources, OutputIterator result, bool has_cycle = false; // Run DFS from each source (skipping already-visited vertices) - for (auto source : sources) { - if (vertex_property_map_get(color, source, Color::White) == Color::White) { - detail::topological_sort_dfs_visit(g, source, color, finish_order, has_cycle, alloc); + for (auto source_vid : sources) { + if (vertex_property_map_get(color, source_vid, Color::White) == Color::White) { + detail::topological_sort_dfs_visit(g, source_vid, color, finish_order, has_cycle, alloc); if (has_cycle) { return false; // Cycle detected } @@ -339,7 +344,9 @@ bool topological_sort(const G& g, const Sources& sources, OutputIterator result, } // Output vertices in reverse finish order (topological order) - std::ranges::copy(finish_order | std::views::reverse, result); + for (const auto vid : finish_order | std::views::reverse) { + *result++ = static_cast(vid); + } return true; } @@ -403,10 +410,10 @@ bool topological_sort(const G& g, const Sources& sources, OutputIterator result, */ template > requires std::output_iterator> -bool topological_sort(const G& g, const vertex_id_t& source, OutputIterator result, +bool topological_sort(const G& g, const vertex_id_t& start_vertex_id, OutputIterator result, const Alloc& alloc = Alloc()) { // Delegate to multi-source version with single source - std::array, 1> sources = {source}; + std::array, 1> sources = {start_vertex_id}; return topological_sort(g, sources, result, alloc); } @@ -476,6 +483,11 @@ requires std::output_iterator> bool topological_sort(const G& g, OutputIterator result, const Alloc& alloc = Alloc()) { using id_type = vertex_id_t; using Color = detail::TopoColor; + using out_iter_t = std::remove_cvref_t; + using out_id_type = std::conditional_t< + requires { typename out_iter_t::container_type::value_type; }, + typename out_iter_t::container_type::value_type, + id_type>; // Lazy init: index graphs get a sized vector (value-init → White=0), // mapped graphs get an empty reserved map (absent key → White via get). @@ -498,7 +510,9 @@ bool topological_sort(const G& g, OutputIterator result, const Alloc& alloc = Al } // Output vertices in reverse finish order (topological order) - std::ranges::copy(finish_order | std::views::reverse, result); + for (const auto vid : finish_order | std::views::reverse) { + *result++ = static_cast(vid); + } return true; } diff --git a/include/graph/container/compressed_graph.hpp b/include/graph/container/compressed_graph.hpp index d037014..7907f01 100644 --- a/include/graph/container/compressed_graph.hpp +++ b/include/graph/container/compressed_graph.hpp @@ -1255,7 +1255,7 @@ class compressed_graph_base */ template requires std::derived_from, compressed_graph_base> - [[nodiscard]] friend constexpr auto target_id(G&& g, const EdgeDesc& uv) noexcept { + [[nodiscard]] friend constexpr auto target_id(G&& /*g*/, const EdgeDesc& uv) noexcept { // Edge descriptor's value() returns an iterator into col_index_ return uv.value()->index; } diff --git a/include/graph/container/detail/undirected_adjacency_list_impl.hpp b/include/graph/container/detail/undirected_adjacency_list_impl.hpp index bf4bc3f..647cd8f 100644 --- a/include/graph/container/detail/undirected_adjacency_list_impl.hpp +++ b/include/graph/container/detail/undirected_adjacency_list_impl.hpp @@ -573,10 +573,12 @@ template class VContainer, typename Alloc> ual_edge::~ual_edge() noexcept { - vertex_edge_list_outward_link_type& outward_link = *static_cast(this); + [[maybe_unused]] vertex_edge_list_outward_link_type& outward_link = + *static_cast(this); assert(outward_link.prev() == nullptr && outward_link.next() == nullptr); // has edge been unlinked? - vertex_edge_list_inward_link_type& inward_link = *static_cast(this); + [[maybe_unused]] vertex_edge_list_inward_link_type& inward_link = + *static_cast(this); assert(inward_link.prev() == nullptr && inward_link.next() == nullptr); // has edge been unlinked? } @@ -771,7 +773,7 @@ template class VContainer, typename Alloc> -ual_vertex::ual_vertex([[maybe_unused]] vertex_set& vertices, +ual_vertex::ual_vertex([[maybe_unused]] vertex_set& vertex_store, [[maybe_unused]] vertex_index index) {} template class VContainer, typename Alloc> -ual_vertex::ual_vertex([[maybe_unused]] vertex_set& vertices, +ual_vertex::ual_vertex([[maybe_unused]] vertex_set& vertex_store, [[maybe_unused]] vertex_index index, const vertex_value_type& val) : base_value_type(val) {} @@ -789,7 +791,7 @@ template class VContainer, typename Alloc> -ual_vertex::ual_vertex([[maybe_unused]] vertex_set& vertices, +ual_vertex::ual_vertex([[maybe_unused]] vertex_set& vertex_store, [[maybe_unused]] vertex_index index, vertex_value_type&& val) noexcept : base_value_type(move(val)) {} diff --git a/include/graph/container/dynamic_graph.hpp b/include/graph/container/dynamic_graph.hpp index 2379e77..b138a80 100644 --- a/include/graph/container/dynamic_graph.hpp +++ b/include/graph/container/dynamic_graph.hpp @@ -4,11 +4,10 @@ #include #include #include -#include #include -#include #include "graph/graph.hpp" #include "graph/adj_list/vertex_descriptor_view.hpp" +#include "graph/adj_list/edge_descriptor_view.hpp" #include "container_utility.hpp" // load_vertices(vrng, vvalue_fnc) -> [uid,vval] diff --git a/include/graph/container/traits/dod_graph_traits.hpp b/include/graph/container/traits/dod_graph_traits.hpp index 44da931..2707998 100644 --- a/include/graph/container/traits/dod_graph_traits.hpp +++ b/include/graph/container/traits/dod_graph_traits.hpp @@ -2,17 +2,9 @@ #include -namespace graph::container { - -// Forward declarations -template -class dynamic_out_edge; - -template -class dynamic_vertex; +#include -template -class dynamic_graph; +namespace graph::container { // dod_graph_traits // Vertices: std::deque (stable iterators) @@ -34,4 +26,8 @@ struct dod_graph_traits { using edges_type = std::deque; }; +// Templated type alias for quick dod_graph definition +template +using dod_graph = dynamic_graph>; + } // namespace graph::container diff --git a/include/graph/container/traits/dofl_graph_traits.hpp b/include/graph/container/traits/dofl_graph_traits.hpp index d69955f..defbad4 100644 --- a/include/graph/container/traits/dofl_graph_traits.hpp +++ b/include/graph/container/traits/dofl_graph_traits.hpp @@ -3,17 +3,9 @@ #include #include -namespace graph::container { - -// Forward declarations -template -class dynamic_out_edge; - -template -class dynamic_vertex; +#include -template -class dynamic_graph; +namespace graph::container { // dofl_graph_traits // Vertices: std::deque (stable iterators) @@ -35,4 +27,8 @@ struct dofl_graph_traits { using edges_type = std::forward_list; }; +// Templated type alias for quick dofl_graph definition +template +using dofl_graph = dynamic_graph>; + } // namespace graph::container diff --git a/include/graph/container/traits/dol_graph_traits.hpp b/include/graph/container/traits/dol_graph_traits.hpp index 3881dea..2a0fa30 100644 --- a/include/graph/container/traits/dol_graph_traits.hpp +++ b/include/graph/container/traits/dol_graph_traits.hpp @@ -3,17 +3,9 @@ #include #include -namespace graph::container { - -// Forward declarations -template -class dynamic_out_edge; - -template -class dynamic_vertex; +#include -template -class dynamic_graph; +namespace graph::container { // dol_graph_traits // Vertices: std::deque (stable iterators) @@ -35,4 +27,8 @@ struct dol_graph_traits { using edges_type = std::list; }; +// Templated type alias for quick dol_graph definition +template +using dol_graph = dynamic_graph>; + } // namespace graph::container diff --git a/include/graph/container/traits/dos_graph_traits.hpp b/include/graph/container/traits/dos_graph_traits.hpp index c4c7773..60ec93a 100644 --- a/include/graph/container/traits/dos_graph_traits.hpp +++ b/include/graph/container/traits/dos_graph_traits.hpp @@ -3,17 +3,9 @@ #include #include -namespace graph::container { - -// Forward declarations -template -class dynamic_out_edge; - -template -class dynamic_vertex; +#include -template -class dynamic_graph; +namespace graph::container { // dos_graph_traits // Vertices: std::deque (stable references on push_back/push_front; random access by index) @@ -44,4 +36,8 @@ struct dos_graph_traits { using edges_type = std::set; }; +// Templated type alias for quick dos_graph definition +template +using dos_graph = dynamic_graph>; + } // namespace graph::container diff --git a/include/graph/container/traits/dous_graph_traits.hpp b/include/graph/container/traits/dous_graph_traits.hpp index e4de54c..53574d1 100644 --- a/include/graph/container/traits/dous_graph_traits.hpp +++ b/include/graph/container/traits/dous_graph_traits.hpp @@ -3,17 +3,9 @@ #include #include -namespace graph::container { - -// Forward declarations -template -class dynamic_out_edge; - -template -class dynamic_vertex; +#include -template -class dynamic_graph; +namespace graph::container { // dous_graph_traits // Vertices: std::deque (stable iterators; random access by vertex ID) @@ -52,4 +44,8 @@ struct dous_graph_traits { using edges_type = std::unordered_set; }; +// Templated type alias for quick dous_graph definition +template +using dous_graph = dynamic_graph>; + } // namespace graph::container diff --git a/include/graph/container/traits/dov_graph_traits.hpp b/include/graph/container/traits/dov_graph_traits.hpp index a840023..7220986 100644 --- a/include/graph/container/traits/dov_graph_traits.hpp +++ b/include/graph/container/traits/dov_graph_traits.hpp @@ -3,17 +3,9 @@ #include #include -namespace graph::container { - -// Forward declarations -template -class dynamic_out_edge; - -template -class dynamic_vertex; +#include -template -class dynamic_graph; +namespace graph::container { // dov_graph_traits // Vertices: std::deque (stable iterators) @@ -35,4 +27,8 @@ struct dov_graph_traits { using edges_type = std::vector; }; +// Templated type alias for quick dov_graph definition +template +using dov_graph = dynamic_graph>; + } // namespace graph::container diff --git a/include/graph/container/traits/mod_graph_traits.hpp b/include/graph/container/traits/mod_graph_traits.hpp index 8147556..3f2777e 100644 --- a/include/graph/container/traits/mod_graph_traits.hpp +++ b/include/graph/container/traits/mod_graph_traits.hpp @@ -4,17 +4,9 @@ #include #include -namespace graph::container { - -// Forward declarations -template -class dynamic_out_edge; - -template -class dynamic_vertex; +#include -template -class dynamic_graph; +namespace graph::container { // mod_graph_traits // Vertices: std::map (associative; key-based lookup; bidirectional iteration) @@ -43,4 +35,8 @@ struct mod_graph_traits { using edges_type = std::deque; }; +// Templated type alias for quick mod_graph definition +template +using mod_graph = dynamic_graph>; + } // namespace graph::container diff --git a/include/graph/container/traits/mofl_graph_traits.hpp b/include/graph/container/traits/mofl_graph_traits.hpp index 001a7c6..d766e39 100644 --- a/include/graph/container/traits/mofl_graph_traits.hpp +++ b/include/graph/container/traits/mofl_graph_traits.hpp @@ -4,17 +4,9 @@ #include #include -namespace graph::container { - -// Forward declarations -template -class dynamic_out_edge; - -template -class dynamic_vertex; +#include -template -class dynamic_graph; +namespace graph::container { // mofl_graph_traits // Vertices: std::map (associative; key-based lookup; bidirectional iteration) @@ -41,4 +33,8 @@ struct mofl_graph_traits { using edges_type = std::forward_list; }; +// Templated type alias for quick mofl_graph definition +template +using mofl_graph = dynamic_graph>; + } // namespace graph::container diff --git a/include/graph/container/traits/mol_graph_traits.hpp b/include/graph/container/traits/mol_graph_traits.hpp index e0608ac..f34f393 100644 --- a/include/graph/container/traits/mol_graph_traits.hpp +++ b/include/graph/container/traits/mol_graph_traits.hpp @@ -4,17 +4,9 @@ #include #include -namespace graph::container { - -// Forward declarations -template -class dynamic_out_edge; - -template -class dynamic_vertex; +#include -template -class dynamic_graph; +namespace graph::container { // mol_graph_traits // Vertices: std::map (associative; key-based lookup; bidirectional iteration) @@ -42,4 +34,8 @@ struct mol_graph_traits { using edges_type = std::list; }; +// Templated type alias for quick mol_graph definition +template +using mol_graph = dynamic_graph>; + } // namespace graph::container diff --git a/include/graph/container/traits/mom_graph_traits.hpp b/include/graph/container/traits/mom_graph_traits.hpp index d64320f..35811d7 100644 --- a/include/graph/container/traits/mom_graph_traits.hpp +++ b/include/graph/container/traits/mom_graph_traits.hpp @@ -2,17 +2,9 @@ #include -namespace graph::container { - -// Forward declarations -template -class dynamic_out_edge; - -template -class dynamic_vertex; +#include -template -class dynamic_graph; +namespace graph::container { // mom_graph_traits // Vertices: std::map (ordered map keyed by vertex ID) @@ -51,4 +43,8 @@ struct mom_graph_traits { using edges_type = std::map; // Map keyed by target vertex ID }; +// Templated type alias for quick mom_graph definition +template +using mom_graph = dynamic_graph>; + } // namespace graph::container diff --git a/include/graph/container/traits/mos_graph_traits.hpp b/include/graph/container/traits/mos_graph_traits.hpp index 924efe1..93a07fc 100644 --- a/include/graph/container/traits/mos_graph_traits.hpp +++ b/include/graph/container/traits/mos_graph_traits.hpp @@ -3,17 +3,9 @@ #include #include -namespace graph::container { - -// Forward declarations -template -class dynamic_out_edge; - -template -class dynamic_vertex; +#include -template -class dynamic_graph; +namespace graph::container { // mos_graph_traits // Vertices: std::map (associative; key-based lookup; bidirectional iteration) @@ -46,4 +38,8 @@ struct mos_graph_traits { using edges_type = std::set; }; +// Templated type alias for quick mos_graph definition +template +using mos_graph = dynamic_graph>; + } // namespace graph::container diff --git a/include/graph/container/traits/mous_graph_traits.hpp b/include/graph/container/traits/mous_graph_traits.hpp index 745fc45..613a261 100644 --- a/include/graph/container/traits/mous_graph_traits.hpp +++ b/include/graph/container/traits/mous_graph_traits.hpp @@ -3,17 +3,9 @@ #include #include -namespace graph::container { - -// Forward declarations -template -class dynamic_out_edge; - -template -class dynamic_vertex; +#include -template -class dynamic_graph; +namespace graph::container { // mous_graph_traits // Vertices: std::map (associative; key-based lookup; bidirectional iteration) @@ -52,4 +44,8 @@ struct mous_graph_traits { using edges_type = std::unordered_set; }; +// Templated type alias for quick mous_graph definition +template +using mous_graph = dynamic_graph>; + } // namespace graph::container diff --git a/include/graph/container/traits/mov_graph_traits.hpp b/include/graph/container/traits/mov_graph_traits.hpp index 2c041bf..c4f7ac2 100644 --- a/include/graph/container/traits/mov_graph_traits.hpp +++ b/include/graph/container/traits/mov_graph_traits.hpp @@ -4,17 +4,9 @@ #include #include -namespace graph::container { - -// Forward declarations -template -class dynamic_out_edge; - -template -class dynamic_vertex; +#include -template -class dynamic_graph; +namespace graph::container { // mov_graph_traits // Vertices: std::map (associative; key-based lookup; bidirectional iteration) @@ -42,4 +34,8 @@ struct mov_graph_traits { using edges_type = std::vector; }; +// Templated type alias for quick mov_graph definition +template +using mov_graph = dynamic_graph>; + } // namespace graph::container diff --git a/include/graph/container/traits/uod_graph_traits.hpp b/include/graph/container/traits/uod_graph_traits.hpp index 340d20f..da97d16 100644 --- a/include/graph/container/traits/uod_graph_traits.hpp +++ b/include/graph/container/traits/uod_graph_traits.hpp @@ -4,17 +4,9 @@ #include #include -namespace graph::container { - -// Forward declarations -template -class dynamic_out_edge; - -template -class dynamic_vertex; +#include -template -class dynamic_graph; +namespace graph::container { // uod_graph_traits // Vertices: std::unordered_map (hash-based; O(1) average lookup; unordered iteration) @@ -43,4 +35,8 @@ struct uod_graph_traits { using edges_type = std::deque; }; +// Templated type alias for quick uod_graph definition +template +using uod_graph = dynamic_graph>; + } // namespace graph::container diff --git a/include/graph/container/traits/uofl_graph_traits.hpp b/include/graph/container/traits/uofl_graph_traits.hpp index e35d371..e17b5bc 100644 --- a/include/graph/container/traits/uofl_graph_traits.hpp +++ b/include/graph/container/traits/uofl_graph_traits.hpp @@ -4,17 +4,9 @@ #include #include -namespace graph::container { - -// Forward declarations -template -class dynamic_out_edge; - -template -class dynamic_vertex; +#include -template -class dynamic_graph; +namespace graph::container { // uofl_graph_traits // Vertices: std::unordered_map (hash-based; O(1) average lookup; unordered iteration) @@ -42,4 +34,8 @@ struct uofl_graph_traits { using edges_type = std::forward_list; }; +// Templated type alias for quick uofl_graph definition +template +using uofl_graph = dynamic_graph>; + } // namespace graph::container diff --git a/include/graph/container/traits/uol_graph_traits.hpp b/include/graph/container/traits/uol_graph_traits.hpp index 1931259..b969cd6 100644 --- a/include/graph/container/traits/uol_graph_traits.hpp +++ b/include/graph/container/traits/uol_graph_traits.hpp @@ -4,17 +4,9 @@ #include #include -namespace graph::container { - -// Forward declarations -template -class dynamic_out_edge; - -template -class dynamic_vertex; +#include -template -class dynamic_graph; +namespace graph::container { // uol_graph_traits // Vertices: std::unordered_map (hash-based; O(1) average lookup; unordered iteration) @@ -43,4 +35,8 @@ struct uol_graph_traits { using edges_type = std::list; }; +// Templated type alias for quick uol_graph definition +template +using uol_graph = dynamic_graph>; + } // namespace graph::container diff --git a/include/graph/container/traits/uos_graph_traits.hpp b/include/graph/container/traits/uos_graph_traits.hpp index 2dfe48b..86691f7 100644 --- a/include/graph/container/traits/uos_graph_traits.hpp +++ b/include/graph/container/traits/uos_graph_traits.hpp @@ -3,17 +3,9 @@ #include #include -namespace graph::container { - -// Forward declarations -template -class dynamic_out_edge; - -template -class dynamic_vertex; +#include -template -class dynamic_graph; +namespace graph::container { // uos_graph_traits // Vertices: std::unordered_map (hash-based; key-based lookup; forward iteration only) @@ -53,4 +45,8 @@ struct uos_graph_traits { using edges_type = std::set; }; +// Templated type alias for quick uos_graph definition +template +using uos_graph = dynamic_graph>; + } // namespace graph::container diff --git a/include/graph/container/traits/uous_graph_traits.hpp b/include/graph/container/traits/uous_graph_traits.hpp index a180ade..6b493de 100644 --- a/include/graph/container/traits/uous_graph_traits.hpp +++ b/include/graph/container/traits/uous_graph_traits.hpp @@ -3,17 +3,9 @@ #include #include -namespace graph::container { - -// Forward declarations -template -class dynamic_out_edge; - -template -class dynamic_vertex; +#include -template -class dynamic_graph; +namespace graph::container { // uous_graph_traits // Vertices: std::unordered_map (hash-based; key-based lookup; forward iteration only) @@ -52,4 +44,8 @@ struct uous_graph_traits { using edges_type = std::unordered_set; }; +// Templated type alias for quick uous_graph definition +template +using uous_graph = dynamic_graph>; + } // namespace graph::container diff --git a/include/graph/container/traits/uov_graph_traits.hpp b/include/graph/container/traits/uov_graph_traits.hpp index e3f3a69..696119f 100644 --- a/include/graph/container/traits/uov_graph_traits.hpp +++ b/include/graph/container/traits/uov_graph_traits.hpp @@ -4,17 +4,9 @@ #include #include -namespace graph::container { - -// Forward declarations -template -class dynamic_out_edge; - -template -class dynamic_vertex; +#include -template -class dynamic_graph; +namespace graph::container { // uov_graph_traits // Vertices: std::unordered_map (hash-based; O(1) average lookup; unordered iteration) @@ -43,4 +35,8 @@ struct uov_graph_traits { using edges_type = std::vector; }; +// Templated type alias for quick uov_graph definition +template +using uov_graph = dynamic_graph>; + } // namespace graph::container diff --git a/include/graph/container/traits/vod_graph_traits.hpp b/include/graph/container/traits/vod_graph_traits.hpp index 1844ebe..80cd101 100644 --- a/include/graph/container/traits/vod_graph_traits.hpp +++ b/include/graph/container/traits/vod_graph_traits.hpp @@ -3,17 +3,9 @@ #include #include -namespace graph::container { - -// Forward declarations -template -class dynamic_out_edge; - -template -class dynamic_vertex; +#include -template -class dynamic_graph; +namespace graph::container { // vod_graph_traits // Vertices: std::vector @@ -35,4 +27,8 @@ struct vod_graph_traits { using edges_type = std::deque; }; +// Templated type alias for quick vod_graph definition +template +using vod_graph = dynamic_graph>; + } // namespace graph::container diff --git a/include/graph/container/traits/vofl_graph_traits.hpp b/include/graph/container/traits/vofl_graph_traits.hpp index b9894dc..29786fe 100644 --- a/include/graph/container/traits/vofl_graph_traits.hpp +++ b/include/graph/container/traits/vofl_graph_traits.hpp @@ -3,17 +3,9 @@ #include #include -namespace graph::container { - -// Forward declarations -template -class dynamic_out_edge; - -template -class dynamic_vertex; +#include -template -class dynamic_graph; +namespace graph::container { // vofl_graph_traits // Vertices: std::vector (contiguous; random access) @@ -37,4 +29,8 @@ struct vofl_graph_traits { using edges_type = std::forward_list; }; +// Templated type alias for quick vofl_graph definition +template +using vofl_graph = dynamic_graph>; + } // namespace graph::container diff --git a/include/graph/container/traits/vol_graph_traits.hpp b/include/graph/container/traits/vol_graph_traits.hpp index 88237c7..731515e 100644 --- a/include/graph/container/traits/vol_graph_traits.hpp +++ b/include/graph/container/traits/vol_graph_traits.hpp @@ -3,17 +3,9 @@ #include #include -namespace graph::container { - -// Forward declarations -template -class dynamic_out_edge; - -template -class dynamic_vertex; +#include -template -class dynamic_graph; +namespace graph::container { // vol_graph_traits // Vertices: std::vector @@ -34,4 +26,8 @@ struct vol_graph_traits { using edges_type = std::list; }; +// Templated type alias for quick vol_graph definition +template +using vol_graph = dynamic_graph>; + } // namespace graph::container diff --git a/include/graph/container/traits/vom_graph_traits.hpp b/include/graph/container/traits/vom_graph_traits.hpp index e0b051e..457fa22 100644 --- a/include/graph/container/traits/vom_graph_traits.hpp +++ b/include/graph/container/traits/vom_graph_traits.hpp @@ -3,17 +3,9 @@ #include #include -namespace graph::container { - -// Forward declarations -template -class dynamic_out_edge; - -template -class dynamic_vertex; +#include -template -class dynamic_graph; +namespace graph::container { // vom_graph_traits // Vertices: std::vector (contiguous; random access by vertex ID) @@ -49,4 +41,8 @@ struct vom_graph_traits { using edges_type = std::map; // Map keyed by target vertex ID }; +// Templated type alias for quick vom_graph definition +template +using vom_graph = dynamic_graph>; + } // namespace graph::container diff --git a/include/graph/container/traits/vos_graph_traits.hpp b/include/graph/container/traits/vos_graph_traits.hpp index cf3c17f..81ea836 100644 --- a/include/graph/container/traits/vos_graph_traits.hpp +++ b/include/graph/container/traits/vos_graph_traits.hpp @@ -3,17 +3,9 @@ #include #include -namespace graph::container { - -// Forward declarations -template -class dynamic_out_edge; - -template -class dynamic_vertex; +#include -template -class dynamic_graph; +namespace graph::container { // vos_graph_traits // Vertices: std::vector (contiguous; random access by vertex ID) @@ -43,4 +35,8 @@ struct vos_graph_traits { using edges_type = std::set; }; +// Templated type alias for quick vos_graph definition +template +using vos_graph = dynamic_graph>; + } // namespace graph::container diff --git a/include/graph/container/traits/voum_graph_traits.hpp b/include/graph/container/traits/voum_graph_traits.hpp index b3d2c77..8cd4db6 100644 --- a/include/graph/container/traits/voum_graph_traits.hpp +++ b/include/graph/container/traits/voum_graph_traits.hpp @@ -3,17 +3,9 @@ #include #include -namespace graph::container { - -// Forward declarations -template -class dynamic_out_edge; - -template -class dynamic_vertex; +#include -template -class dynamic_graph; +namespace graph::container { // voum_graph_traits // Vertices: std::vector (contiguous; random access by vertex ID) @@ -53,4 +45,8 @@ struct voum_graph_traits { using edges_type = std::unordered_map; // Hash map keyed by target vertex ID }; +// Templated type alias for quick voum_graph definition +template +using voum_graph = dynamic_graph>; + } // namespace graph::container diff --git a/include/graph/container/traits/vous_graph_traits.hpp b/include/graph/container/traits/vous_graph_traits.hpp index be6234b..535d827 100644 --- a/include/graph/container/traits/vous_graph_traits.hpp +++ b/include/graph/container/traits/vous_graph_traits.hpp @@ -3,17 +3,9 @@ #include #include -namespace graph::container { - -// Forward declarations -template -class dynamic_out_edge; - -template -class dynamic_vertex; +#include -template -class dynamic_graph; +namespace graph::container { // vous_graph_traits // Vertices: std::vector (contiguous; random access by vertex ID) @@ -47,4 +39,8 @@ struct vous_graph_traits { using edges_type = std::unordered_set; }; +// Templated type alias for quick vous_graph definition +template +using vous_graph = dynamic_graph>; + } // namespace graph::container diff --git a/include/graph/container/traits/vov_graph_traits.hpp b/include/graph/container/traits/vov_graph_traits.hpp index fff6c7a..5d2125c 100644 --- a/include/graph/container/traits/vov_graph_traits.hpp +++ b/include/graph/container/traits/vov_graph_traits.hpp @@ -2,17 +2,9 @@ #include -namespace graph::container { - -// Forward declarations -template -class dynamic_out_edge; - -template -class dynamic_vertex; +#include -template -class dynamic_graph; +namespace graph::container { // vov_graph_traits // Vertices: std::vector @@ -34,4 +26,8 @@ struct vov_graph_traits { using edges_type = std::vector; }; +// Templated type alias for quick vov_graph definition +template +using vov_graph = dynamic_graph>; + } // namespace graph::container diff --git a/include/graph/edge_list/edge_list_descriptor.hpp b/include/graph/edge_list/edge_list_descriptor.hpp index 0fe6729..8e26149 100644 --- a/include/graph/edge_list/edge_list_descriptor.hpp +++ b/include/graph/edge_list/edge_list_descriptor.hpp @@ -1,73 +1,93 @@ #pragma once -#include +#include #include #include #include namespace graph::edge_list { -namespace detail { - // Empty type for void value optimization - struct empty_value { - constexpr auto operator<=>(const empty_value&) const noexcept = default; - }; -} // namespace detail +template +class edge_descriptor; /** - * @brief Lightweight edge descriptor for edge lists + * @brief Lightweight edge descriptor for edge lists without edge values * * This descriptor is a non-owning reference to edge data stored in an edge list. - * It stores references to the source ID, target ID, and optionally the edge value, + * It stores references to source and target IDs, * avoiding any copies. The descriptor is only valid as long as the referenced data exists. * * @tparam VId Vertex ID type - * @tparam EV Edge value type (void for edges without values) */ -template -class edge_descriptor { +template +class edge_descriptor { public: using vertex_id_type = VId; - using edge_value_type = EV; + using edge_value_type = void; - // Constructor without value (for void EV) constexpr edge_descriptor(const VId& src, const VId& tgt) - requires std::is_void_v - : source_id_(src), target_id_(tgt), value_() {} + : source_id_(src), target_id_(tgt) {} + + edge_descriptor(const edge_descriptor&) = default; + edge_descriptor& operator=(const edge_descriptor&) = delete; + + edge_descriptor(edge_descriptor&&) = default; + edge_descriptor& operator=(edge_descriptor&&) = delete; + + [[nodiscard]] constexpr const VId& source_id() const noexcept { return source_id_; } + + [[nodiscard]] constexpr const VId& target_id() const noexcept { return target_id_; } + + constexpr bool operator==(const edge_descriptor& other) const noexcept { + return source_id_ == other.source_id_ && target_id_ == other.target_id_; + } + + constexpr auto operator<=>(const edge_descriptor& other) const noexcept { + if (auto cmp = source_id_ <=> other.source_id_; cmp != 0) + return cmp; + return target_id_ <=> other.target_id_; + } + +private: + const VId& source_id_; + const VId& target_id_; +}; + +/** + * @brief Lightweight edge descriptor for edge lists with edge values + * + * This descriptor is a non-owning reference to edge data stored in an edge list. + * It stores references to source ID, target ID, and edge value. + * The descriptor is only valid as long as the referenced data exists. + * + * @tparam VId Vertex ID type + * @tparam EV Edge value type + */ +template +class edge_descriptor { +public: + using vertex_id_type = VId; + using edge_value_type = EV; - // Constructor with value (for non-void EV) - template - requires(!std::is_void_v) - constexpr edge_descriptor(const VId& src, const VId& tgt, const E& val) + constexpr edge_descriptor(const VId& src, const VId& tgt, const EV& val) : source_id_(src), target_id_(tgt), value_(std::cref(val)) {} - // Copy constructor and assignment - this is a reference type edge_descriptor(const edge_descriptor&) = default; edge_descriptor& operator=(const edge_descriptor&) = delete; - // Move constructor and assignment - this is a reference type edge_descriptor(edge_descriptor&&) = default; edge_descriptor& operator=(edge_descriptor&&) = delete; - // Accessors - return the stored references [[nodiscard]] constexpr const VId& source_id() const noexcept { return source_id_; } [[nodiscard]] constexpr const VId& target_id() const noexcept { return target_id_; } - // Value accessor (only for non-void EV) - template - requires(!std::is_void_v) - [[nodiscard]] constexpr const E& value() const noexcept { + [[nodiscard]] constexpr const EV& value() const noexcept { return value_.get(); } - // Comparison operators - compare referenced values, not references themselves constexpr bool operator==(const edge_descriptor& other) const noexcept { - if constexpr (std::is_void_v) { - return source_id_ == other.source_id_ && target_id_ == other.target_id_; - } else { - return source_id_ == other.source_id_ && target_id_ == other.target_id_ && value_.get() == other.value_.get(); - } + return source_id_ == other.source_id_ && target_id_ == other.target_id_ && value_.get() == other.value_.get(); } constexpr auto operator<=>(const edge_descriptor& other) const noexcept { @@ -75,18 +95,13 @@ class edge_descriptor { return cmp; if (auto cmp = target_id_ <=> other.target_id_; cmp != 0) return cmp; - if constexpr (!std::is_void_v) { - return value_.get() <=> other.value_.get(); - } else { - return std::strong_ordering::equal; - } + return value_.get() <=> other.value_.get(); } private: const VId& source_id_; const VId& target_id_; - [[no_unique_address]] std::conditional_t, detail::empty_value, std::reference_wrapper> - value_; + std::reference_wrapper value_; }; // Deduction guides diff --git a/include/graph/edge_list/edge_list_traits.hpp b/include/graph/edge_list/edge_list_traits.hpp index 4d41718..4c1f27a 100644 --- a/include/graph/edge_list/edge_list_traits.hpp +++ b/include/graph/edge_list/edge_list_traits.hpp @@ -6,7 +6,7 @@ namespace graph::edge_list { // Forward declaration - actual type defined in edge_list_descriptor.hpp template -struct edge_descriptor; +class edge_descriptor; // Type trait to identify edge_list descriptors template diff --git a/include/graph/generators/barabasi_albert.hpp b/include/graph/generators/barabasi_albert.hpp index e0fada2..5fce2da 100644 --- a/include/graph/generators/barabasi_albert.hpp +++ b/include/graph/generators/barabasi_albert.hpp @@ -39,15 +39,15 @@ edge_list barabasi_albert(VId n, VId m, uint64_t seed = 42, std::vector urn; urn.reserve(2 * static_cast(n) * m); - edge_list edges; - edges.reserve(2 * static_cast(n) * m); + edge_list generated_edges; + generated_edges.reserve(2 * static_cast(n) * m); // Seed: fully-connected clique of m0 vertices const VId m0 = std::max(m, VId{2}); for (VId u = 0; u < m0; ++u) { for (VId v = u + 1; v < m0; ++v) { - edges.push_back({u, v, sample_weight(rng, wdist)}); - edges.push_back({v, u, sample_weight(rng, wdist)}); + generated_edges.push_back({u, v, sample_weight(rng, wdist)}); + generated_edges.push_back({v, u, sample_weight(rng, wdist)}); urn.push_back(u); urn.push_back(v); } @@ -66,17 +66,17 @@ edge_list barabasi_albert(VId n, VId m, uint64_t seed = 42, already |= (x == t); if (!already) { chosen.push_back(t); - edges.push_back({w, t, sample_weight(rng, wdist)}); - edges.push_back({t, w, sample_weight(rng, wdist)}); + generated_edges.push_back({w, t, sample_weight(rng, wdist)}); + generated_edges.push_back({t, w, sample_weight(rng, wdist)}); urn.push_back(w); urn.push_back(t); } } } - std::stable_sort(edges.begin(), edges.end(), + std::stable_sort(generated_edges.begin(), generated_edges.end(), [](const auto& a, const auto& b) { return a.source_id < b.source_id; }); - return edges; + return generated_edges; } } // namespace graph::generators diff --git a/include/graph/generators/erdos_renyi.hpp b/include/graph/generators/erdos_renyi.hpp index 462b1d9..1778eb9 100644 --- a/include/graph/generators/erdos_renyi.hpp +++ b/include/graph/generators/erdos_renyi.hpp @@ -42,9 +42,9 @@ edge_list erdos_renyi(VId n, double p, uint64_t seed = 42, std::mt19937_64 rng(seed); const size_t total = static_cast(n) * (n - 1); // n*(n-1) directed pairs - edge_list edges; + edge_list generated_edges; const size_t expected = static_cast(static_cast(total) * p * 1.1) + 16; - edges.reserve(expected); + generated_edges.reserve(expected); // Geometric skip: sample the gap between consecutive selected positions. std::geometric_distribution geom(p); @@ -54,11 +54,11 @@ edge_list erdos_renyi(VId n, double p, uint64_t seed = 42, const VId u = static_cast(pos / (n - 1)); const VId offset = static_cast(pos % (n - 1)); const VId v = (offset < u) ? offset : offset + 1; - edges.push_back({u, v, sample_weight(rng, wdist)}); + generated_edges.push_back({u, v, sample_weight(rng, wdist)}); pos += geom(rng) + 1; } // Edges are already sorted by source_id (u is non-decreasing). - return edges; + return generated_edges; } } // namespace graph::generators diff --git a/include/graph/generators/grid.hpp b/include/graph/generators/grid.hpp index 15b3baa..16c161d 100644 --- a/include/graph/generators/grid.hpp +++ b/include/graph/generators/grid.hpp @@ -33,8 +33,8 @@ edge_list grid_2d(VId rows, VId cols, uint64_t seed = 42, std::mt19937_64 rng(seed); const VId n = rows * cols; - edge_list edges; - edges.reserve(4 * static_cast(n)); // upper bound + edge_list generated_edges; + generated_edges.reserve(4 * static_cast(n)); // upper bound for (VId r = 0; r < rows; ++r) { for (VId c = 0; c < cols; ++c) { @@ -42,20 +42,20 @@ edge_list grid_2d(VId rows, VId cols, uint64_t seed = 42, // Right neighbour if (c + 1 < cols) { VId v = u + 1; - edges.push_back({u, v, sample_weight(rng, wdist)}); - edges.push_back({v, u, sample_weight(rng, wdist)}); + generated_edges.push_back({u, v, sample_weight(rng, wdist)}); + generated_edges.push_back({v, u, sample_weight(rng, wdist)}); } // Down neighbour if (r + 1 < rows) { VId v = u + cols; - edges.push_back({u, v, sample_weight(rng, wdist)}); - edges.push_back({v, u, sample_weight(rng, wdist)}); + generated_edges.push_back({u, v, sample_weight(rng, wdist)}); + generated_edges.push_back({v, u, sample_weight(rng, wdist)}); } } } - std::stable_sort(edges.begin(), edges.end(), + std::stable_sort(generated_edges.begin(), generated_edges.end(), [](const auto& a, const auto& b) { return a.source_id < b.source_id; }); - return edges; + return generated_edges; } } // namespace graph::generators diff --git a/include/graph/generators/path.hpp b/include/graph/generators/path.hpp index 0215dcf..4a0ca23 100644 --- a/include/graph/generators/path.hpp +++ b/include/graph/generators/path.hpp @@ -27,14 +27,14 @@ template edge_list path_graph(VId n, uint64_t seed = 42, weight_dist wdist = weight_dist::uniform) { std::mt19937_64 rng(seed); - edge_list edges; - edges.reserve(n > 0 ? n - 1 : 0); + edge_list generated_edges; + generated_edges.reserve(n > 0 ? n - 1 : 0); for (VId u = 0; u + 1 < n; ++u) { - edges.push_back({u, static_cast(u + 1), sample_weight(rng, wdist)}); + generated_edges.push_back({u, static_cast(u + 1), sample_weight(rng, wdist)}); } // Already sorted. - return edges; + return generated_edges; } } // namespace graph::generators diff --git a/include/graph/io/dot.hpp b/include/graph/io/dot.hpp index e1ffbd1..66e0ff2 100644 --- a/include/graph/io/dot.hpp +++ b/include/graph/io/dot.hpp @@ -184,8 +184,8 @@ namespace detail { inline std::string trim(std::string_view sv) { auto start = sv.find_first_not_of(" \t\r\n"); if (start == std::string_view::npos) return {}; - auto end = sv.find_last_not_of(" \t\r\n"); - return std::string(sv.substr(start, end - start + 1)); + auto end_pos = sv.find_last_not_of(" \t\r\n"); + return std::string(sv.substr(start, end_pos - start + 1)); } inline std::string extract_label(std::string_view attrs) { @@ -197,9 +197,9 @@ namespace detail { pos = attrs.find('"', pos); if (pos == std::string_view::npos) return {}; ++pos; - auto end = attrs.find('"', pos); - if (end == std::string_view::npos) return {}; - return std::string(attrs.substr(pos, end - pos)); + auto end_pos = attrs.find('"', pos); + if (end_pos == std::string_view::npos) return {}; + return std::string(attrs.substr(pos, end_pos - pos)); } } // namespace detail diff --git a/include/graph/io/graphml.hpp b/include/graph/io/graphml.hpp index c88cb52..0a6a5ea 100644 --- a/include/graph/io/graphml.hpp +++ b/include/graph/io/graphml.hpp @@ -308,9 +308,9 @@ namespace detail { pos = tag.find('"', pos); if (pos == std::string_view::npos) return {}; ++pos; - auto end = tag.find('"', pos); - if (end == std::string_view::npos) return {}; - return std::string(tag.substr(pos, end - pos)); + auto end_pos = tag.find('"', pos); + if (end_pos == std::string_view::npos) return {}; + return std::string(tag.substr(pos, end_pos - pos)); } inline std::string xml_unescape(std::string_view s) { @@ -352,9 +352,9 @@ inline graphml_graph read_graphml(std::istream& is) { auto find_tag = [&](size_t from) -> std::pair { auto start = content.find('<', from); if (start == std::string::npos) return {std::string::npos, std::string::npos}; - auto end = content.find('>', start); - if (end == std::string::npos) return {std::string::npos, std::string::npos}; - return {start, end + 1}; + auto tag_end = content.find('>', start); + if (tag_end == std::string::npos) return {std::string::npos, std::string::npos}; + return {start, tag_end + 1}; }; auto get_tag_name = [](std::string_view tag) -> std::string { @@ -362,9 +362,9 @@ inline graphml_graph read_graphml(std::istream& is) { size_t start = 1; if (tag.size() > 1 && tag[1] == '/') start = 2; if (tag.size() > 1 && tag[1] == '?') start = 2; - auto end = tag.find_first_of(" \t\n/>", start); - if (end == std::string_view::npos) end = tag.size() - 1; - return std::string(tag.substr(start, end - start)); + auto end_pos = tag.find_first_of(" \t\n/>", start); + if (end_pos == std::string_view::npos) end_pos = tag.size() - 1; + return std::string(tag.substr(start, end_pos - start)); }; // State machine diff --git a/include/graph/views/bfs.hpp b/include/graph/views/bfs.hpp index 3d08842..1353d84 100644 --- a/include/graph/views/bfs.hpp +++ b/include/graph/views/bfs.hpp @@ -194,8 +194,8 @@ namespace bfs_detail { std::size_t max_depth_ = 0; std::size_t count_ = 0; - bfs_state(G& g, vertex_type seed_vertex, std::size_t num_vertices, Alloc alloc = {}) - : queue_(std::deque(alloc)), visited_(num_vertices, alloc) { + bfs_state(G& g, vertex_type seed_vertex, std::size_t vertex_count, Alloc alloc = {}) + : queue_(std::deque(alloc)), visited_(vertex_count, alloc) { (void)g; queue_.push({seed_vertex, 0}); visited_.mark_visited(seed_vertex); @@ -228,8 +228,8 @@ namespace bfs_detail { std::size_t count_ = 0; std::optional skip_vertex_id_; // Vertex to skip when processing (for cancel_branch) - bfs_edge_state(G& g, vertex_type seed_vertex, std::size_t num_vertices, Alloc alloc = {}) - : queue_(std::deque(alloc)), visited_(num_vertices, alloc) { + bfs_edge_state(G& g, vertex_type seed_vertex, std::size_t vertex_count, Alloc alloc = {}) + : queue_(std::deque(alloc)), visited_(vertex_count, alloc) { auto edge_range = Accessor{}.edges(g, seed_vertex); auto edge_begin = std::ranges::begin(edge_range); auto edge_end = std::ranges::end(edge_range); diff --git a/include/graph/views/dfs.hpp b/include/graph/views/dfs.hpp index 2c7f94e..e4e17d2 100644 --- a/include/graph/views/dfs.hpp +++ b/include/graph/views/dfs.hpp @@ -198,8 +198,8 @@ namespace dfs_detail { std::size_t depth_ = 0; std::size_t count_ = 0; - dfs_state(G& g, vertex_type seed_vertex, std::size_t num_vertices, Alloc alloc = {}) - : stack_(std::vector(alloc)), visited_(num_vertices, alloc) { + dfs_state(G& g, vertex_type seed_vertex, std::size_t vertex_count, Alloc alloc = {}) + : stack_(std::vector(alloc)), visited_(vertex_count, alloc) { auto edge_range = Accessor{}.edges(g, seed_vertex); stack_.push({seed_vertex, std::ranges::begin(edge_range), std::ranges::end(edge_range)}); visited_.mark_visited(seed_vertex); diff --git a/include/graph/views/edgelist.hpp b/include/graph/views/edgelist.hpp index e66f370..71d5775 100644 --- a/include/graph/views/edgelist.hpp +++ b/include/graph/views/edgelist.hpp @@ -197,9 +197,9 @@ class edgelist_view : public std::ranges::view_interface(source_id), static_cast(target_id), current_edge_}; + auto src_id = adj_list::vertex_id(*g_, v_); + auto dst_id = adj_list::target_id(*g_, current_edge_); + return value_type{static_cast(src_id), static_cast(dst_id), current_edge_}; } constexpr iterator& operator++() noexcept { @@ -345,9 +345,9 @@ class edgelist_view : public std::ranges::view_interface> : g_(g), v_(v), v_end_(v_end), current_edge_(current_edge), edge_end_(edge_end), evf_(evf) {} [[nodiscard]] constexpr value_type operator*() const { - auto source_id = adj_list::vertex_id(*g_, v_); - auto target_id = adj_list::target_id(*g_, current_edge_); - return value_type{static_cast(source_id), static_cast(target_id), current_edge_, std::invoke(*evf_, std::as_const(*g_), current_edge_)}; + auto src_id = adj_list::vertex_id(*g_, v_); + auto dst_id = adj_list::target_id(*g_, current_edge_); + return value_type{static_cast(src_id), static_cast(dst_id), current_edge_, std::invoke(*evf_, std::as_const(*g_), current_edge_)}; } constexpr iterator& operator++() noexcept { diff --git a/include/graph/views/incidence.hpp b/include/graph/views/incidence.hpp index 73ae8ab..c73cd88 100644 --- a/include/graph/views/incidence.hpp +++ b/include/graph/views/incidence.hpp @@ -704,7 +704,7 @@ basic_incidence_view(G&, adj_list::vertex_t, EVF) -> basic_incidence_view -[[nodiscard]] constexpr auto basic_incidence(G& g, const adj_list::vertex_id_t& uid) { +[[nodiscard]] constexpr auto basic_incidence(G& g, adj_list::vertex_id_t uid) { auto u = *adj_list::find_vertex(g, uid); return basic_incidence_view(g, u); } @@ -730,7 +730,7 @@ template */ template requires edge_value_function> -[[nodiscard]] constexpr auto basic_incidence(G& g, const adj_list::vertex_id_t& uid, EVF&& evf) { +[[nodiscard]] constexpr auto basic_incidence(G& g, adj_list::vertex_id_t uid, EVF&& evf) { auto u = *adj_list::find_vertex(g, uid); return basic_incidence_view>(g, u, std::forward(evf)); } @@ -769,7 +769,7 @@ requires edge_value_function> /// @brief Create a basic outgoing incidence view (target id only). template -[[nodiscard]] constexpr auto basic_out_incidence(G& g, const adj_list::vertex_id_t& uid) { +[[nodiscard]] constexpr auto basic_out_incidence(G& g, adj_list::vertex_id_t uid) { auto u = *adj_list::find_vertex(g, uid); return basic_incidence_view(g, u); } @@ -777,7 +777,7 @@ template /// @brief Create a basic outgoing incidence view with EVF. template requires edge_value_function> -[[nodiscard]] constexpr auto basic_out_incidence(G& g, const adj_list::vertex_id_t& uid, EVF&& evf) { +[[nodiscard]] constexpr auto basic_out_incidence(G& g, adj_list::vertex_id_t uid, EVF&& evf) { auto u = *adj_list::find_vertex(g, uid); return basic_incidence_view, out_edge_accessor>(g, u, std::forward(evf)); } diff --git a/include/graph/views/search_base.hpp b/include/graph/views/search_base.hpp index 7c1c25f..2738002 100644 --- a/include/graph/views/search_base.hpp +++ b/include/graph/views/search_base.hpp @@ -60,20 +60,20 @@ class visited_tracker { storage_type visited_; - static storage_type make_storage(std::size_t num_vertices, Alloc alloc) { + static storage_type make_storage(std::size_t vertex_count, Alloc alloc) { if constexpr (use_bitset) { - return storage_type(num_vertices, false, alloc); + return storage_type(vertex_count, false, alloc); } else { - (void)num_vertices; + (void)vertex_count; return storage_type(0, std::hash{}, std::equal_to{}, set_alloc(alloc)); } } public: - /// Construct tracker for a graph with @p num_vertices vertices. - /// @p num_vertices is used to pre-size the bitset; ignored for the hash variant. - explicit visited_tracker(std::size_t num_vertices, Alloc alloc = {}) - : visited_(make_storage(num_vertices, alloc)) {} + /// Construct tracker for a graph with @p vertex_count vertices. + /// @p vertex_count is used to pre-size the bitset; ignored for the hash variant. + explicit visited_tracker(std::size_t vertex_count, Alloc alloc = {}) + : visited_(make_storage(vertex_count, alloc)) {} /// Check if a vertex has been visited [[nodiscard]] bool is_visited(const Vertex& v) const { diff --git a/include/graph/views/topological_sort.hpp b/include/graph/views/topological_sort.hpp index 755622e..3ae2b1d 100644 --- a/include/graph/views/topological_sort.hpp +++ b/include/graph/views/topological_sort.hpp @@ -238,38 +238,54 @@ namespace topo_detail { [[nodiscard]] const std::optional& cycle_vertex() const noexcept { return cycle_vertex_; } private: - // Recursive DFS visit for topological sort - void dfs_visit(G& g, vertex_type v, bool detect_cycles) { - visited_.mark_visited(v); + // Iterative DFS visit for topological sort (avoids stack overflow on deep graphs) + void dfs_visit(G& g, vertex_type start_v, bool detect_cycles) { + using edge_iterator_type = std::ranges::iterator_t>; + struct frame { + vertex_type v; + edge_iterator_type it; + edge_iterator_type edge_end; + }; + + std::vector dfs_stack; + + auto push_vertex = [&](vertex_type v) { + visited_.mark_visited(v); + if (detect_cycles) { + rec_stack_.mark_visited(v); + } + auto edge_range = Accessor{}.edges(g, v); + dfs_stack.push_back({v, std::ranges::begin(edge_range), std::ranges::end(edge_range)}); + }; - if (detect_cycles) { - rec_stack_.mark_visited(v); - } + push_vertex(start_v); - // Visit all children - for (auto edge : Accessor{}.edges(g, v)) { - auto target_v = Accessor{}.neighbor(g, edge); + while (!dfs_stack.empty()) { + auto& [v, it, edge_end] = dfs_stack.back(); - if (detect_cycles && rec_stack_.is_visited(target_v)) { - // Back edge detected - target_v closes the cycle - cycle_vertex_ = target_v; - return; - } + if (it == edge_end) { + // All children visited — add to post-order + if (detect_cycles) { + rec_stack_.unmark_visited(v); + } + post_order_.push_back(v); + dfs_stack.pop_back(); + } else { + auto edge = *it; + ++it; + auto target_v = Accessor{}.neighbor(g, edge); + + if (detect_cycles && rec_stack_.is_visited(target_v)) { + // Back edge detected — target_v closes the cycle + cycle_vertex_ = target_v; + return; + } - if (!visited_.is_visited(target_v)) { - dfs_visit(g, target_v, detect_cycles); - if (cycle_vertex_) { - return; // Propagate early exit + if (!visited_.is_visited(target_v)) { + push_vertex(target_v); } } } - - if (detect_cycles) { - rec_stack_.unmark_visited(v); - } - - // Add to post-order after all children visited - post_order_.push_back(v); } }; @@ -290,7 +306,7 @@ namespace topo_detail { * * @see vertices_topological_sort_view — with value function * @see edges_topological_sort_view — edge-oriented variant - */ + */ template class vertices_topological_sort_view : public std::ranges::view_interface> { diff --git a/tests/adaptors/test_filtered_graph.cpp b/tests/adaptors/test_filtered_graph.cpp index fcecc8d..7e9836d 100644 --- a/tests/adaptors/test_filtered_graph.cpp +++ b/tests/adaptors/test_filtered_graph.cpp @@ -61,9 +61,7 @@ TEST_CASE("filtered_graph with keep_all passes through", "[filtered_graph]") { // All edges visible std::size_t edge_count = 0; for (auto&& [uid, u] : graph::views::vertexlist(fg)) { - for (auto&& [tid, uv] : graph::views::incidence(fg, u)) { - ++edge_count; - } + edge_count += static_cast(std::ranges::distance(graph::views::incidence(fg, u))); } CHECK(edge_count == 5); } @@ -145,7 +143,6 @@ TEST_CASE("filtered_graph: dijkstra on filtered subgraph", "[filtered_graph][dij auto fg = graph::adaptors::filtered_graph(g, [](auto uid) { return uid != 1; }); - using fg_t = decltype(fg); const std::size_t n = graph::num_vertices(fg); constexpr double inf = std::numeric_limits::max(); @@ -153,35 +150,9 @@ TEST_CASE("filtered_graph: dijkstra on filtered subgraph", "[filtered_graph][dij std::vector pred(n); for (std::size_t i = 0; i < n; ++i) pred[i] = i; - // Distance/predecessor functions - auto dist_fn = [&dist](const auto&, auto uid) -> double& { - return dist[static_cast(uid)]; - }; - auto pred_fn = [&pred](const auto&, auto uid) -> std::size_t& { - return pred[static_cast(uid)]; - }; - // Weight function — extract from pair - auto weight_fn = [](const auto& g_ref, const auto& uv) -> double { - return std::get<1>(*uv.value()); // second element of pair - // Wait, this is the inner edge descriptor from the underlying graph. - // For vector>>, the raw edge is pair. - // But uv is the OUTER edge descriptor (from the CPO re-wrapping). - // uv.value() is a filter_view::iterator. - // *uv.value() is the INNER edge_descriptor. - // (*uv.value()).value() would be... no, need to think about this. - // Actually uv IS an edge_descriptor from the filtered graph. - // The edges() function returns filter_view. - // The CPO wraps this in edge_descriptor_view. - // So uv from the CPO is edge_descriptor. - // uv.value() is the filter_iter. - // *uv.value() is the inner edge_descriptor from the underlying graph. - // For vector>>, inner_edge_descriptor.value() - // would be... I need to check. Actually for native graph types, - // the edge's inner_value(g) gives access to the pair. - // This is getting complicated. Let me use a simpler approach. - }; - // Actually, this test is getting too complex because of the double-wrapping. // Let me verify the simpler tests first and come back to Dijkstra. + CHECK(dist.size() == n); + CHECK(pred.size() == n); SUCCEED(); // placeholder } diff --git a/tests/adj_list/CMakeLists.txt b/tests/adj_list/CMakeLists.txt index f2181f7..ea6038a 100644 --- a/tests/adj_list/CMakeLists.txt +++ b/tests/adj_list/CMakeLists.txt @@ -63,4 +63,6 @@ if(MSVC) endif() # Register tests with CTest -catch_discover_tests(graph3_adj_list_tests) +catch_discover_tests(graph3_adj_list_tests + DISCOVERY_MODE PRE_TEST +) diff --git a/tests/adj_list/concepts/test_bidirectional_concepts.cpp b/tests/adj_list/concepts/test_bidirectional_concepts.cpp index a115797..08c2b6f 100644 --- a/tests/adj_list/concepts/test_bidirectional_concepts.cpp +++ b/tests/adj_list/concepts/test_bidirectional_concepts.cpp @@ -99,7 +99,7 @@ TEST_CASE("bidirectional_adjacency_list runtime validation", auto verts = vertices(g); auto it = verts.begin(); auto v0 = *it++; - auto v1 = *it++; + ++it; auto v2 = *it++; // Verify in_edges returns correct incoming edges diff --git a/tests/adj_list/cpo/test_contains_edge_cpo.cpp b/tests/adj_list/cpo/test_contains_edge_cpo.cpp index 38bdf57..69e2575 100644 --- a/tests/adj_list/cpo/test_contains_edge_cpo.cpp +++ b/tests/adj_list/cpo/test_contains_edge_cpo.cpp @@ -17,6 +17,8 @@ using namespace graph::adj_list; // ============================================================================= struct GraphWithContainsEdgeMember { + using vertex_id_type = size_t; + std::vector> adj_list; GraphWithContainsEdgeMember(size_t n) : adj_list(n) {} @@ -41,6 +43,8 @@ struct GraphWithContainsEdgeMember { namespace test_adl { struct GraphWithADLContainsEdge { + using vertex_id_type = size_t; + std::vector> adj_list; GraphWithADLContainsEdge(size_t n) : adj_list(n) {} diff --git a/tests/adj_list/cpo/test_degree_cpo.cpp b/tests/adj_list/cpo/test_degree_cpo.cpp index 93c11b9..473422f 100644 --- a/tests/adj_list/cpo/test_degree_cpo.cpp +++ b/tests/adj_list/cpo/test_degree_cpo.cpp @@ -17,6 +17,8 @@ using namespace graph::adj_list; // ============================================================================= struct GraphWithDegree { + using vertex_id_type = size_t; + std::vector> adj_list; GraphWithDegree(size_t n) : adj_list(n) {} @@ -33,6 +35,8 @@ struct GraphWithDegree { namespace test_adl { struct GraphWithADLDegree { + using vertex_id_type = size_t; + std::vector> adj_list; GraphWithADLDegree(size_t n) : adj_list(n) {} diff --git a/tests/adj_list/cpo/test_edge_value_cpo_value_method.cpp b/tests/adj_list/cpo/test_edge_value_cpo_value_method.cpp index c31a4ad..74eb0d1 100644 --- a/tests/adj_list/cpo/test_edge_value_cpo_value_method.cpp +++ b/tests/adj_list/cpo/test_edge_value_cpo_value_method.cpp @@ -17,7 +17,6 @@ constexpr VKey vertex_id(Iter it, const G& g) { TEST_CASE("edge_value CPO with .value() method", "[cpo][edge_value][value_method]") { undirected_adjacency_list g({{0, 1, 100}}); VKey k1 = 0; - VKey k2 = 1; SECTION("edge_value CPO works with undirected_adjacency_list edges") { // Get edge through vertex edge list @@ -58,7 +57,6 @@ TEST_CASE("edge_value CPO with .value() method", "[cpo][edge_value][value_method TEST_CASE("edge_value CPO resolution priority", "[cpo][edge_value][priority]") { undirected_adjacency_list g({{0, 1, 42}}); VKey k1 = 0; - VKey k2 = 1; // Get edge auto& v = g.vertices()[k1]; diff --git a/tests/adj_list/cpo/test_find_vertex_cpo.cpp b/tests/adj_list/cpo/test_find_vertex_cpo.cpp index 6de3e28..932d406 100644 --- a/tests/adj_list/cpo/test_find_vertex_cpo.cpp +++ b/tests/adj_list/cpo/test_find_vertex_cpo.cpp @@ -65,6 +65,8 @@ TEST_CASE("find_vertex - deque graph (random access default)", "[graph_cpo][find // Custom graph with find_vertex member struct CustomGraphWithMember { + using vertex_id_type = std::size_t; + std::vector> adj_list; // Custom find_vertex that validates ID range and returns iterator to vertex_descriptor_view @@ -101,6 +103,8 @@ TEST_CASE("find_vertex - custom member function", "[graph_cpo][find_vertex][memb namespace custom_ns { struct GraphWithADL { + using vertex_id_type = std::size_t; + std::vector> adj_list; }; diff --git a/tests/adj_list/cpo/test_find_vertex_edge_cpo.cpp b/tests/adj_list/cpo/test_find_vertex_edge_cpo.cpp index d0cea98..fd1de64 100644 --- a/tests/adj_list/cpo/test_find_vertex_edge_cpo.cpp +++ b/tests/adj_list/cpo/test_find_vertex_edge_cpo.cpp @@ -27,6 +27,8 @@ using namespace graph::adj_list; // ============================================================================= struct GraphWithFindEdgeMember { + using vertex_id_type = size_t; + std::vector> adj_list; GraphWithFindEdgeMember(size_t n) : adj_list(n) {} @@ -50,6 +52,8 @@ struct GraphWithFindEdgeMember { namespace test_adl { struct GraphWithADLFindEdge { + using vertex_id_type = size_t; + std::vector> adj_list; GraphWithADLFindEdge(size_t n) : adj_list(n) {} @@ -356,7 +360,7 @@ TEST_CASE("find_vertex_edge integrates with target() CPO", "[find_vertex_edge][c auto verts = vertices(graph); auto it = verts.begin(); auto v0 = *it++; - auto v1 = *it++; + ++it; auto v2 = *it; // Find edge 0 -> 2 diff --git a/tests/adj_list/cpo/test_source_id_cpo.cpp b/tests/adj_list/cpo/test_source_id_cpo.cpp index ed7cb20..ff540a6 100644 --- a/tests/adj_list/cpo/test_source_id_cpo.cpp +++ b/tests/adj_list/cpo/test_source_id_cpo.cpp @@ -166,7 +166,7 @@ TEST_CASE("source_id(g,uv) - native edge member function", "[source_id][cpo][mem SECTION("Native edge member function is called") { std::vector sources; for (auto e : edges(g.adjacency_list, v0)) { - sources.push_back(static_cast(source_id(g.adjacency_list, e))); + sources.push_back(source_id(g.adjacency_list, e)); } // Should use CustomEdge::source_id() which returns source * 100 diff --git a/tests/adj_list/descriptors/test_edge_descriptor.cpp b/tests/adj_list/descriptors/test_edge_descriptor.cpp index e1073ce..2ec05ca 100644 --- a/tests/adj_list/descriptors/test_edge_descriptor.cpp +++ b/tests/adj_list/descriptors/test_edge_descriptor.cpp @@ -236,7 +236,7 @@ TEST_CASE("edge_descriptor_view with vector - per-vertex adjacency", "[edge_desc std::size_t count = 0; for (auto ed : view) { - REQUIRE(ed.value() == edges_from_v5.begin() + count); + REQUIRE(ed.value() == std::ranges::next(edges_from_v5.begin(), static_cast(count))); REQUIRE(ed.source().value() == 5); // All have same source ++count; } diff --git a/tests/algorithms/CMakeLists.txt b/tests/algorithms/CMakeLists.txt index 5126358..53805be 100644 --- a/tests/algorithms/CMakeLists.txt +++ b/tests/algorithms/CMakeLists.txt @@ -30,6 +30,7 @@ target_link_libraries(test_algorithms # Discover and register tests catch_discover_tests(test_algorithms + DISCOVERY_MODE PRE_TEST TEST_PREFIX "algorithms." PROPERTIES LABELS "algorithms" diff --git a/tests/algorithms/test_bellman_ford_shortest_paths.cpp b/tests/algorithms/test_bellman_ford_shortest_paths.cpp index ddc9027..e3fd20b 100644 --- a/tests/algorithms/test_bellman_ford_shortest_paths.cpp +++ b/tests/algorithms/test_bellman_ford_shortest_paths.cpp @@ -56,7 +56,7 @@ TEST_CASE("bellman_ford_shortest_paths - CLRS example", "[algorithm][bellman_for init_shortest_paths(g, distance, predecessor); auto result = bellman_ford_shortest_paths(g, vertex_id_t(0), container_value_fn(distance), container_value_fn(predecessor), - [](const auto& g, const auto& uv) { return edge_value(g, uv); }); + [](const auto& graph_ref, const auto& uv) { return edge_value(graph_ref, uv); }); // No negative cycle should be detected REQUIRE(!result.has_value()); @@ -79,7 +79,7 @@ TEST_CASE("bellman_ford_shortest_paths - path graph", "[algorithm][bellman_ford_ init_shortest_paths(g, distance, predecessor); auto result = bellman_ford_shortest_paths(g, vertex_id_t(0), container_value_fn(distance), container_value_fn(predecessor), - [](const auto& g, const auto& uv) { return edge_value(g, uv); }); + [](const auto& graph_ref, const auto& uv) { return edge_value(graph_ref, uv); }); // No negative cycle REQUIRE(!result.has_value()); @@ -100,7 +100,7 @@ TEST_CASE("bellman_ford_shortest_distances - no predecessors", "[algorithm][bell // Test distances-only variant (no predecessor tracking) auto result = bellman_ford_shortest_distances(g, vertex_id_t(0), container_value_fn(distance), - [](const auto& g, const auto& uv) { return edge_value(g, uv); }); + [](const auto& graph_ref, const auto& uv) { return edge_value(graph_ref, uv); }); // No negative cycle REQUIRE(!result.has_value()); @@ -126,7 +126,7 @@ TEST_CASE("bellman_ford_shortest_paths - multi-source", "[algorithm][bellman_for std::vector> sources = {0, 3}; auto result = bellman_ford_shortest_paths(g, sources, container_value_fn(distance), container_value_fn(predecessor), - [](const auto& g, const auto& uv) { return edge_value(g, uv); }); + [](const auto& graph_ref, const auto& uv) { return edge_value(graph_ref, uv); }); // No negative cycle REQUIRE(!result.has_value()); @@ -152,7 +152,7 @@ TEST_CASE("bellman_ford_shortest_distances - multi-source", "[algorithm][bellman std::vector> sources = {0, 3}; auto result = bellman_ford_shortest_distances(g, sources, container_value_fn(distance), - [](const auto& g, const auto& uv) { return edge_value(g, uv); }); + [](const auto& graph_ref, const auto& uv) { return edge_value(graph_ref, uv); }); // No negative cycle REQUIRE(!result.has_value()); @@ -175,7 +175,7 @@ TEST_CASE("bellman_ford_shortest_paths - with visitor", "[algorithm][bellman_for auto result = bellman_ford_shortest_paths( g, vertex_id_t(0), container_value_fn(distance), container_value_fn(predecessor), - [](const auto& g, const auto& uv) { return edge_value(g, uv); }, visitor); + [](const auto& graph_ref, const auto& uv) { return edge_value(graph_ref, uv); }, visitor); // No negative cycle REQUIRE(!result.has_value()); @@ -222,7 +222,7 @@ TEST_CASE("bellman_ford_shortest_paths - predecessor path reconstruction", "[alg init_shortest_paths(g, distance, predecessor); auto result = bellman_ford_shortest_paths(g, vertex_id_t(0), container_value_fn(distance), container_value_fn(predecessor), - [](const auto& g, const auto& uv) { return edge_value(g, uv); }); + [](const auto& graph_ref, const auto& uv) { return edge_value(graph_ref, uv); }); // No negative cycle REQUIRE(!result.has_value()); @@ -293,7 +293,7 @@ TEST_CASE("bellman_ford_shortest_paths - negative weight cycle detection", "[alg auto result = bellman_ford_shortest_paths( g, vertex_id_t(0), container_value_fn(distance), container_value_fn(predecessor), - [](const auto& g, const auto& uv) { return edge_value(g, uv); }, visitor); + [](const auto& graph_ref, const auto& uv) { return edge_value(graph_ref, uv); }, visitor); // Negative cycle should be detected REQUIRE(result.has_value()); @@ -317,7 +317,7 @@ TEST_CASE("bellman_ford_shortest_paths - find negative cycle vertices", "[algori init_shortest_paths(g, distance, predecessor); auto cycle_vertex = bellman_ford_shortest_paths(g, vertex_id_t(0), container_value_fn(distance), container_value_fn(predecessor), - [](const auto& g, const auto& uv) { return edge_value(g, uv); }); + [](const auto& graph_ref, const auto& uv) { return edge_value(graph_ref, uv); }); REQUIRE(cycle_vertex.has_value()); @@ -386,7 +386,7 @@ TEMPLATE_TEST_CASE("bellman_ford_shortest_paths - sparse CLRS example", predecessors[uid] = uid; auto result = bellman_ford_shortest_paths(g, id_type(exp.s), container_value_fn(distances), container_value_fn(predecessors), - [](const auto& g, const auto& uv) { return edge_value(g, uv); }); + [](const auto& graph_ref, const auto& uv) { return edge_value(graph_ref, uv); }); // No negative cycle should be detected REQUIRE(!result.has_value()); @@ -411,7 +411,7 @@ TEMPLATE_TEST_CASE("bellman_ford_shortest_distances - sparse CLRS example", auto distances = make_vertex_property_map(g, infinite_distance()); auto result = bellman_ford_shortest_distances(g, id_type(exp.s), container_value_fn(distances), - [](const auto& g, const auto& uv) { return edge_value(g, uv); }); + [](const auto& graph_ref, const auto& uv) { return edge_value(graph_ref, uv); }); // No negative cycle REQUIRE(!result.has_value()); @@ -437,7 +437,7 @@ TEMPLATE_TEST_CASE("bellman_ford_shortest_paths - sparse multi-source", // Start from s (10) and y (40) std::vector sources = {exp.s, exp.y}; auto result = bellman_ford_shortest_paths(g, sources, container_value_fn(distances), container_value_fn(predecessors), - [](const auto& g, const auto& uv) { return edge_value(g, uv); }); + [](const auto& graph_ref, const auto& uv) { return edge_value(graph_ref, uv); }); // No negative cycle REQUIRE(!result.has_value()); @@ -468,7 +468,7 @@ TEMPLATE_TEST_CASE("bellman_ford_shortest_paths - sparse with visitor", BellmanCountingVisitor visitor; auto result = bellman_ford_shortest_paths( g, id_type(exp.s), container_value_fn(distances), container_value_fn(predecessors), - [](const auto& g, const auto& uv) { return edge_value(g, uv); }, visitor); + [](const auto& graph_ref, const auto& uv) { return edge_value(graph_ref, uv); }, visitor); REQUIRE(!result.has_value()); REQUIRE(visitor.edges_examined > 0); @@ -492,7 +492,7 @@ TEMPLATE_TEST_CASE("bellman_ford_shortest_paths - sparse negative cycle detectio auto result = bellman_ford_shortest_paths( g, id_type(10), container_value_fn(distances), container_value_fn(predecessors), - [](const auto& g, const auto& uv) { return edge_value(g, uv); }); + [](const auto& graph_ref, const auto& uv) { return edge_value(graph_ref, uv); }); // Negative cycle should be detected REQUIRE(result.has_value()); @@ -517,7 +517,7 @@ TEMPLATE_TEST_CASE("bellman_ford_shortest_paths - sparse find negative cycle ver auto cycle_vertex = bellman_ford_shortest_paths( g, id_type(10), container_value_fn(distances), container_value_fn(predecessors), - [](const auto& g, const auto& uv) { return edge_value(g, uv); }); + [](const auto& graph_ref, const auto& uv) { return edge_value(graph_ref, uv); }); REQUIRE(cycle_vertex.has_value()); @@ -547,6 +547,6 @@ TEMPLATE_TEST_CASE("bellman_ford_shortest_paths - sparse source not in graph thr // Vertex ID 999 does not exist in the sparse graph CHECK_THROWS_AS(bellman_ford_shortest_paths(g, id_type(999), container_value_fn(distances), container_value_fn(predecessors), - [](const auto& g, const auto& uv) { return edge_value(g, uv); }), + [](const auto& graph_ref, const auto& uv) { return edge_value(graph_ref, uv); }), std::out_of_range); } diff --git a/tests/algorithms/test_breadth_first_search.cpp b/tests/algorithms/test_breadth_first_search.cpp index 15b0fbb..e8898c6 100644 --- a/tests/algorithms/test_breadth_first_search.cpp +++ b/tests/algorithms/test_breadth_first_search.cpp @@ -49,7 +49,7 @@ struct BFSTrackingVisitor { } template - void on_examine_edge(const G& g, const Edge& e) { + void on_examine_edge(const G&, const Edge&) { // Store edge endpoints for verification edges_examined.push_back({-1, -1}); // Placeholder, actual implementation would extract source/target } @@ -197,11 +197,11 @@ TEST_CASE("breadth_first_search - complete graph", "[algorithm][bfs][single_sour TEST_CASE("breadth_first_search - tree structure", "[algorithm][bfs][single_source]") { using Graph = vov_void; - // Binary tree: 0 - // / \\ - // 1 2 - // / \\ - // 3 4 + /* Binary tree: 0 + / \\ + 1 2 + / \\ + 3 4 */ Graph g({{0, 1}, {0, 2}, {1, 3}, {1, 4}}); CountingVisitor visitor; @@ -654,10 +654,10 @@ TEMPLATE_TEST_CASE("breadth_first_search - sparse graph basic traversal", using Graph = TestType; auto g = bfs_graph(); - auto source = bfs_source(); + auto start_vertex = bfs_source(); CountingVisitor visitor; - breadth_first_search(g, source, visitor); + breadth_first_search(g, start_vertex, visitor); // BFS from source should discover all 5 vertices: source -> two children -> merge -> leaf REQUIRE(visitor.vertices_discovered == 5); @@ -671,10 +671,10 @@ TEMPLATE_TEST_CASE("breadth_first_search - sparse graph with tracking visitor", using Graph = TestType; auto g = bfs_graph(); - auto source = bfs_source(); + auto start_vertex = bfs_source(); BFSTrackingVisitor visitor; - breadth_first_search(g, source, visitor); + breadth_first_search(g, start_vertex, visitor); // All 5 vertices should be discovered, examined, and finished REQUIRE(visitor.discovered.size() == 5); @@ -682,7 +682,7 @@ TEMPLATE_TEST_CASE("breadth_first_search - sparse graph with tracking visitor", REQUIRE(visitor.finished.size() == 5); // Source vertex should be discovered first - REQUIRE(visitor.discovered[0] == static_cast(source)); + REQUIRE(visitor.discovered[0] == static_cast(start_vertex)); } TEMPLATE_TEST_CASE("breadth_first_search - sparse graph multi-source", @@ -713,10 +713,10 @@ TEMPLATE_TEST_CASE("breadth_first_search - sparse graph empty visitor", using Graph = TestType; auto g = bfs_graph(); - auto source = bfs_source(); + auto start_vertex = bfs_source(); // Should work with default empty visitor (no callbacks) - REQUIRE_NOTHROW(breadth_first_search(g, source)); + REQUIRE_NOTHROW(breadth_first_search(g, start_vertex)); } TEMPLATE_TEST_CASE("breadth_first_search - sparse graph partial reachability", diff --git a/tests/algorithms/test_depth_first_search.cpp b/tests/algorithms/test_depth_first_search.cpp index 4f7a517..69f6c3b 100644 --- a/tests/algorithms/test_depth_first_search.cpp +++ b/tests/algorithms/test_depth_first_search.cpp @@ -53,27 +53,27 @@ struct DFSTrackingVisitor { } template - void on_examine_edge(const G& g, const Edge& e) { + void on_examine_edge(const G&, const Edge&) { edges_examined.push_back({-1, -1}); // Placeholder } template - void on_tree_edge(const G& g, const Edge& e) { + void on_tree_edge(const G&, const Edge&) { tree_edges.push_back({-1, -1}); // Placeholder } template - void on_back_edge(const G& g, const Edge& e) { + void on_back_edge(const G&, const Edge&) { back_edges.push_back({-1, -1}); // Placeholder } template - void on_forward_or_cross_edge(const G& g, const Edge& e) { + void on_forward_or_cross_edge(const G&, const Edge&) { forward_or_cross_edges.push_back({-1, -1}); // Placeholder } template - void on_finish_edge(const G& g, const Edge& e) { + void on_finish_edge(const G&, const Edge&) { finished_edges.push_back({-1, -1}); // Placeholder } @@ -253,11 +253,11 @@ TEST_CASE("depth_first_search - self-loop handling", "[algorithm][dfs][single_so TEST_CASE("depth_first_search - tree structure", "[algorithm][dfs][single_source]") { using Graph = vov_void; - // Binary tree: 0 - // / \ - // 1 2 - // / \ - // 3 4 + /* Binary tree: 0 + / \ + 1 2 + / \ + 3 4 */ Graph g({{0, 1}, {0, 2}, {1, 3}, {1, 4}}); DFSCountingVisitor visitor; @@ -736,10 +736,10 @@ TEMPLATE_TEST_CASE("depth_first_search - sparse graph basic traversal", using Graph = TestType; auto g = bfs_graph(); // 5-vertex DAG: src->a,b->merge->leaf - auto source = bfs_source(); + auto start_vertex = bfs_source(); DFSCountingVisitor visitor; - depth_first_search(g, source, visitor); + depth_first_search(g, start_vertex, visitor); // DFS from source should discover all 5 reachable vertices REQUIRE(visitor.vertices_discovered == 5); @@ -752,23 +752,23 @@ TEMPLATE_TEST_CASE("depth_first_search - sparse graph with tracking visitor", using Graph = TestType; auto g = bfs_graph(); - auto source = bfs_source(); + auto start_vertex = bfs_source(); DFSTrackingVisitor visitor; - depth_first_search(g, source, visitor); + depth_first_search(g, start_vertex, visitor); // All 5 vertices should be discovered and finished REQUIRE(visitor.discovered.size() == 5); REQUIRE(visitor.finished.size() == 5); // Source vertex should be discovered first - REQUIRE(visitor.discovered[0] == static_cast(source)); + REQUIRE(visitor.discovered[0] == static_cast(start_vertex)); // Source should be initialized and started REQUIRE(visitor.initialized.size() == 1); - REQUIRE(visitor.initialized[0] == static_cast(source)); + REQUIRE(visitor.initialized[0] == static_cast(start_vertex)); REQUIRE(visitor.started.size() == 1); - REQUIRE(visitor.started[0] == static_cast(source)); + REQUIRE(visitor.started[0] == static_cast(start_vertex)); } TEMPLATE_TEST_CASE("depth_first_search - sparse graph DAG edge classification", @@ -778,16 +778,11 @@ TEMPLATE_TEST_CASE("depth_first_search - sparse graph DAG edge classification", // Diamond DAG: src->a, src->b, a->sink, b->sink auto g = dag_graph(); - auto source = bfs_source(); // DAG source == bfs source for contiguous; + auto start_vertex = bfs_source(); // DAG source == bfs source for contiguous; // for sparse, dag uses 10 as root too DFSCountingVisitor visitor; - - if constexpr (is_sparse_vertex_container_v) { - depth_first_search(g, vertex_id_t(10), visitor); - } else { - depth_first_search(g, vertex_id_t(0), visitor); - } + depth_first_search(g, start_vertex, visitor); // All 4 vertices discovered REQUIRE(visitor.vertices_discovered == 4); @@ -806,10 +801,10 @@ TEMPLATE_TEST_CASE("depth_first_search - sparse graph cycle detection", using Graph = TestType; auto g = cycle_graph(); - auto source = cycle_source(); + auto start_vertex = cycle_source(); DFSCountingVisitor visitor; - depth_first_search(g, source, visitor); + depth_first_search(g, start_vertex, visitor); // All 4 vertices in the cycle should be discovered REQUIRE(visitor.vertices_discovered == 4); @@ -825,10 +820,10 @@ TEMPLATE_TEST_CASE("depth_first_search - sparse graph empty visitor", using Graph = TestType; auto g = bfs_graph(); - auto source = bfs_source(); + auto start_vertex = bfs_source(); // Should work with default empty visitor (no callbacks) - REQUIRE_NOTHROW(depth_first_search(g, source)); + REQUIRE_NOTHROW(depth_first_search(g, start_vertex)); } TEMPLATE_TEST_CASE("depth_first_search - sparse graph partial reachability", diff --git a/tests/algorithms/test_dijkstra_indexed_heap.cpp b/tests/algorithms/test_dijkstra_indexed_heap.cpp index 26c7742..e079734 100644 --- a/tests/algorithms/test_dijkstra_indexed_heap.cpp +++ b/tests/algorithms/test_dijkstra_indexed_heap.cpp @@ -17,7 +17,6 @@ #include "../common/algorithm_test_types.hpp" #include "../common/map_graph_fixtures.hpp" #include -#include #include #include @@ -457,13 +456,13 @@ TEST_CASE("dijkstra(indexed_heap) - string vertex IDs (CLRS topology)", auto wt = [](const auto& gr, const auto& uv) { return edge_value(gr, uv); }; - VId source{"s"}; - dijkstra_shortest_paths(g, source, + VId start_vertex{"s"}; + dijkstra_shortest_paths(g, start_vertex, container_value_fn(d_def), container_value_fn(p_def), wt, empty_visitor{}, std::less{}, std::plus{}, use_default_heap{}, std::allocator{}); - dijkstra_shortest_paths(g, source, + dijkstra_shortest_paths(g, start_vertex, container_value_fn(d_idx), container_value_fn(p_idx), wt, empty_visitor{}, std::less{}, std::plus{}, use_indexed_dary_heap<>{}, std::allocator{}); diff --git a/tests/algorithms/test_dijkstra_shortest_paths.cpp b/tests/algorithms/test_dijkstra_shortest_paths.cpp index dfe2065..bc91978 100644 --- a/tests/algorithms/test_dijkstra_shortest_paths.cpp +++ b/tests/algorithms/test_dijkstra_shortest_paths.cpp @@ -52,7 +52,7 @@ TEST_CASE("dijkstra_shortest_paths - CLRS example", "[algorithm][dijkstra_shorte dijkstra_shortest_paths(g, vertex_id_t(0), container_value_fn(distance), container_value_fn(predecessor), - [](const auto& g, const auto& uv) { return edge_value(g, uv); }); + [](const auto& graph_ref, const auto& uv) { return edge_value(graph_ref, uv); }); // Validate against known results from CLRS Figure 24.6 REQUIRE(distance[0] == clrs_dijkstra_results::distances_from_0[0]); // s: 0 @@ -74,7 +74,7 @@ TEST_CASE("dijkstra_shortest_paths - path graph", "[algorithm][dijkstra_shortest dijkstra_shortest_paths(g, vertex_id_t(0), container_value_fn(distance), container_value_fn(predecessor), - [](const auto& g, const auto& uv) { return edge_value(g, uv); }); + [](const auto& graph_ref, const auto& uv) { return edge_value(graph_ref, uv); }); // Path: 0 -> 1 -> 2 -> 3 with weight 1 each for (size_t i = 0; i < path_graph_4_results::num_vertices; ++i) { @@ -93,7 +93,7 @@ TEST_CASE("dijkstra_shortest_distances - no predecessors", "[algorithm][dijkstra // Test distances-only variant (no predecessor tracking) dijkstra_shortest_distances(g, vertex_id_t(0), container_value_fn(distance), - [](const auto& g, const auto& uv) { return edge_value(g, uv); }); + [](const auto& graph_ref, const auto& uv) { return edge_value(graph_ref, uv); }); // Validate distances match expected results REQUIRE(distance[0] == clrs_dijkstra_results::distances_from_0[0]); // s: 0 @@ -118,7 +118,7 @@ TEST_CASE("dijkstra_shortest_paths - multi-source", "[algorithm][dijkstra_shorte dijkstra_shortest_paths(g, sources, container_value_fn(distance), container_value_fn(predecessor), - [](const auto& g, const auto& uv) { return edge_value(g, uv); }); + [](const auto& graph_ref, const auto& uv) { return edge_value(graph_ref, uv); }); // Both source vertices should have distance 0 REQUIRE(distance[0] == 0); @@ -142,7 +142,7 @@ TEST_CASE("dijkstra_shortest_distances - multi-source", "[algorithm][dijkstra_sh dijkstra_shortest_distances(g, sources, container_value_fn(distance), - [](const auto& g, const auto& uv) { return edge_value(g, uv); }); + [](const auto& graph_ref, const auto& uv) { return edge_value(graph_ref, uv); }); // Both source vertices should have distance 0 REQUIRE(distance[0] == 0); @@ -164,7 +164,7 @@ TEST_CASE("dijkstra_shortest_paths - with visitor", "[algorithm][dijkstra_shorte g, vertex_id_t(0), container_value_fn(distance), container_value_fn(predecessor), - [](const auto& g, const auto& uv) { return edge_value(g, uv); }, visitor); + [](const auto& graph_ref, const auto& uv) { return edge_value(graph_ref, uv); }, visitor); // Verify visitor was called (should have discovered all 4 vertices, examined them, and relaxed edges) REQUIRE(visitor.vertices_discovered == 4); @@ -209,7 +209,7 @@ TEST_CASE("dijkstra_shortest_paths - predecessor path reconstruction", "[algorit dijkstra_shortest_paths(g, vertex_id_t(0), container_value_fn(distance), container_value_fn(predecessor), - [](const auto& g, const auto& uv) { return edge_value(g, uv); }); + [](const auto& graph_ref, const auto& uv) { return edge_value(graph_ref, uv); }); // Reconstruct path from 0 to 3: should be 0 -> 1 -> 2 -> 3 std::vector> path; @@ -290,7 +290,7 @@ TEST_CASE("dijkstra_shortest_paths - vertex id visitor", "[algorithm][dijkstra_s dijkstra_shortest_paths(g, vertex_id_t(0), container_value_fn(distance), container_value_fn(predecessor), - [](const auto& g, const auto& uv) { return edge_value(g, uv); }, visitor); + [](const auto& graph_ref, const auto& uv) { return edge_value(graph_ref, uv); }, visitor); // All 5 vertices should be discovered via id-based callbacks // (examine may be called more than once per vertex due to re-enqueue) @@ -317,7 +317,7 @@ TEST_CASE("dijkstra_shortest_paths - source vertex out of range throws", "[algor CHECK_THROWS_AS(dijkstra_shortest_paths(g, vertex_id_t(99), container_value_fn(distances), container_value_fn(predecessor), - [](const auto& g, const auto& uv) { return edge_value(g, uv); }), + [](const auto& graph_ref, const auto& uv) { return edge_value(graph_ref, uv); }), std::out_of_range); } @@ -380,7 +380,7 @@ TEST_CASE("dijkstra_shortest_paths - on_edge_not_relaxed visitor callback", "[al dijkstra_shortest_paths(g, vertex_id_t(0), container_value_fn(distances), container_value_fn(predecessor), - [](const auto& g, const auto& uv) { return edge_value(g, uv); }, visitor); + [](const auto& graph_ref, const auto& uv) { return edge_value(graph_ref, uv); }, visitor); CHECK(visitor.edges_not_relaxed > 0); REQUIRE(distances[0] == 0); @@ -402,8 +402,6 @@ TEMPLATE_TEST_CASE("dijkstra_shortest_paths - sparse CLRS example", SPARSE_VERTEX_TYPES) { using Graph = TestType; using id_type = vertex_id_t; - using DistMap = decltype(make_vertex_property_map(std::declval(), 0)); - using PredMap = decltype(make_vertex_property_map(std::declval(), id_type{})); const auto& exp = clrs_dijkstra_sparse_expected{}; auto g = map_fixtures::clrs_dijkstra_graph(); @@ -416,7 +414,7 @@ TEMPLATE_TEST_CASE("dijkstra_shortest_paths - sparse CLRS example", dijkstra_shortest_paths(g, id_type(exp.s), container_value_fn(distances), container_value_fn(predecessors), - [](const auto& g, const auto& uv) { return edge_value(g, uv); }); + [](const auto& graph_ref, const auto& uv) { return edge_value(graph_ref, uv); }); // Validate distances against known CLRS results for (size_t i = 0; i < exp.num_vertices; ++i) { @@ -439,7 +437,7 @@ TEMPLATE_TEST_CASE("dijkstra_shortest_distances - sparse CLRS example", dijkstra_shortest_distances(g, id_type(exp.s), container_value_fn(distances), - [](const auto& g, const auto& uv) { return edge_value(g, uv); }); + [](const auto& graph_ref, const auto& uv) { return edge_value(graph_ref, uv); }); for (size_t i = 0; i < exp.num_vertices; ++i) { REQUIRE(distances[exp.vertex_ids[i]] == exp.distances[i]); @@ -464,7 +462,7 @@ TEMPLATE_TEST_CASE("dijkstra_shortest_paths - sparse multi-source", dijkstra_shortest_paths(g, sources, container_value_fn(distances), container_value_fn(predecessors), - [](const auto& g, const auto& uv) { return edge_value(g, uv); }); + [](const auto& graph_ref, const auto& uv) { return edge_value(graph_ref, uv); }); // Both sources should have distance 0 REQUIRE(distances[exp.s] == 0); @@ -494,7 +492,7 @@ TEMPLATE_TEST_CASE("dijkstra_shortest_paths - sparse with visitor", g, id_type(exp.s), container_value_fn(distances), container_value_fn(predecessors), - [](const auto& g, const auto& uv) { return edge_value(g, uv); }, visitor); + [](const auto& graph_ref, const auto& uv) { return edge_value(graph_ref, uv); }, visitor); REQUIRE(visitor.vertices_discovered == static_cast(exp.num_vertices)); REQUIRE(visitor.vertices_examined >= static_cast(exp.num_vertices)); @@ -517,7 +515,7 @@ TEMPLATE_TEST_CASE("dijkstra_shortest_paths - sparse source not in graph throws" CHECK_THROWS_AS(dijkstra_shortest_paths(g, id_type(999), container_value_fn(distances), container_value_fn(predecessors), - [](const auto& g, const auto& uv) { return edge_value(g, uv); }), + [](const auto& graph_ref, const auto& uv) { return edge_value(graph_ref, uv); }), std::out_of_range); } @@ -585,7 +583,7 @@ TEMPLATE_TEST_CASE("dijkstra_shortest_paths - string vertex IDs", dijkstra_shortest_paths(g, std::string("s"), container_value_fn(distances), container_value_fn(predecessors), - [](const auto& g, const auto& uv) { return edge_value(g, uv); }); + [](const auto& graph_ref, const auto& uv) { return edge_value(graph_ref, uv); }); // Validate all distances for (const auto& [vid, expected_dist] : clrs_string_expected::distances) { @@ -603,14 +601,13 @@ TEMPLATE_TEST_CASE("dijkstra_shortest_distances - string vertex IDs", "[algorithm][dijkstra_shortest_paths][string_id]", STRING_VID_TYPES) { using Graph = TestType; - using id_type = vertex_id_t; auto g = clrs_dijkstra_string_graph(); auto distances = make_vertex_property_map(g, infinite_distance()); dijkstra_shortest_distances(g, std::string("s"), container_value_fn(distances), - [](const auto& g, const auto& uv) { return edge_value(g, uv); }); + [](const auto& graph_ref, const auto& uv) { return edge_value(graph_ref, uv); }); for (const auto& [vid, expected_dist] : clrs_string_expected::distances) { REQUIRE(distances[vid] == expected_dist); @@ -634,7 +631,7 @@ TEMPLATE_TEST_CASE("dijkstra_shortest_paths - string vertex IDs multi-source", dijkstra_shortest_paths(g, sources, container_value_fn(distances), container_value_fn(predecessors), - [](const auto& g, const auto& uv) { return edge_value(g, uv); }); + [](const auto& graph_ref, const auto& uv) { return edge_value(graph_ref, uv); }); // Both sources should have distance 0 REQUIRE(distances[std::string("s")] == 0); @@ -663,7 +660,7 @@ TEMPLATE_TEST_CASE("dijkstra_shortest_paths - string vertex IDs with visitor", g, std::string("s"), container_value_fn(distances), container_value_fn(predecessors), - [](const auto& g, const auto& uv) { return edge_value(g, uv); }, visitor); + [](const auto& graph_ref, const auto& uv) { return edge_value(graph_ref, uv); }, visitor); REQUIRE(visitor.vertices_discovered == static_cast(clrs_string_expected::num_vertices)); REQUIRE(visitor.vertices_examined >= static_cast(clrs_string_expected::num_vertices)); @@ -687,7 +684,7 @@ TEMPLATE_TEST_CASE("dijkstra_shortest_paths - string vertex IDs invalid source t CHECK_THROWS_AS(dijkstra_shortest_paths(g, std::string("nonexistent"), container_value_fn(distances), container_value_fn(predecessors), - [](const auto& g, const auto& uv) { return edge_value(g, uv); }), + [](const auto& graph_ref, const auto& uv) { return edge_value(graph_ref, uv); }), std::out_of_range); } @@ -706,7 +703,7 @@ TEMPLATE_TEST_CASE("dijkstra_shortest_paths - string vertex IDs path reconstruct dijkstra_shortest_paths(g, std::string("s"), container_value_fn(distances), container_value_fn(predecessors), - [](const auto& g, const auto& uv) { return edge_value(g, uv); }); + [](const auto& graph_ref, const auto& uv) { return edge_value(graph_ref, uv); }); // Reconstruct path from "s" to "x": should be s -> y -> t -> x (cost 5+3+1=9) std::vector path; diff --git a/tests/algorithms/test_label_propagation.cpp b/tests/algorithms/test_label_propagation.cpp index 23454eb..8f1e4bd 100644 --- a/tests/algorithms/test_label_propagation.cpp +++ b/tests/algorithms/test_label_propagation.cpp @@ -419,13 +419,12 @@ using namespace graph::test::map_fixtures; /// Generic convergence check for vertex property maps. template bool fully_converged_generic(G&& g, const Label& label) { - using vid_t = adj_list::vertex_id_t>; auto it = vertices(g).begin(); - auto end = vertices(g).end(); - if (it == end) + auto last = vertices(g).end(); + if (it == last) return true; auto first_label = label.find(vertex_id(g, *it))->second; - for (; it != end; ++it) { + for (; it != last; ++it) { if (label.find(vertex_id(g, *it))->second != first_label) return false; } @@ -436,7 +435,6 @@ TEMPLATE_TEST_CASE("label_propagation - sparse single edge", "[algorithm][label_propagation][sparse]", SPARSE_VERTEX_TYPES) { using Graph = TestType; - using vid_t = adj_list::vertex_id_t; // Bidirectional edge: 10-20 Graph g({{10, 20, 1}, {20, 10, 1}}); @@ -457,7 +455,6 @@ TEMPLATE_TEST_CASE("label_propagation - sparse path all same label", "[algorithm][label_propagation][sparse]", SPARSE_VERTEX_TYPES) { using Graph = TestType; - using vid_t = adj_list::vertex_id_t; // Bidirectional path: 10-20-30-40 Graph g({{10, 20, 1}, {20, 10, 1}, {20, 30, 1}, {30, 20, 1}, {30, 40, 1}, {40, 30, 1}}); @@ -478,7 +475,6 @@ TEMPLATE_TEST_CASE("label_propagation - sparse K4 majority wins", "[algorithm][label_propagation][sparse]", SPARSE_VERTEX_TYPES) { using Graph = TestType; - using vid_t = adj_list::vertex_id_t; // K4: every pair connected bidirectionally Graph g({{10, 20, 1}, {10, 30, 1}, {10, 40, 1}, @@ -503,7 +499,6 @@ TEMPLATE_TEST_CASE("label_propagation - sparse disconnected", "[algorithm][label_propagation][sparse]", SPARSE_VERTEX_TYPES) { using Graph = TestType; - using vid_t = adj_list::vertex_id_t; // Component 1: 10-20, Component 2: 30-40 Graph g({{10, 20, 1}, {20, 10, 1}, {30, 40, 1}, {40, 30, 1}}); @@ -528,7 +523,6 @@ TEMPLATE_TEST_CASE("label_propagation - sparse empty_label propagation", "[algorithm][label_propagation][sparse]", SPARSE_VERTEX_TYPES) { using Graph = TestType; - using vid_t = adj_list::vertex_id_t; // Bidirectional path: 10-20-30-40 Graph g({{10, 20, 1}, {20, 10, 1}, {20, 30, 1}, {30, 20, 1}, {30, 40, 1}, {40, 30, 1}}); diff --git a/tests/algorithms/test_mis.cpp b/tests/algorithms/test_mis.cpp index 9951e90..aaa40be 100644 --- a/tests/algorithms/test_mis.cpp +++ b/tests/algorithms/test_mis.cpp @@ -39,13 +39,13 @@ bool is_maximal(const G& g, const std::vector& mis_v for (auto u : vertices(g)) { auto uid = vertex_id(g, u); - if (mis_set.count(uid)) + if (mis_set.count(static_cast(uid))) continue; // Already in set // Check if uid is adjacent to any vertex in the MIS bool adjacent_to_mis = false; for (auto uv : edges(g, u)) { - if (mis_set.count(target_id(g, uv))) { + if (mis_set.count(static_cast(target_id(g, uv)))) { adjacent_to_mis = true; break; } diff --git a/tests/algorithms/test_mst.cpp b/tests/algorithms/test_mst.cpp index 004ac19..8f118e8 100644 --- a/tests/algorithms/test_mst.cpp +++ b/tests/algorithms/test_mst.cpp @@ -48,20 +48,20 @@ struct simple_edge { * For N vertices, a tree must have exactly N-1 edges */ template -bool is_tree(size_t num_vertices, const EdgeList& edges) { - return edges.size() == num_vertices - 1; +bool is_tree(size_t vertex_count, const EdgeList& edge_list) { + return edge_list.size() == vertex_count - 1; } /** * @brief Calculate total weight of edges in a spanning tree */ template -auto total_weight(const EdgeList& edges) { +auto total_weight(const EdgeList& edge_list) { using edge_type = typename EdgeList::value_type; using weight_type = typename edge_type::value_type; weight_type total = 0; - for (const auto& e : edges) { + for (const auto& e : edge_list) { total += e.value; } return total; @@ -71,9 +71,9 @@ auto total_weight(const EdgeList& edges) { * @brief Check if all edges in tree connect vertices that exist */ template -bool edges_valid(size_t num_vertices, const EdgeList& edges) { - for (const auto& e : edges) { - if (e.source_id >= num_vertices || e.target_id >= num_vertices) { +bool edges_valid(size_t vertex_count, const EdgeList& edge_list) { + for (const auto& e : edge_list) { + if (e.source_id >= vertex_count || e.target_id >= vertex_count) { return false; } } @@ -84,15 +84,15 @@ bool edges_valid(size_t num_vertices, const EdgeList& edges) { * @brief Check connectivity using union-find */ template -bool is_connected(size_t num_vertices, const EdgeList& edges) { - if (num_vertices == 0) +bool is_connected(size_t vertex_count, const EdgeList& edge_list) { + if (vertex_count == 0) return true; - if (num_vertices == 1) + if (vertex_count == 1) return true; - if (edges.empty()) + if (edge_list.empty()) return false; - std::vector parent(num_vertices); + std::vector parent(vertex_count); std::iota(parent.begin(), parent.end(), 0); auto find = [&](size_t x) { @@ -113,13 +113,13 @@ bool is_connected(size_t num_vertices, const EdgeList& edges) { return false; }; - for (const auto& e : edges) { + for (const auto& e : edge_list) { unite(e.source_id, e.target_id); } // Check if all vertices have the same root size_t root = find(0); - for (size_t i = 1; i < num_vertices; ++i) { + for (size_t i = 1; i < vertex_count; ++i) { if (find(i) != root) { return false; } @@ -379,7 +379,7 @@ TEST_CASE("kruskal and prim produce same MST weight", "[algorithm][mst]") { using Edge = simple_edge; // Create a graph - std::vector edges = {{0, 1, 2}, {0, 3, 6}, {1, 2, 3}, {1, 3, 8}, {1, 4, 5}, {2, 4, 7}, {3, 4, 9}}; + std::vector edge_list = {{0, 1, 2}, {0, 3, 6}, {1, 2, 3}, {1, 3, 8}, {1, 4, 5}, {2, 4, 7}, {3, 4, 9}}; // Build graph for Prim with bidirectional edges Graph g({{0, 1, 2}, @@ -399,7 +399,7 @@ TEST_CASE("kruskal and prim produce same MST weight", "[algorithm][mst]") { // Run Kruskal std::vector kruskal_mst; - kruskal(edges, kruskal_mst); + kruskal(edge_list, kruskal_mst); int kruskal_weight = total_weight(kruskal_mst); // Run Prim @@ -600,9 +600,9 @@ TEMPLATE_TEST_CASE("prim - sparse kruskal comparison", {40, 50, 9}, {50, 40, 9}}); // Run Kruskal with contiguous edge list (same topology) - std::vector edges = {{0, 1, 2}, {0, 3, 6}, {1, 2, 3}, {1, 3, 8}, {1, 4, 5}, {2, 4, 7}, {3, 4, 9}}; + std::vector edge_list = {{0, 1, 2}, {0, 3, 6}, {1, 2, 3}, {1, 3, 8}, {1, 4, 5}, {2, 4, 7}, {3, 4, 9}}; std::vector kruskal_mst; - kruskal(edges, kruskal_mst); + kruskal(edge_list, kruskal_mst); int kruskal_weight = total_weight(kruskal_mst); // Run Prim on sparse graph @@ -640,7 +640,7 @@ TEMPLATE_TEST_CASE("prim - sparse invalid seed throws", TEST_CASE("prim - indexed d-ary heap parity", "[algorithm][mst][prim][indexed_heap]") { using Graph = vov_weighted; - using id_t = vertex_id_t; + using vid_t = vertex_id_t; // 8-vertex weighted undirected graph that triggers post-finalization // re-relaxation (the case that exposed the original Prim correctness bug). @@ -654,10 +654,10 @@ TEST_CASE("prim - indexed d-ary heap parity", "[algorithm][mst][prim][indexed_he const auto N = num_vertices(g); auto run = [&](auto heap_tag) { - std::vector predecessor(N); + std::vector predecessor(N); std::vector weight(N); init_shortest_paths(g, weight, predecessor); - auto total = prim(g, id_t{0}, + auto total = prim(g, vid_t{0}, container_value_fn(weight), container_value_fn(predecessor), [](const auto& gr, const auto& uv) { return edge_value(gr, uv); }, @@ -672,12 +672,12 @@ TEST_CASE("prim - indexed d-ary heap parity", "[algorithm][mst][prim][indexed_he // Cross-check the absolute MST weight against Kruskal on the same edges. using Edge = simple_edge; - std::vector edges = { + std::vector edge_list = { {0, 1, 4}, {0, 2, 1}, {1, 2, 2}, {1, 3, 5}, {2, 3, 8}, {2, 4, 10}, {3, 4, 2}, {3, 5, 6}, {4, 5, 3}, {4, 6, 9}, {5, 6, 7}, {5, 7, 1}, {6, 7, 4}}; std::vector mst; - graph::kruskal(edges, mst); + graph::kruskal(edge_list, mst); const int kruskal_weight = total_weight(mst); REQUIRE(kruskal_weight == 18); // sanity diff --git a/tests/algorithms/test_scc_bidirectional.cpp b/tests/algorithms/test_scc_bidirectional.cpp index 5dacc5b..0a904d8 100644 --- a/tests/algorithms/test_scc_bidirectional.cpp +++ b/tests/algorithms/test_scc_bidirectional.cpp @@ -13,7 +13,6 @@ #include #include -#include #include #include #include "../common/graph_fixtures.hpp" @@ -84,11 +83,11 @@ using bidir_vov_int = dynamic_graph -bool all_same_component(const Component& component, const std::vector& vertices) { - if (vertices.empty()) +bool all_same_component(const Component& component, const std::vector& vertex_ids) { + if (vertex_ids.empty()) return true; - auto first_comp = component[vertices[0]]; - return std::all_of(vertices.begin(), vertices.end(), [&](size_t v) { return component[v] == first_comp; }); + auto first_comp = component[vertex_ids[0]]; + return std::all_of(vertex_ids.begin(), vertex_ids.end(), [&](size_t v) { return component[v] == first_comp; }); } template diff --git a/tests/algorithms/test_tarjan_scc.cpp b/tests/algorithms/test_tarjan_scc.cpp index f63479e..01ee374 100644 --- a/tests/algorithms/test_tarjan_scc.cpp +++ b/tests/algorithms/test_tarjan_scc.cpp @@ -12,7 +12,6 @@ #include #include #include -#include #include #include #include "../common/graph_fixtures.hpp" @@ -39,11 +38,11 @@ using vov_int = dynamic_graph -bool all_same_component(const Component& component, const std::vector& vertices) { - if (vertices.empty()) +bool all_same_component(const Component& component, const std::vector& vertex_ids) { + if (vertex_ids.empty()) return true; - auto first_comp = component[vertices[0]]; - return std::all_of(vertices.begin(), vertices.end(), [&](size_t v) { return component[v] == first_comp; }); + auto first_comp = component[vertex_ids[0]]; + return std::all_of(vertex_ids.begin(), vertex_ids.end(), [&](size_t v) { return component[v] == first_comp; }); } template diff --git a/tests/algorithms/test_topological_sort.cpp b/tests/algorithms/test_topological_sort.cpp index c037948..c1c080b 100644 --- a/tests/algorithms/test_topological_sort.cpp +++ b/tests/algorithms/test_topological_sort.cpp @@ -25,17 +25,20 @@ using namespace graph::test::algorithm; // Verify that the ordering is valid: for every edge (u,v), u appears before v template bool is_valid_topological_order(const G& g, const Order& order) { + using id_type = vertex_id_t; + // Build position map - std::unordered_map position; + std::unordered_map position; for (size_t i = 0; i < order.size(); ++i) { - position[order[i]] = i; + position[static_cast(order[i])] = i; } // Check every edge for (auto uid : order) { - for (auto&& [vid] : views::basic_incidence(g, uid)) { + const id_type uid_key = static_cast(uid); + for (auto&& [vid] : views::basic_incidence(g, uid_key)) { // If target is in the ordering, it must come after source - if (position.count(vid) && position[uid] >= position[vid]) { + if (position.count(vid) && position[uid_key] >= position[vid]) { return false; } } @@ -52,7 +55,7 @@ TEST_CASE("topological_sort full-graph - simple DAG", "[algorithm][topological_s // DAG: 0 -> 1 -> 2 Graph g({{0, 1}, {1, 2}}); - std::vector order; + std::vector order; bool success = topological_sort(g, std::back_inserter(order)); @@ -67,7 +70,7 @@ TEST_CASE("topological_sort full-graph - diamond DAG", "[algorithm][topological_ // Diamond: 0 -> {1,2} -> 3 Graph g({{0, 1}, {0, 2}, {1, 3}, {2, 3}}); - std::vector order; + std::vector order; bool success = topological_sort(g, std::back_inserter(order)); @@ -83,7 +86,7 @@ TEST_CASE("topological_sort full-graph - disconnected components", "[algorithm][ // Two components: 0->1, 2->3 Graph g({{0, 1}, {2, 3}}); - std::vector order; + std::vector order; bool success = topological_sort(g, std::back_inserter(order)); @@ -92,8 +95,8 @@ TEST_CASE("topological_sort full-graph - disconnected components", "[algorithm][ REQUIRE(is_valid_topological_order(g, order)); // All vertices should be present - std::set vertices(order.begin(), order.end()); - REQUIRE(vertices.size() == 4); + std::set vertex_set(order.begin(), order.end()); + REQUIRE(vertex_set.size() == 4); } TEST_CASE("topological_sort full-graph - cycle detection", "[algorithm][topological_sort][full_graph][cycle]") { @@ -101,7 +104,7 @@ TEST_CASE("topological_sort full-graph - cycle detection", "[algorithm][topologi // Cycle: 0 -> 1 -> 2 -> 0 Graph g({{0, 1}, {1, 2}, {2, 0}}); - std::vector order; + std::vector order; bool success = topological_sort(g, std::back_inserter(order)); @@ -112,7 +115,7 @@ TEST_CASE("topological_sort full-graph - single vertex", "[algorithm][topologica using Graph = vov_void; auto g = single_vertex(); - std::vector order; + std::vector order; bool success = topological_sort(g, std::back_inserter(order)); @@ -126,7 +129,7 @@ TEST_CASE("topological_sort full-graph - complex DAG multiple paths", "[algorith // Complex DAG: 0->{1,2}, 1->3, 2->3 Graph g({{0, 1}, {0, 2}, {1, 3}, {2, 3}}); - std::vector order; + std::vector order; bool success = topological_sort(g, std::back_inserter(order)); @@ -135,8 +138,8 @@ TEST_CASE("topological_sort full-graph - complex DAG multiple paths", "[algorith REQUIRE(is_valid_topological_order(g, order)); // Verify all vertices present - std::set vertices(order.begin(), order.end()); - REQUIRE(vertices == std::set{0, 1, 2, 3}); + std::set vertex_set(order.begin(), order.end()); + REQUIRE(vertex_set == std::set{0, 1, 2, 3}); REQUIRE(order.front() == 0); REQUIRE(order.back() == 3); } @@ -146,7 +149,7 @@ TEST_CASE("topological_sort full-graph - tree structure", "[algorithm][topologic // Binary tree: 0 -> {1, 2}, 1 -> {3, 4} Graph g({{0, 1}, {0, 2}, {1, 3}, {1, 4}}); - std::vector order; + std::vector order; bool success = topological_sort(g, std::back_inserter(order)); @@ -165,7 +168,7 @@ TEST_CASE("topological_sort single-source - simple DAG", "[algorithm][topologica // DAG: 0 -> 1 -> 2 Graph g({{0, 1}, {1, 2}}); - std::vector order; + std::vector order; bool success = topological_sort(g, 0u, std::back_inserter(order)); @@ -180,7 +183,7 @@ TEST_CASE("topological_sort single-source - diamond DAG", "[algorithm][topologic // Diamond: 0 -> {1,2} -> 3 Graph g({{0, 1}, {0, 2}, {1, 3}, {2, 3}}); - std::vector order; + std::vector order; bool success = topological_sort(g, 0u, std::back_inserter(order)); @@ -196,14 +199,14 @@ TEST_CASE("topological_sort single-source - partial graph", "[algorithm][topolog // Graph: 0->1->2, 3->4 (3,4 unreachable from 0) Graph g({{0, 1}, {1, 2}, {3, 4}}); - std::vector order; + std::vector order; bool success = topological_sort(g, 0u, std::back_inserter(order)); REQUIRE(success); REQUIRE(order.size() == 3); // Only 0, 1, 2 - REQUIRE(std::find(order.begin(), order.end(), 3) == order.end()); - REQUIRE(std::find(order.begin(), order.end(), 4) == order.end()); + REQUIRE(std::find(order.begin(), order.end(), static_cast(3)) == order.end()); + REQUIRE(std::find(order.begin(), order.end(), static_cast(4)) == order.end()); } TEST_CASE("topological_sort single-source - cycle detection", "[algorithm][topological_sort][single_source][cycle]") { @@ -211,7 +214,7 @@ TEST_CASE("topological_sort single-source - cycle detection", "[algorithm][topol // Cycle: 0 -> 1 -> 2 -> 0 Graph g({{0, 1}, {1, 2}, {2, 0}}); - std::vector order; + std::vector order; bool success = topological_sort(g, 0u, std::back_inserter(order)); @@ -223,7 +226,7 @@ TEST_CASE("topological_sort single-source - isolated vertex", "[algorithm][topol // Graph: 0->1, 2 (isolated), 3->4 Graph g({{0, 1}, {3, 4}}); - std::vector order; + std::vector order; bool success = topological_sort(g, 2u, std::back_inserter(order)); @@ -237,7 +240,7 @@ TEST_CASE("topological_sort single-source - tree structure", "[algorithm][topolo // Binary tree: 0 -> {1, 2}, 1 -> {3, 4} Graph g({{0, 1}, {0, 2}, {1, 3}, {1, 4}}); - std::vector order; + std::vector order; bool success = topological_sort(g, 0u, std::back_inserter(order)); @@ -253,7 +256,7 @@ TEST_CASE("topological_sort single-source - starting from middle vertex", // Chain: 0->1->2->3->4 Graph g({{0, 1}, {1, 2}, {2, 3}, {3, 4}}); - std::vector order; + std::vector order; // Start from vertex 2 (middle) bool success = topological_sort(g, 2u, std::back_inserter(order)); @@ -272,7 +275,7 @@ TEST_CASE("topological_sort - single vertex", "[algorithm][topological_sort][mul using Graph = vov_void; auto g = single_vertex(); - std::vector order; + std::vector order; std::vector sources = {0}; bool success = topological_sort(g, sources, std::back_inserter(order)); @@ -287,7 +290,7 @@ TEST_CASE("topological_sort - simple DAG", "[algorithm][topological_sort][multi_ // DAG: 0 -> 1 -> 2 Graph g({{0, 1}, {1, 2}}); - std::vector order; + std::vector order; std::vector sources = {0}; bool success = topological_sort(g, sources, std::back_inserter(order)); @@ -297,9 +300,9 @@ TEST_CASE("topological_sort - simple DAG", "[algorithm][topological_sort][multi_ REQUIRE(is_valid_topological_order(g, order)); // 0 must come before 1, 1 must come before 2 - auto pos_0 = std::find(order.begin(), order.end(), 0); - auto pos_1 = std::find(order.begin(), order.end(), 1); - auto pos_2 = std::find(order.begin(), order.end(), 2); + auto pos_0 = std::find(order.begin(), order.end(), static_cast(0)); + auto pos_1 = std::find(order.begin(), order.end(), static_cast(1)); + auto pos_2 = std::find(order.begin(), order.end(), static_cast(2)); REQUIRE(pos_0 < pos_1); REQUIRE(pos_1 < pos_2); } @@ -309,7 +312,7 @@ TEST_CASE("topological_sort - diamond DAG", "[algorithm][topological_sort][multi // Diamond: 0 -> {1,2} -> 3 Graph g({{0, 1}, {0, 2}, {1, 3}, {2, 3}}); - std::vector order; + std::vector order; std::vector sources = {0}; bool success = topological_sort(g, sources, std::back_inserter(order)); @@ -329,7 +332,7 @@ TEST_CASE("topological_sort - multi-source same component", "[algorithm][topolog // Graph: 0->2, 1->2, 2->3 Graph g({{0, 2}, {1, 2}, {2, 3}}); std::vector sources = {0, 1}; - std::vector order; + std::vector order; bool success = topological_sort(g, sources, std::back_inserter(order)); @@ -338,10 +341,10 @@ TEST_CASE("topological_sort - multi-source same component", "[algorithm][topolog REQUIRE(is_valid_topological_order(g, order)); // Both 0 and 1 must come before 2, 2 must come before 3 - auto pos_0 = std::find(order.begin(), order.end(), 0); - auto pos_1 = std::find(order.begin(), order.end(), 1); - auto pos_2 = std::find(order.begin(), order.end(), 2); - auto pos_3 = std::find(order.begin(), order.end(), 3); + auto pos_0 = std::find(order.begin(), order.end(), static_cast(0)); + auto pos_1 = std::find(order.begin(), order.end(), static_cast(1)); + auto pos_2 = std::find(order.begin(), order.end(), static_cast(2)); + auto pos_3 = std::find(order.begin(), order.end(), static_cast(3)); REQUIRE(pos_0 < pos_2); REQUIRE(pos_1 < pos_2); REQUIRE(pos_2 < pos_3); @@ -353,7 +356,7 @@ TEST_CASE("topological_sort - multi-source disconnected components", "[algorithm // Two components: 0->1, 2->3 Graph g({{0, 1}, {2, 3}}); std::vector sources = {0, 2}; - std::vector order; + std::vector order; bool success = topological_sort(g, sources, std::back_inserter(order)); @@ -368,18 +371,18 @@ TEST_CASE("topological_sort - partial graph (unreachable vertices)", "[algorithm // Graph: 0->1->2, 3->4 (3,4 unreachable from 0) Graph g({{0, 1}, {1, 2}, {3, 4}}); std::vector sources = {0}; - std::vector order; + std::vector order; bool success = topological_sort(g, sources, std::back_inserter(order)); REQUIRE(success); REQUIRE(order.size() == 3); // Only 0, 1, 2 - REQUIRE(std::find(order.begin(), order.end(), 0) != order.end()); - REQUIRE(std::find(order.begin(), order.end(), 1) != order.end()); - REQUIRE(std::find(order.begin(), order.end(), 2) != order.end()); + REQUIRE(std::find(order.begin(), order.end(), static_cast(0)) != order.end()); + REQUIRE(std::find(order.begin(), order.end(), static_cast(1)) != order.end()); + REQUIRE(std::find(order.begin(), order.end(), static_cast(2)) != order.end()); // 3 and 4 should NOT be in the output - REQUIRE(std::find(order.begin(), order.end(), 3) == order.end()); - REQUIRE(std::find(order.begin(), order.end(), 4) == order.end()); + REQUIRE(std::find(order.begin(), order.end(), static_cast(3)) == order.end()); + REQUIRE(std::find(order.begin(), order.end(), static_cast(4)) == order.end()); } TEST_CASE("topological_sort - cycle detection simple", "[algorithm][topological_sort][cycle][multi_source]") { @@ -388,7 +391,7 @@ TEST_CASE("topological_sort - cycle detection simple", "[algorithm][topological_ // Simple cycle: 0 -> 1 -> 2 -> 0 Graph g({{0, 1}, {1, 2}, {2, 0}}); std::vector sources = {0}; - std::vector order; + std::vector order; bool success = topological_sort(g, sources, std::back_inserter(order)); @@ -401,7 +404,7 @@ TEST_CASE("topological_sort - cycle detection self-loop", "[algorithm][topologic // Self-loop at vertex 0 auto g = self_loop(); std::vector sources = {0}; - std::vector order; + std::vector order; bool success = topological_sort(g, sources, std::back_inserter(order)); @@ -414,7 +417,7 @@ TEST_CASE("topological_sort - cycle detection complex", "[algorithm][topological // DAG with cycle: 0->1->2->3, 3->1 (cycle at 1-2-3) Graph g({{0, 1}, {1, 2}, {2, 3}, {3, 1}}); std::vector sources = {0}; - std::vector order; + std::vector order; bool success = topological_sort(g, sources, std::back_inserter(order)); @@ -427,7 +430,7 @@ TEST_CASE("topological_sort - tree structure", "[algorithm][topological_sort][mu // Binary tree: 0 -> {1, 2}, 1 -> {3, 4} Graph g({{0, 1}, {0, 2}, {1, 3}, {1, 4}}); std::vector sources = {0}; - std::vector order; + std::vector order; bool success = topological_sort(g, sources, std::back_inserter(order)); @@ -445,7 +448,7 @@ TEST_CASE("topological_sort - long chain", "[algorithm][topological_sort][multi_ // Chain: 0->1->2->3->4->5 Graph g({{0, 1}, {1, 2}, {2, 3}, {3, 4}, {4, 5}}); std::vector sources = {0}; - std::vector order; + std::vector order; bool success = topological_sort(g, sources, std::back_inserter(order)); @@ -469,7 +472,7 @@ TEST_CASE("topological_sort - complex DAG", "[algorithm][topological_sort][multi // 5 -> 6 Graph g({{0, 1}, {0, 2}, {0, 3}, {1, 4}, {2, 4}, {2, 5}, {3, 5}, {4, 6}, {5, 6}}); std::vector sources = {0}; - std::vector order; + std::vector order; bool success = topological_sort(g, sources, std::back_inserter(order)); @@ -487,7 +490,7 @@ TEST_CASE("topological_sort - empty source list", "[algorithm][topological_sort] Graph g({{0, 1}, {1, 2}}); std::vector sources; // Empty - std::vector order; + std::vector order; bool success = topological_sort(g, sources, std::back_inserter(order)); @@ -502,7 +505,7 @@ TEST_CASE("topological_sort - redundant sources", "[algorithm][topological_sort] Graph g({{0, 1}, {1, 2}}); // Sources include both 0 and 1, but 1 is reachable from 0 std::vector sources = {0, 1}; - std::vector order; + std::vector order; bool success = topological_sort(g, sources, std::back_inserter(order)); @@ -521,7 +524,7 @@ TEST_CASE("topological_sort - parallel edges", "[algorithm][topological_sort][mu // Parallel edges: 0->1 (twice), 1->2 Graph g({{0, 1}, {0, 1}, {1, 2}}); std::vector sources = {0}; - std::vector order; + std::vector order; bool success = topological_sort(g, sources, std::back_inserter(order)); @@ -536,7 +539,7 @@ TEST_CASE("topological_sort - isolated vertex as source", "[algorithm][topologic // Graph: 0->1, 2 (isolated), 3->4 Graph g({{0, 1}, {3, 4}}); std::vector sources = {2}; // Isolated vertex - std::vector order; + std::vector order; bool success = topological_sort(g, sources, std::back_inserter(order)); @@ -551,7 +554,7 @@ TEST_CASE("topological_sort - all vertices as sources", "[algorithm][topological // Graph: 0->2, 1->2, 2->3 Graph g({{0, 2}, {1, 2}, {2, 3}}); std::vector sources = {0, 1, 2, 3}; // All vertices - std::vector order; + std::vector order; bool success = topological_sort(g, sources, std::back_inserter(order)); @@ -566,7 +569,7 @@ TEST_CASE("topological_sort - verify unique vertices in output", "[algorithm][to // Diamond graph from multiple overlapping sources Graph g({{0, 1}, {0, 2}, {1, 3}, {2, 3}}); std::vector sources = {0, 1, 2}; // Overlapping sources - std::vector order; + std::vector order; bool success = topological_sort(g, sources, std::back_inserter(order)); @@ -584,7 +587,7 @@ TEST_CASE("topological_sort - strongly connected component", "[algorithm][topolo // Strongly connected: 0<->1<->2<->0 Graph g({{0, 1}, {1, 0}, {1, 2}, {2, 1}, {2, 0}, {0, 2}}); std::vector sources = {0}; - std::vector order; + std::vector order; bool success = topological_sort(g, sources, std::back_inserter(order)); @@ -597,7 +600,7 @@ TEST_CASE("topological_sort - DAG with forward edges", "[algorithm][topological_ // DAG with forward edge: 0->1->2, 0->2 Graph g({{0, 1}, {1, 2}, {0, 2}}); std::vector sources = {0}; - std::vector order; + std::vector order; bool success = topological_sort(g, sources, std::back_inserter(order)); @@ -613,7 +616,7 @@ TEST_CASE("topological_sort - verify output order property", "[algorithm][topolo // Create a graph where order matters Graph g({{0, 3}, {1, 3}, {2, 3}, {3, 4}}); std::vector sources = {0, 1, 2}; - std::vector order; + std::vector order; bool success = topological_sort(g, sources, std::back_inserter(order)); @@ -621,11 +624,11 @@ TEST_CASE("topological_sort - verify output order property", "[algorithm][topolo REQUIRE(order.size() == 5); // Verify that 3 comes after 0, 1, and 2 - auto pos_0 = std::distance(order.begin(), std::find(order.begin(), order.end(), 0)); - auto pos_1 = std::distance(order.begin(), std::find(order.begin(), order.end(), 1)); - auto pos_2 = std::distance(order.begin(), std::find(order.begin(), order.end(), 2)); - auto pos_3 = std::distance(order.begin(), std::find(order.begin(), order.end(), 3)); - auto pos_4 = std::distance(order.begin(), std::find(order.begin(), order.end(), 4)); + auto pos_0 = std::distance(order.begin(), std::find(order.begin(), order.end(), static_cast(0))); + auto pos_1 = std::distance(order.begin(), std::find(order.begin(), order.end(), static_cast(1))); + auto pos_2 = std::distance(order.begin(), std::find(order.begin(), order.end(), static_cast(2))); + auto pos_3 = std::distance(order.begin(), std::find(order.begin(), order.end(), static_cast(3))); + auto pos_4 = std::distance(order.begin(), std::find(order.begin(), order.end(), static_cast(4))); REQUIRE(pos_0 < pos_3); REQUIRE(pos_1 < pos_3); @@ -714,16 +717,16 @@ TEMPLATE_TEST_CASE("topological_sort - sparse single-source DAG", SPARSE_VERTEX_TYPES) { using Graph = TestType; auto g = map_fixtures::dag_graph(); - auto source = map_fixtures::bfs_source(); + auto start_vertex = map_fixtures::bfs_source(); using vid_t = vertex_id_t; std::vector order; - bool success = topological_sort(g, source, std::back_inserter(order)); + bool success = topological_sort(g, start_vertex, std::back_inserter(order)); REQUIRE(success); REQUIRE(order.size() == 4); // root reaches all 4 vertices in dag REQUIRE(is_valid_topo_order_generic(g, order)); - REQUIRE(order.front() == source); + REQUIRE(order.front() == start_vertex); } TEMPLATE_TEST_CASE("topological_sort - sparse multi-source partial reachability", @@ -784,3 +787,4 @@ TEMPLATE_TEST_CASE("topological_sort - sparse multi-source all sources", std::set unique_verts(order.begin(), order.end()); REQUIRE(unique_verts.size() == 4); } + diff --git a/tests/algorithms/test_triangle_count.cpp b/tests/algorithms/test_triangle_count.cpp index c432f70..91fcfdd 100644 --- a/tests/algorithms/test_triangle_count.cpp +++ b/tests/algorithms/test_triangle_count.cpp @@ -6,7 +6,6 @@ #include #include #include -#include #include #include #include @@ -18,7 +17,7 @@ using namespace graph; using namespace graph::container; // Graph type with sorted edges (required for triangle_count) -using vos_void = dynamic_graph>; +using vos_void = vos_graph<>; // Undirected adjacency list (automatically handles bidirectional edges) using ual_int = undirected_adjacency_list; diff --git a/tests/common/algorithm_test_types.hpp b/tests/common/algorithm_test_types.hpp index a04e55a..f903639 100644 --- a/tests/common/algorithm_test_types.hpp +++ b/tests/common/algorithm_test_types.hpp @@ -127,9 +127,10 @@ using mofl_weighted = graph_test_types::int_ev; // Undirected Graph Types (when undirected_adjacency_list support is added) // ============================================================================= -// Placeholder for future undirected graph types -// #define ALL_UNDIRECTED_TYPES \ -// undirected_vov, undirected_dov, undirected_vol +/* Placeholder for future undirected graph types: +#define ALL_UNDIRECTED_TYPES \ + undirected_vov, undirected_dov, undirected_vol +*/ // ============================================================================= // Helper Traits for Algorithm Requirements diff --git a/tests/common/graph_fixtures.hpp b/tests/common/graph_fixtures.hpp index 74987b3..bc4f6f8 100644 --- a/tests/common/graph_fixtures.hpp +++ b/tests/common/graph_fixtures.hpp @@ -193,11 +193,11 @@ Graph star_graph_5() { // ============================================================================= // Binary Tree: Complete binary tree with 7 vertices -// 0 -// / \ -// 1 2 -// / \ / \ -// 3 4 5 6 +/* 0 + / \ + 1 2 + / \ / \ + 3 4 5 6 */ // ============================================================================= struct binary_tree_7_results { @@ -222,11 +222,11 @@ Graph binary_tree_7() { // ============================================================================= // DAG (Directed Acyclic Graph) - Simple Diamond Shape -// 0 -// / \ -// 1 2 -// \ / -// 3 +/* 0 + / \ + 1 2 + \ / + 3 */ // Useful for topological sort, critical path, etc. // ============================================================================= diff --git a/tests/common/graph_test_types.hpp b/tests/common/graph_test_types.hpp index fbee06c..ba3ccfb 100644 --- a/tests/common/graph_test_types.hpp +++ b/tests/common/graph_test_types.hpp @@ -23,7 +23,6 @@ #ifndef GRAPH_TEST_TYPES_HPP #define GRAPH_TEST_TYPES_HPP -#include #include #include #include diff --git a/tests/container/CMakeLists.txt b/tests/container/CMakeLists.txt index b88d555..73f53a4 100644 --- a/tests/container/CMakeLists.txt +++ b/tests/container/CMakeLists.txt @@ -78,4 +78,6 @@ if(MSVC) endif() # Register tests with CTest -catch_discover_tests(graph3_container_tests) +catch_discover_tests(graph3_container_tests + DISCOVERY_MODE PRE_TEST +) diff --git a/tests/container/dynamic_graph/test_dynamic_edge_comparison.cpp b/tests/container/dynamic_graph/test_dynamic_edge_comparison.cpp index 3eafa02..4932c2e 100644 --- a/tests/container/dynamic_graph/test_dynamic_edge_comparison.cpp +++ b/tests/container/dynamic_graph/test_dynamic_edge_comparison.cpp @@ -13,7 +13,6 @@ #include #include -#include #include #include #include diff --git a/tests/container/dynamic_graph/test_dynamic_graph_bidirectional.cpp b/tests/container/dynamic_graph/test_dynamic_graph_bidirectional.cpp index eabb2b9..3ba8d15 100644 --- a/tests/container/dynamic_graph/test_dynamic_graph_bidirectional.cpp +++ b/tests/container/dynamic_graph/test_dynamic_graph_bidirectional.cpp @@ -12,7 +12,6 @@ #include #include -#include #include #include #include @@ -365,7 +364,7 @@ TEST_CASE("bidir in_edges carry correct edge values", auto uid = vertex_id(g, v); for (auto ie : in_edges(g, v)) { auto sid = source_id(g, ie); - auto key = std::pair{sid, uid}; + auto key = std::pair{static_cast(sid), static_cast(uid)}; REQUIRE(expected.count(key) == 1); REQUIRE(edge_value(g, ie) == expected[key]); } @@ -675,11 +674,13 @@ TEMPLATE_TEST_CASE("bidir total in_degree equals total out_degree", TEST_CASE("bidir in_incidence view", "[dynamic_graph][bidirectional][views][in_incidence]") { auto g = make_triangle_graph(); + using id_type = graph::vertex_id_t; SECTION("in_incidence by vertex id") { // vertex 2 has in-edges from 0 and 1 std::set sources; - for (auto [sid, ie] : graph::views::in_incidence(g, uint32_t{2})) { + const id_type target_vid = 2; + for (auto [sid, ie] : graph::views::in_incidence(g, target_vid)) { sources.insert(static_cast(sid)); } REQUIRE(sources == std::set{0, 1}); @@ -687,7 +688,8 @@ TEST_CASE("bidir in_incidence view", SECTION("in_incidence with edge value function") { std::vector weights; - for (auto [sid, ie] : graph::views::in_incidence(g, uint32_t{2})) { + const id_type target_vid = 2; + for (auto [sid, ie] : graph::views::in_incidence(g, target_vid)) { weights.push_back(edge_value(g, ie)); } std::sort(weights.begin(), weights.end()); @@ -695,10 +697,8 @@ TEST_CASE("bidir in_incidence view", } SECTION("in_incidence on vertex with no in-edges") { - size_t count = 0; - for ([[maybe_unused]] auto entry : graph::views::in_incidence(g, uint32_t{0})) { - ++count; - } + const id_type target_vid = 0; + size_t count = static_cast(std::ranges::distance(graph::views::in_incidence(g, target_vid))); REQUIRE(count == 0); } } @@ -710,21 +710,21 @@ TEST_CASE("bidir in_incidence view", TEST_CASE("bidir in_neighbors view", "[dynamic_graph][bidirectional][views][in_neighbors]") { auto g = make_triangle_graph(); + using id_type = graph::vertex_id_t; SECTION("in_neighbors by vertex id") { // vertex 2 has in-neighbors 0 and 1 std::set nbrs; - for (auto [nid, nv] : graph::views::in_neighbors(g, uint32_t{2})) { + const id_type target_vid = 2; + for (auto [nid, nv] : graph::views::in_neighbors(g, target_vid)) { nbrs.insert(static_cast(nid)); } REQUIRE(nbrs == std::set{0, 1}); } SECTION("in_neighbors on vertex with no in-edges") { - size_t count = 0; - for ([[maybe_unused]] auto entry : graph::views::in_neighbors(g, uint32_t{0})) { - ++count; - } + const id_type target_vid = 0; + size_t count = static_cast(std::ranges::distance(graph::views::in_neighbors(g, target_vid))); REQUIRE(count == 0); } } @@ -736,9 +736,11 @@ TEST_CASE("bidir in_neighbors view", TEST_CASE("bidir basic_in_incidence view", "[dynamic_graph][bidirectional][views][basic_in_incidence]") { auto g = make_triangle_graph(); + using id_type = graph::vertex_id_t; std::set sources; - for (auto [sid] : graph::views::basic_in_incidence(g, uint32_t{2})) { + const id_type target_vid = 2; + for (auto [sid] : graph::views::basic_in_incidence(g, target_vid)) { sources.insert(static_cast(sid)); } REQUIRE(sources == std::set{0, 1}); @@ -747,9 +749,11 @@ TEST_CASE("bidir basic_in_incidence view", TEST_CASE("bidir basic_in_neighbors view", "[dynamic_graph][bidirectional][views][basic_in_neighbors]") { auto g = make_triangle_graph(); + using id_type = graph::vertex_id_t; std::set nbrs; - for (auto [nid] : graph::views::basic_in_neighbors(g, uint32_t{2})) { + const id_type target_vid = 2; + for (auto [nid] : graph::views::basic_in_neighbors(g, target_vid)) { nbrs.insert(static_cast(nid)); } REQUIRE(nbrs == std::set{0, 1}); diff --git a/tests/container/dynamic_graph/test_dynamic_graph_common.cpp b/tests/container/dynamic_graph/test_dynamic_graph_common.cpp index feabbdc..91e3c4e 100644 --- a/tests/container/dynamic_graph/test_dynamic_graph_common.cpp +++ b/tests/container/dynamic_graph/test_dynamic_graph_common.cpp @@ -42,7 +42,6 @@ #include #include #include -#include #include #include #include @@ -143,7 +142,7 @@ TEMPLATE_TEST_CASE("move construction", REQUIRE(g2.size() == 0); } -TEMPLATE_TEST_CASE("construction with initializer_list edges", +TEMPLATE_TEST_CASE("construction with initializer_list edge_list", "[common][construction]", (vofl_graph_traits), (vol_graph_traits), @@ -183,8 +182,8 @@ TEMPLATE_TEST_CASE("construction with edge range and load", using edge_data = copyable_edge_t; Graph g; - std::vector edges = {{0, 1}, {1, 2}, {2, 3}}; - g.load_edges(edges, std::identity{}); + std::vector edge_list = {{0, 1}, {1, 2}, {2, 3}}; + g.load_edges(edge_list, std::identity{}); REQUIRE(g.size() == 4); } @@ -351,7 +350,7 @@ TEMPLATE_TEST_CASE("default value initialization", // Vertices should be default-initialized REQUIRE(g.size() == 5); - // Access all vertices to ensure they're properly constructed + // Access all vertex_list to ensure they're properly constructed for (size_t i = 0; i < 5; ++i) { auto& v = g[i]; (void)v; // Just ensure we can access it @@ -375,10 +374,10 @@ TEMPLATE_TEST_CASE("load_edges with simple edge list", using Graph = dynamic_graph; using edge_data = copyable_edge_t; - std::vector edges = {{0, 1}, {1, 2}, {2, 0}}; + std::vector edge_list = {{0, 1}, {1, 2}, {2, 0}}; Graph g; - g.load_edges(edges, std::identity{}); + g.load_edges(edge_list, std::identity{}); REQUIRE(g.size() == 3); } @@ -396,14 +395,14 @@ TEMPLATE_TEST_CASE("load_edges with edge values", using Graph = dynamic_graph; using edge_data = copyable_edge_t; - std::vector edges = {{0, 1, 10}, {1, 2, 20}, {2, 0, 30}}; + std::vector edge_list = {{0, 1, 10}, {1, 2, 20}, {2, 0, 30}}; Graph g; - g.load_edges(edges, std::identity{}); + g.load_edges(edge_list, std::identity{}); REQUIRE(g.size() == 3); - // Verify edge values exist (iterator through edges) + // Verify edge values exist (iterator through edge_list) auto& v0 = g[0]; bool found = false; for (auto& e : v0.edges()) { @@ -428,10 +427,10 @@ TEMPLATE_TEST_CASE("load_vertices basic", using Graph = dynamic_graph; using vertex_data = copyable_vertex_t; - std::vector vertices = {{0, 100}, {1, 200}, {2, 300}}; + std::vector vertex_list = {{0, 100}, {1, 200}, {2, 300}}; Graph g; - g.load_vertices(vertices, std::identity{}); + g.load_vertices(vertex_list, std::identity{}); REQUIRE(g.size() == 3); REQUIRE(g[0].value() == 100); @@ -452,9 +451,9 @@ TEMPLATE_TEST_CASE("load_edges with empty range", using Graph = dynamic_graph; using edge_data = copyable_edge_t; - std::vector edges; + std::vector edge_list; Graph g; - g.load_edges(edges, std::identity{}); + g.load_edges(edge_list, std::identity{}); // Empty edge load may create vertex 0 REQUIRE(g.size() <= 1); @@ -473,9 +472,9 @@ TEMPLATE_TEST_CASE("load_edges auto-extends vertex count", using Graph = dynamic_graph; using edge_data = copyable_edge_t; - std::vector edges = {{0, 10}, {5, 20}}; + std::vector edge_list = {{0, 10}, {5, 20}}; Graph g; - g.load_edges(edges, std::identity{}); + g.load_edges(edge_list, std::identity{}); // Should auto-extend to include vertex 20 REQUIRE(g.size() >= 21); @@ -497,11 +496,11 @@ TEMPLATE_TEST_CASE("load_vertices then load_edges", Graph g; - std::vector vertices = {{0, 10}, {1, 20}, {2, 30}}; - g.load_vertices(vertices, std::identity{}); + std::vector vertex_list = {{0, 10}, {1, 20}, {2, 30}}; + g.load_vertices(vertex_list, std::identity{}); - std::vector edges = {{0, 1, 100}, {1, 2, 200}}; - g.load_edges(edges, std::identity{}); + std::vector edge_list = {{0, 1, 100}, {1, 2, 200}}; + g.load_edges(edge_list, std::identity{}); REQUIRE(g.size() == 3); REQUIRE(g[0].value() == 10); @@ -602,9 +601,9 @@ TEMPLATE_TEST_CASE("load with self-loops", using Graph = dynamic_graph; using edge_data = copyable_edge_t; - std::vector edges = {{0, 0}, {1, 1}, {0, 1}}; + std::vector edge_list = {{0, 0}, {1, 1}, {0, 1}}; Graph g; - g.load_edges(edges, std::identity{}); + g.load_edges(edge_list, std::identity{}); REQUIRE(g.size() == 2); @@ -619,7 +618,7 @@ TEMPLATE_TEST_CASE("load with self-loops", REQUIRE(has_self_loop); } -TEMPLATE_TEST_CASE("load vertices with non-contiguous IDs", +TEMPLATE_TEST_CASE("load vertex_list with non-contiguous IDs", "[common][load]", (vofl_graph_traits), (vol_graph_traits), @@ -632,9 +631,9 @@ TEMPLATE_TEST_CASE("load vertices with non-contiguous IDs", using Graph = dynamic_graph; Graph g; - g.resize_vertices(11); // Pre-allocate for vertices 0-10 - std::vector> vertices = {{0, 100}, {5, 500}, {10, 1000}}; - g.load_vertices(vertices, std::identity{}); + g.resize_vertices(11); // Pre-allocate for vertex_list 0-10 + std::vector> vertex_list = {{0, 100}, {5, 500}, {10, 1000}}; + g.load_vertices(vertex_list, std::identity{}); REQUIRE(g.size() == 11); // Should have indices 0-10 REQUIRE(g[0].value() == 100); @@ -642,7 +641,7 @@ TEMPLATE_TEST_CASE("load vertices with non-contiguous IDs", REQUIRE(g[10].value() == 1000); } -TEMPLATE_TEST_CASE("load vertices in reverse order", +TEMPLATE_TEST_CASE("load vertex_list in reverse order", "[common][load]", (vofl_graph_traits), (vol_graph_traits), @@ -655,8 +654,8 @@ TEMPLATE_TEST_CASE("load vertices in reverse order", using Graph = dynamic_graph; Graph g; - std::vector> vertices = {{4, 400}, {3, 300}, {2, 200}, {1, 100}, {0, 0}}; - g.load_vertices(vertices, std::identity{}); + std::vector> vertex_list = {{4, 400}, {3, 300}, {2, 200}, {1, 100}, {0, 0}}; + g.load_vertices(vertex_list, std::identity{}); REQUIRE(g.size() == 5); REQUIRE(g[0].value() == 0); @@ -680,15 +679,15 @@ TEMPLATE_TEST_CASE("vertex access by index", (dod_graph_traits)) { using Graph = dynamic_graph; - std::vector> edges = {{0, 1}}; + std::vector> edge_list = {{0, 1}}; Graph g; - g.load_edges(edges, std::identity{}); + g.load_edges(edge_list, std::identity{}); REQUIRE(g.size() == 2); auto& v0 = g[0]; auto& v1 = g[1]; - // Verify vertices are accessible + // Verify vertex_list are accessible REQUIRE(&v0 != &v1); } @@ -704,9 +703,9 @@ TEMPLATE_TEST_CASE("vertex iteration", (dod_graph_traits)) { using Graph = dynamic_graph; - std::vector> edges = {{0, 1}, {1, 2}}; + std::vector> edge_list = {{0, 1}, {1, 2}}; Graph g; - g.load_edges(edges, std::identity{}); + g.load_edges(edge_list, std::identity{}); size_t count = 0; for (auto it = g.begin(); it != g.end(); ++it) { @@ -727,9 +726,9 @@ TEMPLATE_TEST_CASE("const vertex iteration", (dod_graph_traits)) { using Graph = dynamic_graph; - std::vector> edges = {{0, 1}, {1, 2}}; + std::vector> edge_list = {{0, 1}, {1, 2}}; Graph g; - g.load_edges(edges, std::identity{}); + g.load_edges(edge_list, std::identity{}); const Graph& cg = g; size_t count = 0; @@ -739,7 +738,7 @@ TEMPLATE_TEST_CASE("const vertex iteration", REQUIRE(count == 3); } -TEMPLATE_TEST_CASE("range-based for loop on vertices", +TEMPLATE_TEST_CASE("range-based for loop on vertex_list", "[common][access]", (vofl_graph_traits), (vol_graph_traits), @@ -751,9 +750,9 @@ TEMPLATE_TEST_CASE("range-based for loop on vertices", (dod_graph_traits)) { using Graph = dynamic_graph; - std::vector> vertices = {{0, 10}, {1, 20}, {2, 30}}; + std::vector> vertex_list = {{0, 10}, {1, 20}, {2, 30}}; Graph g; - g.load_vertices(vertices, std::identity{}); + g.load_vertices(vertex_list, std::identity{}); int sum = 0; for (auto& v : g) { @@ -762,7 +761,7 @@ TEMPLATE_TEST_CASE("range-based for loop on vertices", REQUIRE(sum == 60); } -TEMPLATE_TEST_CASE("size queries on vertices", +TEMPLATE_TEST_CASE("size queries on vertex_list", "[common][access]", (vofl_graph_traits), (vol_graph_traits), @@ -777,8 +776,8 @@ TEMPLATE_TEST_CASE("size queries on vertices", Graph g; REQUIRE(g.size() == 0); - std::vector> edges = {{0, 1}, {1, 2}, {2, 3}}; - g.load_edges(edges, std::identity{}); + std::vector> edge_list = {{0, 1}, {1, 2}, {2, 3}}; + g.load_edges(edge_list, std::identity{}); REQUIRE(g.size() == 4); } @@ -795,9 +794,9 @@ TEMPLATE_TEST_CASE("single vertex access", (dod_graph_traits)) { using Graph = dynamic_graph; - std::vector> vertices = {{0, 42}}; + std::vector> vertex_list = {{0, 42}}; Graph g; - g.load_vertices(vertices, std::identity{}); + g.load_vertices(vertex_list, std::identity{}); REQUIRE(g.size() == 1); REQUIRE(g[0].value() == 42); @@ -815,13 +814,13 @@ TEMPLATE_TEST_CASE("large graph vertex access", (dod_graph_traits)) { using Graph = dynamic_graph; - std::vector> edges; + std::vector> edge_list; for (uint64_t i = 0; i < 100; ++i) { - edges.push_back({i, i + 1}); + edge_list.push_back({i, i + 1}); } Graph g; - g.load_edges(edges, std::identity{}); + g.load_edges(edge_list, std::identity{}); REQUIRE(g.size() == 101); auto& v50 = g[50]; @@ -840,9 +839,9 @@ TEMPLATE_TEST_CASE("vertex value access and modification", (dod_graph_traits)) { using Graph = dynamic_graph; - std::vector> vertices = {{0, 10}, {1, 20}}; + std::vector> vertex_list = {{0, 10}, {1, 20}}; Graph g; - g.load_vertices(vertices, std::identity{}); + g.load_vertices(vertex_list, std::identity{}); REQUIRE(g[0].value() == 10); g[0].value() = 100; @@ -878,9 +877,9 @@ TEMPLATE_TEST_CASE("vertex iterator validity", (dod_graph_traits)) { using Graph = dynamic_graph; - std::vector> edges = {{0, 1}, {1, 2}}; + std::vector> edge_list = {{0, 1}, {1, 2}}; Graph g; - g.load_edges(edges, std::identity{}); + g.load_edges(edge_list, std::identity{}); auto it1 = g.begin(); auto it2 = g.begin(); @@ -903,8 +902,8 @@ TEMPLATE_TEST_CASE("vertex access bounds checking", using Graph = dynamic_graph; Graph g; - std::vector> vertices = {{0, 10}, {1, 20}, {2, 30}}; - g.load_vertices(vertices, std::identity{}); + std::vector> vertex_list = {{0, 10}, {1, 20}, {2, 30}}; + g.load_vertices(vertex_list, std::identity{}); // Valid accesses REQUIRE(g[0].value() == 10); @@ -919,7 +918,7 @@ TEMPLATE_TEST_CASE("vertex access bounds checking", //================================================================================================== TEMPLATE_TEST_CASE("edge iteration from vertex", - "[common][edges]", + "[common][edge_list]", (vofl_graph_traits), (vol_graph_traits), (vov_graph_traits), @@ -930,9 +929,9 @@ TEMPLATE_TEST_CASE("edge iteration from vertex", (dod_graph_traits)) { using Graph = dynamic_graph; - std::vector> edges = {{0, 1}, {0, 2}, {0, 3}}; + std::vector> edge_list = {{0, 1}, {0, 2}, {0, 3}}; Graph g; - g.load_edges(edges, std::identity{}); + g.load_edges(edge_list, std::identity{}); auto& v0 = g[0]; size_t edge_count = 0; @@ -944,8 +943,8 @@ TEMPLATE_TEST_CASE("edge iteration from vertex", REQUIRE(edge_count == 3); } -TEMPLATE_TEST_CASE("empty vertex has no edges", - "[common][edges]", +TEMPLATE_TEST_CASE("empty vertex has no edge_list", + "[common][edge_list]", (vofl_graph_traits), (vol_graph_traits), (vov_graph_traits), @@ -956,9 +955,9 @@ TEMPLATE_TEST_CASE("empty vertex has no edges", (dod_graph_traits)) { using Graph = dynamic_graph; - std::vector> edges = {{0, 1}}; + std::vector> edge_list = {{0, 1}}; Graph g; - g.load_edges(edges, std::identity{}); + g.load_edges(edge_list, std::identity{}); auto& v1 = g[1]; size_t edge_count = 0; @@ -969,8 +968,8 @@ TEMPLATE_TEST_CASE("empty vertex has no edges", REQUIRE(edge_count == 0); } -TEMPLATE_TEST_CASE("parallel edges support", - "[common][edges]", +TEMPLATE_TEST_CASE("parallel edge_list support", + "[common][edge_list]", (vofl_graph_traits), (vol_graph_traits), (vov_graph_traits), @@ -981,9 +980,9 @@ TEMPLATE_TEST_CASE("parallel edges support", (dod_graph_traits)) { using Graph = dynamic_graph; - std::vector> edges = {{0, 1, 10}, {0, 1, 20}, {0, 1, 30}}; + std::vector> edge_list = {{0, 1, 10}, {0, 1, 20}, {0, 1, 30}}; Graph g; - g.load_edges(edges, std::identity{}); + g.load_edges(edge_list, std::identity{}); auto& v0 = g[0]; size_t count = 0; @@ -991,11 +990,11 @@ TEMPLATE_TEST_CASE("parallel edges support", REQUIRE(e.target_id() == 1); ++count; } - REQUIRE(count == 3); // All parallel edges exist + REQUIRE(count == 3); // All parallel edge_list exist } -TEMPLATE_TEST_CASE("edge degree queries", - "[common][edges]", +TEMPLATE_TEST_CASE("edge degree_count queries", + "[common][edge_list]", (vofl_graph_traits), (vol_graph_traits), (vov_graph_traits), @@ -1006,20 +1005,20 @@ TEMPLATE_TEST_CASE("edge degree queries", (dod_graph_traits)) { using Graph = dynamic_graph; - std::vector> edges = {{0, 1}, {0, 2}, {0, 3}, {1, 2}}; + std::vector> edge_list = {{0, 1}, {0, 2}, {0, 3}, {1, 2}}; Graph g; - g.load_edges(edges, std::identity{}); + g.load_edges(edge_list, std::identity{}); auto& v0 = g[0]; - size_t degree = static_cast(std::ranges::distance(v0.edges())); - REQUIRE(degree == 3); + size_t degree_count = static_cast(std::ranges::distance(v0.edges())); + REQUIRE(degree_count == 3); auto& v1 = g[1]; REQUIRE(static_cast(std::ranges::distance(v1.edges())) == 1); } TEMPLATE_TEST_CASE("edge empty check", - "[common][edges]", + "[common][edge_list]", (vofl_graph_traits), (vol_graph_traits), (vov_graph_traits), @@ -1030,9 +1029,9 @@ TEMPLATE_TEST_CASE("edge empty check", (dod_graph_traits)) { using Graph = dynamic_graph; - std::vector> edges = {{0, 1}}; + std::vector> edge_list = {{0, 1}}; Graph g; - g.load_edges(edges, std::identity{}); + g.load_edges(edge_list, std::identity{}); auto& v0 = g[0]; REQUIRE(v0.edges().begin() != v0.edges().end()); @@ -1042,7 +1041,7 @@ TEMPLATE_TEST_CASE("edge empty check", } TEMPLATE_TEST_CASE("bidirectional edge traversal", - "[common][edges]", + "[common][edge_list]", (vofl_graph_traits), (vol_graph_traits), (vov_graph_traits), @@ -1053,9 +1052,9 @@ TEMPLATE_TEST_CASE("bidirectional edge traversal", (dod_graph_traits)) { using Graph = dynamic_graph; - std::vector> edges = {{0, 1}, {1, 0}}; + std::vector> edge_list = {{0, 1}, {1, 0}}; Graph g; - g.load_edges(edges, std::identity{}); + g.load_edges(edge_list, std::identity{}); auto& v0 = g[0]; bool found_forward = false; @@ -1076,7 +1075,7 @@ TEMPLATE_TEST_CASE("bidirectional edge traversal", } TEMPLATE_TEST_CASE("edge target validation", - "[common][edges]", + "[common][edge_list]", (vofl_graph_traits), (vol_graph_traits), (vov_graph_traits), @@ -1087,9 +1086,9 @@ TEMPLATE_TEST_CASE("edge target validation", (dod_graph_traits)) { using Graph = dynamic_graph; - std::vector> edges = {{0, 1}, {0, 2}, {0, 3}}; + std::vector> edge_list = {{0, 1}, {0, 2}, {0, 3}}; Graph g; - g.load_edges(edges, std::identity{}); + g.load_edges(edge_list, std::identity{}); auto& v0 = g[0]; std::vector targets; @@ -1105,7 +1104,7 @@ TEMPLATE_TEST_CASE("edge target validation", } TEMPLATE_TEST_CASE("edge value iteration", - "[common][edges]", + "[common][edge_list]", (vofl_graph_traits), (vol_graph_traits), (vov_graph_traits), @@ -1116,9 +1115,9 @@ TEMPLATE_TEST_CASE("edge value iteration", (dod_graph_traits)) { using Graph = dynamic_graph; - std::vector> edges = {{0, 1, 10}, {0, 2, 20}, {0, 3, 30}}; + std::vector> edge_list = {{0, 1, 10}, {0, 2, 20}, {0, 3, 30}}; Graph g; - g.load_edges(edges, std::identity{}); + g.load_edges(edge_list, std::identity{}); auto& v0 = g[0]; int sum = 0; @@ -1129,7 +1128,7 @@ TEMPLATE_TEST_CASE("edge value iteration", } TEMPLATE_TEST_CASE("edge iterator increment", - "[common][edges]", + "[common][edge_list]", (vofl_graph_traits), (vol_graph_traits), (vov_graph_traits), @@ -1140,9 +1139,9 @@ TEMPLATE_TEST_CASE("edge iterator increment", (dod_graph_traits)) { using Graph = dynamic_graph; - std::vector> edges = {{0, 1}, {0, 2}, {0, 3}}; + std::vector> edge_list = {{0, 1}, {0, 2}, {0, 3}}; Graph g; - g.load_edges(edges, std::identity{}); + g.load_edges(edge_list, std::identity{}); auto& v0 = g[0]; auto it = v0.edges().begin(); @@ -1158,8 +1157,8 @@ TEMPLATE_TEST_CASE("edge iterator increment", REQUIRE(it == v0.edges().end()); } -TEMPLATE_TEST_CASE("high degree vertex", - "[common][edges]", +TEMPLATE_TEST_CASE("high degree_count vertex", + "[common][edge_list]", (vofl_graph_traits), (vol_graph_traits), (vov_graph_traits), @@ -1170,21 +1169,21 @@ TEMPLATE_TEST_CASE("high degree vertex", (dod_graph_traits)) { using Graph = dynamic_graph; - std::vector> edges; + std::vector> edge_list; for (uint64_t i = 1; i <= 50; ++i) { - edges.push_back({0, i}); + edge_list.push_back({0, i}); } Graph g; - g.load_edges(edges, std::identity{}); + g.load_edges(edge_list, std::identity{}); auto& v0 = g[0]; - size_t degree = static_cast(std::ranges::distance(v0.edges())); - REQUIRE(degree == 50); + size_t degree_count = static_cast(std::ranges::distance(v0.edges())); + REQUIRE(degree_count == 50); } TEMPLATE_TEST_CASE("edge range filtering", - "[common][edges]", + "[common][edge_list]", (vofl_graph_traits), (vol_graph_traits), (vov_graph_traits), @@ -1195,9 +1194,9 @@ TEMPLATE_TEST_CASE("edge range filtering", (dod_graph_traits)) { using Graph = dynamic_graph; - std::vector> edges = {{0, 1, 10}, {0, 2, 25}, {0, 3, 30}, {0, 4, 15}}; + std::vector> edge_list = {{0, 1, 10}, {0, 2, 25}, {0, 3, 30}, {0, 4, 15}}; Graph g; - g.load_edges(edges, std::identity{}); + g.load_edges(edge_list, std::identity{}); auto& v0 = g[0]; auto count = std::ranges::count_if(v0.edges(), [](const auto& e) { return e.value() >= 20; }); @@ -1205,7 +1204,7 @@ TEMPLATE_TEST_CASE("edge range filtering", } TEMPLATE_TEST_CASE("edge access from const vertex reference", - "[common][edges]", + "[common][edge_list]", (vofl_graph_traits), (vol_graph_traits), (vov_graph_traits), @@ -1216,9 +1215,9 @@ TEMPLATE_TEST_CASE("edge access from const vertex reference", (dod_graph_traits)) { using Graph = dynamic_graph; - std::vector> edges = {{0, 1, 10}, {0, 2, 20}}; + std::vector> edge_list = {{0, 1, 10}, {0, 2, 20}}; Graph g; - g.load_edges(edges, std::identity{}); + g.load_edges(edge_list, std::identity{}); const auto& v0_const = g[0]; int sum = 0; @@ -1241,8 +1240,8 @@ TEMPLATE_TEST_CASE("vertex value modification", using Graph = dynamic_graph; Graph g; - std::vector> vertices = {{0, 1.5}, {1, 2.5}}; - g.load_vertices(vertices, std::identity{}); + std::vector> vertex_list = {{0, 1.5}, {1, 2.5}}; + g.load_vertices(vertex_list, std::identity{}); g[0].value() = 3.14; REQUIRE(g[0].value() == 3.14); @@ -1279,14 +1278,14 @@ TEMPLATE_TEST_CASE("string values work correctly", Graph g("graph_value"); REQUIRE(g.graph_value() == "graph_value"); - std::vector> vertices = {{0, "v0"}, {1, "v1"}}; - g.load_vertices(vertices, std::identity{}); + std::vector> vertex_list = {{0, "v0"}, {1, "v1"}}; + g.load_vertices(vertex_list, std::identity{}); REQUIRE(g[0].value() == "v0"); REQUIRE(g[1].value() == "v1"); - std::vector> edges = {{0, 1, "e01"}}; - g.load_edges(edges, std::identity{}); + std::vector> edge_list = {{0, 1, "e01"}}; + g.load_edges(edge_list, std::identity{}); for (auto& e : g[0].edges()) { REQUIRE(e.value() == "e01"); @@ -1305,9 +1304,9 @@ TEMPLATE_TEST_CASE("edge value modification", (dod_graph_traits)) { using Graph = dynamic_graph; - std::vector> edges = {{0, 1, 10}}; + std::vector> edge_list = {{0, 1, 10}}; Graph g; - g.load_edges(edges, std::identity{}); + g.load_edges(edge_list, std::identity{}); auto& v0 = g[0]; for (auto& e : v0.edges()) { @@ -1331,9 +1330,9 @@ TEMPLATE_TEST_CASE("vertex value modification", (dod_graph_traits)) { using Graph = dynamic_graph; - std::vector> vertices = {{0, 10}, {1, 20}}; + std::vector> vertex_list = {{0, 10}, {1, 20}}; Graph g; - g.load_vertices(vertices, std::identity{}); + g.load_vertices(vertex_list, std::identity{}); g[0].value() = 100; g[1].value() = 200; @@ -1393,12 +1392,12 @@ TEMPLATE_TEST_CASE("mixed value types", Graph g(3.14); REQUIRE(g.graph_value() == 3.14); - std::vector> vertices = {{0, "vertex"}}; - g.load_vertices(vertices, std::identity{}); + std::vector> vertex_list = {{0, "vertex"}}; + g.load_vertices(vertex_list, std::identity{}); REQUIRE(g[0].value() == "vertex"); - std::vector> edges = {{0, 0, 42}}; - g.load_edges(edges, std::identity{}); + std::vector> edge_list = {{0, 0, 42}}; + g.load_edges(edge_list, std::identity{}); for (auto& e : g[0].edges()) { REQUIRE(e.value() == 42); @@ -1418,10 +1417,10 @@ TEMPLATE_TEST_CASE("const value access", using Graph = dynamic_graph; Graph g(42); - std::vector> vertices = {{0, 10}}; - g.load_vertices(vertices, std::identity{}); - std::vector> edges = {{0, 0, 5}}; - g.load_edges(edges, std::identity{}); + std::vector> vertex_list = {{0, 10}}; + g.load_vertices(vertex_list, std::identity{}); + std::vector> edge_list = {{0, 0, 5}}; + g.load_edges(edge_list, std::identity{}); const Graph& cg = g; REQUIRE(cg.graph_value() == 42); @@ -1449,14 +1448,14 @@ TEMPLATE_TEST_CASE("large graph construction", (dod_graph_traits)) { using Graph = dynamic_graph; - // Create a graph with 1000 vertices - std::vector> edges; + // Create a graph with 1000 vertex_list + std::vector> edge_list; for (uint64_t i = 0; i < 1000; ++i) { - edges.push_back({i, (i + 1) % 1000}); + edge_list.push_back({i, (i + 1) % 1000}); } Graph g; - g.load_edges(edges, std::identity{}); + g.load_edges(edge_list, std::identity{}); REQUIRE(g.size() == 1000); } @@ -1476,8 +1475,8 @@ TEMPLATE_TEST_CASE("graph size tracking", Graph g; REQUIRE(g.size() == 0); - std::vector> edges = {{0, 1}, {1, 2}}; - g.load_edges(edges, std::identity{}); + std::vector> edge_list = {{0, 1}, {1, 2}}; + g.load_edges(edge_list, std::identity{}); REQUIRE(g.size() == 3); std::vector> more_edges = {{3, 4}}; @@ -1497,9 +1496,9 @@ TEMPLATE_TEST_CASE("begin/end iteration", (dod_graph_traits)) { using Graph = dynamic_graph; - std::vector> edges = {{0, 1}, {1, 2}}; + std::vector> edge_list = {{0, 1}, {1, 2}}; Graph g; - g.load_edges(edges, std::identity{}); + g.load_edges(edge_list, std::identity{}); size_t count = 0; for (auto it = g.begin(); it != g.end(); ++it) { @@ -1520,9 +1519,9 @@ TEMPLATE_TEST_CASE("cbegin/cend const iteration", (dod_graph_traits)) { using Graph = dynamic_graph; - std::vector> edges = {{0, 1}, {1, 2}}; + std::vector> edge_list = {{0, 1}, {1, 2}}; Graph g; - g.load_edges(edges, std::identity{}); + g.load_edges(edge_list, std::identity{}); size_t count = 0; for (auto it = g.cbegin(); it != g.cend(); ++it) { @@ -1587,9 +1586,9 @@ TEMPLATE_TEST_CASE("graph iterator distance", (dod_graph_traits)) { using Graph = dynamic_graph; - std::vector> edges = {{0, 1}, {1, 2}, {2, 3}}; + std::vector> edge_list = {{0, 1}, {1, 2}, {2, 3}}; Graph g; - g.load_edges(edges, std::identity{}); + g.load_edges(edge_list, std::identity{}); auto dist = std::distance(g.begin(), g.end()); REQUIRE(static_cast(dist) == g.size()); @@ -1608,10 +1607,10 @@ TEMPLATE_TEST_CASE("copy preserves structure", using Graph = dynamic_graph; Graph g1; - std::vector> vertices = {{0, 10}, {1, 20}}; - g1.load_vertices(vertices, std::identity{}); - std::vector> edges = {{0, 1, 100}}; - g1.load_edges(edges, std::identity{}); + std::vector> vertex_list = {{0, 10}, {1, 20}}; + g1.load_vertices(vertex_list, std::identity{}); + std::vector> edge_list = {{0, 1, 100}}; + g1.load_edges(edge_list, std::identity{}); Graph g2(g1); REQUIRE(g2.size() == g1.size()); @@ -1631,11 +1630,11 @@ TEMPLATE_TEST_CASE("ranges integration", (dod_graph_traits)) { using Graph = dynamic_graph; - std::vector> edges = {{0, 1, 10}, {0, 2, 20}, {1, 2, 30}}; + std::vector> edge_list = {{0, 1, 10}, {0, 2, 20}, {1, 2, 30}}; Graph g; - g.load_edges(edges, std::identity{}); + g.load_edges(edge_list, std::identity{}); - // Use std::ranges to count edges with value >= 20 + // Use std::ranges to count edge_list with value >= 20 auto& v0 = g[0]; auto count = std::ranges::count_if(v0.edges(), [](const auto& e) { return e.value() >= 20; }); REQUIRE(count == 1); @@ -1654,13 +1653,13 @@ TEMPLATE_TEST_CASE("graph equality comparison", using Graph = dynamic_graph; Graph g1; - std::vector> vertices = {{0, 10}, {1, 20}}; - g1.load_vertices(vertices, std::identity{}); + std::vector> vertex_list = {{0, 10}, {1, 20}}; + g1.load_vertices(vertex_list, std::identity{}); Graph g2; - g2.load_vertices(vertices, std::identity{}); + g2.load_vertices(vertex_list, std::identity{}); - // Both graphs have same vertices + // Both graphs have same vertex_list REQUIRE(g1.size() == g2.size()); REQUIRE(g1[0].value() == g2[0].value()); } @@ -1678,8 +1677,8 @@ TEMPLATE_TEST_CASE("graph capacity queries", using Graph = dynamic_graph; Graph g; - std::vector> edges = {{0, 1}, {1, 2}, {2, 3}}; - g.load_edges(edges, std::identity{}); + std::vector> edge_list = {{0, 1}, {1, 2}, {2, 3}}; + g.load_edges(edge_list, std::identity{}); REQUIRE(g.size() == 4); REQUIRE(g.begin() != g.end()); @@ -1730,10 +1729,10 @@ TEMPLATE_TEST_CASE("clear graph", using Graph = dynamic_graph; Graph g; - std::vector> vertices = {{0, 10}, {1, 20}}; - g.load_vertices(vertices, std::identity{}); - std::vector> edges = {{0, 1, 100}}; - g.load_edges(edges, std::identity{}); + std::vector> vertex_list = {{0, 10}, {1, 20}}; + g.load_vertices(vertex_list, std::identity{}); + std::vector> edge_list = {{0, 1, 100}}; + g.load_edges(edge_list, std::identity{}); REQUIRE(g.size() == 2); @@ -1755,8 +1754,8 @@ TEMPLATE_TEST_CASE("resize graph", using Graph = dynamic_graph; Graph g; - std::vector> vertices = {{0, 10}, {1, 20}}; - g.load_vertices(vertices, std::identity{}); + std::vector> vertex_list = {{0, 10}, {1, 20}}; + g.load_vertices(vertex_list, std::identity{}); REQUIRE(g.size() == 2); @@ -1781,8 +1780,8 @@ TEMPLATE_TEST_CASE("repeated load operations", Graph g; for (int i = 0; i < 10; ++i) { - std::vector> edges = {{0, 1}}; - g.load_edges(edges, std::identity{}); + std::vector> edge_list = {{0, 1}}; + g.load_edges(edge_list, std::identity{}); } REQUIRE(g.size() == 2); @@ -1801,11 +1800,11 @@ TEMPLATE_TEST_CASE("large vertex count", using Graph = dynamic_graph; Graph g; - std::vector> edges; + std::vector> edge_list; for (uint64_t i = 0; i < 100; ++i) { - edges.push_back({i, i + 1}); + edge_list.push_back({i, i + 1}); } - g.load_edges(edges, std::identity{}); + g.load_edges(edge_list, std::identity{}); REQUIRE(g.size() == 101); REQUIRE(g.begin() != g.end()); @@ -1824,8 +1823,8 @@ TEMPLATE_TEST_CASE("move assignment efficiency", using Graph = dynamic_graph; Graph g1; - std::vector> vertices = {{0, "test"}}; - g1.load_vertices(vertices, std::identity{}); + std::vector> vertex_list = {{0, "test"}}; + g1.load_vertices(vertex_list, std::identity{}); Graph g2; g2 = std::move(g1); @@ -1847,13 +1846,13 @@ TEMPLATE_TEST_CASE("sparse graph memory", using Graph = dynamic_graph; Graph g; - // Create sparse graph: only edges 0->100 and 50->150 - std::vector> edges = {{0, 100}, {50, 150}}; - g.load_edges(edges, std::identity{}); + // Create sparse graph: only edge_list 0->100 and 50->150 + std::vector> edge_list = {{0, 100}, {50, 150}}; + g.load_edges(edge_list, std::identity{}); REQUIRE(g.size() == 151); - // Most vertices should have no edges + // Most vertex_list should have no edge_list size_t empty_count = 0; for (auto& v : g) { if (v.edges().begin() == v.edges().end()) { @@ -1904,8 +1903,8 @@ TEMPLATE_TEST_CASE("single vertex graph", using Graph = dynamic_graph; Graph g; - std::vector> vertices = {{0, 42}}; - g.load_vertices(vertices, std::identity{}); + std::vector> vertex_list = {{0, 42}}; + g.load_vertices(vertex_list, std::identity{}); REQUIRE(g.size() == 1); REQUIRE(g[0].value() == 42); @@ -1925,8 +1924,8 @@ TEMPLATE_TEST_CASE("only self-loops", using Graph = dynamic_graph; Graph g; - std::vector> edges = {{0, 0}, {1, 1}, {2, 2}}; - g.load_edges(edges, std::identity{}); + std::vector> edge_list = {{0, 0}, {1, 1}, {2, 2}}; + g.load_edges(edge_list, std::identity{}); REQUIRE(g.size() == 3); @@ -1941,7 +1940,7 @@ TEMPLATE_TEST_CASE("only self-loops", } } -TEMPLATE_TEST_CASE("disconnected vertices", +TEMPLATE_TEST_CASE("disconnected vertex_list", "[common][edge_case]", (vofl_graph_traits), (vol_graph_traits), @@ -1954,12 +1953,12 @@ TEMPLATE_TEST_CASE("disconnected vertices", using Graph = dynamic_graph; Graph g; - std::vector> edges = {{0, 1}, {2, 3}}; - g.load_edges(edges, std::identity{}); + std::vector> edge_list = {{0, 1}, {2, 3}}; + g.load_edges(edge_list, std::identity{}); REQUIRE(g.size() == 4); - // Vertices 1 and 2 have no outgoing edges + // Vertices 1 and 2 have no outgoing edge_list REQUIRE(g[1].edges().begin() == g[1].edges().end()); } @@ -1976,22 +1975,22 @@ TEMPLATE_TEST_CASE("complete graph small", using Graph = dynamic_graph; Graph g; - // Complete graph K4: all vertices connected to all others - std::vector> edges; + // Complete graph K4: all vertex_list connected to all others + std::vector> edge_list; for (uint64_t i = 0; i < 4; ++i) { for (uint64_t j = 0; j < 4; ++j) { if (i != j) { - edges.push_back({i, j}); + edge_list.push_back({i, j}); } } } - g.load_edges(edges, std::identity{}); + g.load_edges(edge_list, std::identity{}); REQUIRE(g.size() == 4); for (size_t i = 0; i < 4; ++i) { - size_t degree = static_cast(std::ranges::distance(g[i].edges())); - REQUIRE(degree == 3); + size_t degree_count = static_cast(std::ranges::distance(g[i].edges())); + REQUIRE(degree_count == 3); } } @@ -2009,11 +2008,11 @@ TEMPLATE_TEST_CASE("star graph", Graph g; // Star: center vertex 0 connects to all others - std::vector> edges; + std::vector> edge_list; for (uint64_t i = 1; i <= 10; ++i) { - edges.push_back({0, i}); + edge_list.push_back({0, i}); } - g.load_edges(edges, std::identity{}); + g.load_edges(edge_list, std::identity{}); size_t center_degree = static_cast(std::ranges::distance(g[0].edges())); REQUIRE(center_degree == 10); @@ -2037,18 +2036,18 @@ TEMPLATE_TEST_CASE("chain graph", using Graph = dynamic_graph; Graph g; - std::vector> edges; + std::vector> edge_list; for (uint64_t i = 0; i < 10; ++i) { - edges.push_back({i, i + 1}); + edge_list.push_back({i, i + 1}); } - g.load_edges(edges, std::identity{}); + g.load_edges(edge_list, std::identity{}); REQUIRE(g.size() == 11); // Each vertex (except last) has exactly 1 outgoing edge for (size_t i = 0; i < 10; ++i) { - size_t degree = static_cast(std::ranges::distance(g[i].edges())); - REQUIRE(degree == 1); + size_t degree_count = static_cast(std::ranges::distance(g[i].edges())); + REQUIRE(degree_count == 1); } } @@ -2065,8 +2064,8 @@ TEMPLATE_TEST_CASE("duplicate edge loading", using Graph = dynamic_graph; Graph g; - std::vector> edges = {{0, 1, 10}, {0, 1, 20}, {0, 1, 30}}; - g.load_edges(edges, std::identity{}); + std::vector> edge_list = {{0, 1, 10}, {0, 1, 20}, {0, 1, 30}}; + g.load_edges(edge_list, std::identity{}); // All duplicates should be loaded size_t count = static_cast(std::ranges::distance(g[0].edges())); @@ -2086,8 +2085,8 @@ TEMPLATE_TEST_CASE("very large vertex ID", using Graph = dynamic_graph; Graph g; - std::vector> edges = {{0, 1000}}; - g.load_edges(edges, std::identity{}); + std::vector> edge_list = {{0, 1000}}; + g.load_edges(edge_list, std::identity{}); REQUIRE(g.size() >= 1001); } @@ -2106,13 +2105,13 @@ TEMPLATE_TEST_CASE("mixed load order", Graph g; - // Load edges first - std::vector> edges = {{0, 1, 100}}; - g.load_edges(edges, std::identity{}); + // Load edge_list first + std::vector> edge_list = {{0, 1, 100}}; + g.load_edges(edge_list, std::identity{}); // Then load vertices (should overwrite defaults) - std::vector> vertices = {{0, 10}, {1, 20}}; - g.load_vertices(vertices, std::identity{}); + std::vector> vertex_list = {{0, 10}, {1, 20}}; + g.load_vertices(vertex_list, std::identity{}); REQUIRE(g[0].value() == 10); REQUIRE(g[1].value() == 20); @@ -2131,15 +2130,15 @@ TEMPLATE_TEST_CASE("cycle graph", using Graph = dynamic_graph; Graph g; - std::vector> edges = {{0, 1}, {1, 2}, {2, 3}, {3, 0}}; - g.load_edges(edges, std::identity{}); + std::vector> edge_list = {{0, 1}, {1, 2}, {2, 3}, {3, 0}}; + g.load_edges(edge_list, std::identity{}); REQUIRE(g.size() == 4); // Each vertex has exactly 1 outgoing edge for (size_t i = 0; i < 4; ++i) { - size_t degree = static_cast(std::ranges::distance(g[i].edges())); - REQUIRE(degree == 1); + size_t degree_count = static_cast(std::ranges::distance(g[i].edges())); + REQUIRE(degree_count == 1); } } @@ -2157,22 +2156,22 @@ TEMPLATE_TEST_CASE("bipartite graph", Graph g; // Bipartite: group 0,1,2 connects only to group 3,4,5 - std::vector> edges = {{0, 3}, {0, 4}, {0, 5}, {1, 3}, {1, 4}, + std::vector> edge_list = {{0, 3}, {0, 4}, {0, 5}, {1, 3}, {1, 4}, {1, 5}, {2, 3}, {2, 4}, {2, 5}}; - g.load_edges(edges, std::identity{}); + g.load_edges(edge_list, std::identity{}); REQUIRE(g.size() == 6); - // Group 1 has outgoing edges + // Group 1 has outgoing edge_list for (size_t i = 0; i < 3; ++i) { - size_t degree = static_cast(std::ranges::distance(g[i].edges())); - REQUIRE(degree == 3); + size_t degree_count = static_cast(std::ranges::distance(g[i].edges())); + REQUIRE(degree_count == 3); } - // Group 2 has no outgoing edges + // Group 2 has no outgoing edge_list for (size_t i = 3; i < 6; ++i) { - size_t degree = static_cast(std::ranges::distance(g[i].edges())); - REQUIRE(degree == 0); + size_t degree_count = static_cast(std::ranges::distance(g[i].edges())); + REQUIRE(degree_count == 0); } } @@ -2205,8 +2204,8 @@ TEMPLATE_TEST_CASE("zero vertex ID", using Graph = dynamic_graph; Graph g; - std::vector> vertices = {{0, 42}}; - g.load_vertices(vertices, std::identity{}); + std::vector> vertex_list = {{0, 42}}; + g.load_vertices(vertex_list, std::identity{}); REQUIRE(g.size() >= 1); REQUIRE(g[0].value() == 42); @@ -2225,9 +2224,9 @@ TEMPLATE_TEST_CASE("maximum vertex ID handling", using Graph = dynamic_graph; Graph g; - g.resize_vertices(1001); // Pre-allocate for vertices 0-1000 - std::vector> vertices = {{0, 1}, {1000, 1000}}; - g.load_vertices(vertices, std::identity{}); + g.resize_vertices(1001); // Pre-allocate for vertex_list 0-1000 + std::vector> vertex_list = {{0, 1}, {1000, 1000}}; + g.load_vertices(vertex_list, std::identity{}); REQUIRE(g.size() == 1001); REQUIRE(g[1000].value() == 1000); @@ -2245,17 +2244,14 @@ TEMPLATE_TEST_CASE("unordered edge loading", (dod_graph_traits)) { using Graph = dynamic_graph; - std::vector> edges = {{5, 2, 52}, {0, 3, 3}, {2, 1, 21}, {3, 5, 35}}; + std::vector> edge_list = {{5, 2, 52}, {0, 3, 3}, {2, 1, 21}, {3, 5, 35}}; Graph g; - g.load_edges(edges, std::identity{}); + g.load_edges(edge_list, std::identity{}); REQUIRE(g.size() == 6); - // Verify vertex 5 exists and has edges + // Verify vertex 5 exists and has edge_list auto& v5 = g[5]; - size_t edge_count = 0; - for (auto& e : v5.edges()) { - ++edge_count; - } + size_t edge_count = static_cast(std::ranges::distance(v5.edges())); REQUIRE(edge_count >= 1); } @@ -2276,8 +2272,8 @@ TEMPLATE_TEST_CASE("vertex iterator pre-increment", using Graph = dynamic_graph; Graph g; - std::vector> edges = {{0, 1}, {1, 2}}; - g.load_edges(edges, std::identity{}); + std::vector> edge_list = {{0, 1}, {1, 2}}; + g.load_edges(edge_list, std::identity{}); auto it = g.begin(); auto it2 = ++it; @@ -2298,8 +2294,8 @@ TEMPLATE_TEST_CASE("edge iterator comparison", using Graph = dynamic_graph; Graph g; - std::vector> edges = {{0, 1}, {0, 2}}; - g.load_edges(edges, std::identity{}); + std::vector> edge_list = {{0, 1}, {0, 2}}; + g.load_edges(edge_list, std::identity{}); auto& v0 = g[0]; auto it1 = v0.edges().begin(); @@ -2310,7 +2306,7 @@ TEMPLATE_TEST_CASE("edge iterator comparison", REQUIRE(it1 != it2); } -TEMPLATE_TEST_CASE("ranges filter edges", +TEMPLATE_TEST_CASE("ranges filter edge_list", "[common][iterators]", (vofl_graph_traits), (vol_graph_traits), @@ -2323,8 +2319,8 @@ TEMPLATE_TEST_CASE("ranges filter edges", using Graph = dynamic_graph; Graph g; - std::vector> edges = {{0, 1, 5}, {0, 2, 15}, {0, 3, 25}, {0, 4, 35}}; - g.load_edges(edges, std::identity{}); + std::vector> edge_list = {{0, 1, 5}, {0, 2, 15}, {0, 3, 25}, {0, 4, 35}}; + g.load_edges(edge_list, std::identity{}); auto& v0 = g[0]; auto filtered = v0.edges() | std::views::filter([](const auto& e) { return e.value() > 10; }); @@ -2333,7 +2329,7 @@ TEMPLATE_TEST_CASE("ranges filter edges", REQUIRE(count == 3); } -TEMPLATE_TEST_CASE("ranges transform edges", +TEMPLATE_TEST_CASE("ranges transform edge_list", "[common][iterators]", (vofl_graph_traits), (vol_graph_traits), @@ -2346,8 +2342,8 @@ TEMPLATE_TEST_CASE("ranges transform edges", using Graph = dynamic_graph; Graph g; - std::vector> edges = {{0, 1, 10}, {0, 2, 20}, {0, 3, 30}}; - g.load_edges(edges, std::identity{}); + std::vector> edge_list = {{0, 1, 10}, {0, 2, 20}, {0, 3, 30}}; + g.load_edges(edge_list, std::identity{}); auto& v0 = g[0]; auto transformed = v0.edges() | std::views::transform([](const auto& e) { return e.value() * 2; }); @@ -2372,8 +2368,8 @@ TEMPLATE_TEST_CASE("ranges accumulate edge values", using Graph = dynamic_graph; Graph g; - std::vector> edges = {{0, 1, 10}, {0, 2, 20}, {0, 3, 30}}; - g.load_edges(edges, std::identity{}); + std::vector> edge_list = {{0, 1, 10}, {0, 2, 20}, {0, 3, 30}}; + g.load_edges(edge_list, std::identity{}); auto& v0 = g[0]; int sum = 0; @@ -2396,8 +2392,8 @@ TEMPLATE_TEST_CASE("ranges find edge", using Graph = dynamic_graph; Graph g; - std::vector> edges = {{0, 1, 10}, {0, 2, 20}, {0, 3, 30}}; - g.load_edges(edges, std::identity{}); + std::vector> edge_list = {{0, 1, 10}, {0, 2, 20}, {0, 3, 30}}; + g.load_edges(edge_list, std::identity{}); auto& v0 = g[0]; auto it = std::ranges::find_if(v0.edges(), [](const auto& e) { return e.value() == 20; }); @@ -2419,8 +2415,8 @@ TEMPLATE_TEST_CASE("ranges all_of edge predicate", using Graph = dynamic_graph; Graph g; - std::vector> edges = {{0, 1, 10}, {0, 2, 20}, {0, 3, 30}}; - g.load_edges(edges, std::identity{}); + std::vector> edge_list = {{0, 1, 10}, {0, 2, 20}, {0, 3, 30}}; + g.load_edges(edge_list, std::identity{}); auto& v0 = g[0]; bool all_positive = std::ranges::all_of(v0.edges(), [](const auto& e) { return e.value() > 0; }); @@ -2441,8 +2437,8 @@ TEMPLATE_TEST_CASE("ranges any_of edge predicate", using Graph = dynamic_graph; Graph g; - std::vector> edges = {{0, 1, 5}, {0, 2, 15}, {0, 3, 25}}; - g.load_edges(edges, std::identity{}); + std::vector> edge_list = {{0, 1, 5}, {0, 2, 15}, {0, 3, 25}}; + g.load_edges(edge_list, std::identity{}); auto& v0 = g[0]; bool has_large = std::ranges::any_of(v0.edges(), [](const auto& e) { return e.value() > 20; }); @@ -2468,16 +2464,16 @@ TEMPLATE_TEST_CASE("build graph incrementally", Graph g; - // Step 1: Add vertices - std::vector> vertices = {{0, 10}, {1, 20}, {2, 30}}; - g.load_vertices(vertices, std::identity{}); + // Step 1: Add vertex_list + std::vector> vertex_list = {{0, 10}, {1, 20}, {2, 30}}; + g.load_vertices(vertex_list, std::identity{}); REQUIRE(g.size() == 3); - // Step 2: Add edges + // Step 2: Add edge_list std::vector> edges1 = {{0, 1, 100}}; g.load_edges(edges1, std::identity{}); - // Step 3: Add more edges + // Step 3: Add more edge_list std::vector> edges2 = {{1, 2, 200}}; g.load_edges(edges2, std::identity{}); @@ -2500,10 +2496,10 @@ TEMPLATE_TEST_CASE("modify and query", using Graph = dynamic_graph; Graph g; - std::vector> vertices = {{0, 10}, {1, 20}}; - g.load_vertices(vertices, std::identity{}); - std::vector> edges = {{0, 1, 100}}; - g.load_edges(edges, std::identity{}); + std::vector> vertex_list = {{0, 10}, {1, 20}}; + g.load_vertices(vertex_list, std::identity{}); + std::vector> edge_list = {{0, 1, 100}}; + g.load_edges(edge_list, std::identity{}); // Modify g[0].value() = 99; @@ -2531,8 +2527,8 @@ TEMPLATE_TEST_CASE("copy and modify independently", using Graph = dynamic_graph; Graph g1; - std::vector> vertices = {{0, 10}}; - g1.load_vertices(vertices, std::identity{}); + std::vector> vertex_list = {{0, 10}}; + g1.load_vertices(vertex_list, std::identity{}); Graph g2(g1); @@ -2634,11 +2630,11 @@ TEMPLATE_TEST_CASE("complex graph construction", Graph g(3.14159); - std::vector> vertices = {{0, "Alice"}, {1, "Bob"}, {2, "Charlie"}}; - g.load_vertices(vertices, std::identity{}); + std::vector> vertex_list = {{0, "Alice"}, {1, "Bob"}, {2, "Charlie"}}; + g.load_vertices(vertex_list, std::identity{}); - std::vector> edges = {{0, 1, 10}, {1, 2, 20}, {2, 0, 30}}; - g.load_edges(edges, std::identity{}); + std::vector> edge_list = {{0, 1, 10}, {1, 2, 20}, {2, 0, 30}}; + g.load_edges(edge_list, std::identity{}); REQUIRE(g.graph_value() == 3.14159); REQUIRE(g.size() == 3); @@ -2667,15 +2663,15 @@ TEMPLATE_TEST_CASE("multi-component graph workflow", using Graph = dynamic_graph; Graph g; - g.resize_vertices(8); // Pre-allocate space for all vertices + g.resize_vertices(8); // Pre-allocate space for all vertex_list - // Component 1: vertices 0-2 + // Component 1: vertex_list 0-2 std::vector> comp1 = {{0, 10}, {1, 20}, {2, 30}}; g.load_vertices(comp1, std::identity{}); std::vector> edges1 = {{0, 1}, {1, 2}}; g.load_edges(edges1, std::identity{}); - // Component 2: vertices 5-7 (disconnected from component 1) + // Component 2: vertex_list 5-7 (disconnected from component 1) std::vector> comp2 = {{5, 50}, {6, 60}, {7, 70}}; g.load_vertices(comp2, std::identity{}); std::vector> edges2 = {{5, 6}, {6, 7}}; @@ -2685,7 +2681,7 @@ TEMPLATE_TEST_CASE("multi-component graph workflow", REQUIRE(g[0].value() == 10); REQUIRE(g[5].value() == 50); - // Vertices 3 and 4 exist but have no edges + // Vertices 3 and 4 exist but have no edge_list auto& v3 = g[3]; REQUIRE(v3.edges().begin() == v3.edges().end()); auto& v4 = g[4]; diff --git a/tests/container/dynamic_graph/test_dynamic_graph_conversions.cpp b/tests/container/dynamic_graph/test_dynamic_graph_conversions.cpp index bcb7669..a4609bb 100644 --- a/tests/container/dynamic_graph/test_dynamic_graph_conversions.cpp +++ b/tests/container/dynamic_graph/test_dynamic_graph_conversions.cpp @@ -1,6 +1,5 @@ #include #include -#include #include #include #include @@ -15,12 +14,12 @@ using namespace graph::adj_list; using namespace graph::container; // Graph type aliases -using vov_uint = dynamic_graph>; +using vov_uint = vov_graph; using mos_string = - dynamic_graph>; -using vov_int = dynamic_graph>; + mos_graph; +using vov_int = vov_graph; using dofl_uint = - dynamic_graph>; + dofl_graph; // ID mapper class: converts IDs from one type to another template @@ -67,21 +66,21 @@ class id_mapper { // Helper: Convert graph with ID mapping template -TargetGraph convert_graph(const SourceGraph& source, const id_mapper& mapper) { +TargetGraph convert_graph(const SourceGraph& src_graph, const id_mapper& mapper) { std::vector> edge_list; std::vector> vertex_list; // Add all vertices (even isolated ones) - for (auto&& u : vertices(source)) { - auto uid = vertex_id(source, u); + for (auto&& u : vertices(src_graph)) { + auto uid = vertex_id(src_graph, u); vertex_list.push_back({.id = mapper.to(uid)}); } // Add all edges - for (auto&& u : vertices(source)) { - auto uid = vertex_id(source, u); - for (auto&& e : edges(source, u)) { - auto vid = target_id(source, e); + for (auto&& u : vertices(src_graph)) { + auto uid = vertex_id(src_graph, u); + for (auto&& e : edges(src_graph, u)) { + auto vid = target_id(src_graph, e); edge_list.push_back({.source_id = mapper.to(uid), .target_id = mapper.to(vid)}); } } diff --git a/tests/container/dynamic_graph/test_dynamic_graph_cpo_edge_map.cpp b/tests/container/dynamic_graph/test_dynamic_graph_cpo_edge_map.cpp index ba3d5ec..c35a1d8 100644 --- a/tests/container/dynamic_graph/test_dynamic_graph_cpo_edge_map.cpp +++ b/tests/container/dynamic_graph/test_dynamic_graph_cpo_edge_map.cpp @@ -265,7 +265,7 @@ TEMPLATE_TEST_CASE("edge_map CPO vertex_id(g, u)", "[dynamic_graph][cpo][vertex_ std::vector ids; for (auto v : vertices(g)) { - ids.push_back(vertex_id(g, v)); + ids.push_back(static_cast(vertex_id(g, v))); } std::ranges::sort(ids); diff --git a/tests/container/dynamic_graph/test_dynamic_graph_cpo_forward_list.cpp b/tests/container/dynamic_graph/test_dynamic_graph_cpo_forward_list.cpp index 8322799..a829856 100644 --- a/tests/container/dynamic_graph/test_dynamic_graph_cpo_forward_list.cpp +++ b/tests/container/dynamic_graph/test_dynamic_graph_cpo_forward_list.cpp @@ -603,7 +603,6 @@ TEMPLATE_TEST_CASE("forward_list CPO edges(g, uid)", "[dynamic_graph][cpo][edges } SECTION("with edge values") { - using Graph_int_ev = typename Types::int_ev; Graph_int_ev g; g.resize_vertices(3); @@ -644,7 +643,6 @@ TEMPLATE_TEST_CASE("forward_list CPO edges(g, uid)", "[dynamic_graph][cpo][edges } SECTION("with parallel edges") { - using Graph_int_ev = typename Types::int_ev; Graph_int_ev g; g.resize_vertices(3); @@ -667,7 +665,6 @@ TEMPLATE_TEST_CASE("forward_list CPO edges(g, uid)", "[dynamic_graph][cpo][edges } SECTION("consistency with edges(g, u)") { - using Graph_int_ev = typename Types::int_ev; Graph_int_ev g; g.resize_vertices(4); diff --git a/tests/container/dynamic_graph/test_dynamic_graph_cpo_random_access.cpp b/tests/container/dynamic_graph/test_dynamic_graph_cpo_random_access.cpp index 00385c9..2b881bf 100644 --- a/tests/container/dynamic_graph/test_dynamic_graph_cpo_random_access.cpp +++ b/tests/container/dynamic_graph/test_dynamic_graph_cpo_random_access.cpp @@ -740,7 +740,6 @@ TEMPLATE_TEST_CASE("random_access CPO edges(g, uid)", } SECTION("with edge values") { - using Graph_int_ev = typename Types::int_ev; Graph_int_ev g; g.resize_vertices(3); @@ -780,7 +779,6 @@ TEMPLATE_TEST_CASE("random_access CPO edges(g, uid)", } SECTION("with parallel edges") { - using Graph_int_ev = typename Types::int_ev; Graph_int_ev g; g.resize_vertices(3); @@ -803,7 +801,6 @@ TEMPLATE_TEST_CASE("random_access CPO edges(g, uid)", } SECTION("consistency with edges(g, u)") { - using Graph_int_ev = typename Types::int_ev; Graph_int_ev g; g.resize_vertices(4); diff --git a/tests/container/dynamic_graph/test_dynamic_graph_cpo_sorted.cpp b/tests/container/dynamic_graph/test_dynamic_graph_cpo_sorted.cpp index aa45c23..d05ae65 100644 --- a/tests/container/dynamic_graph/test_dynamic_graph_cpo_sorted.cpp +++ b/tests/container/dynamic_graph/test_dynamic_graph_cpo_sorted.cpp @@ -674,7 +674,6 @@ TEMPLATE_TEST_CASE("sorted CPO edges(g, uid)", "[dynamic_graph][cpo][edges]", vo } SECTION("with edge values") { - using Graph_int_ev = typename Types::int_ev; Graph_int_ev g; g.resize_vertices(3); @@ -714,7 +713,6 @@ TEMPLATE_TEST_CASE("sorted CPO edges(g, uid)", "[dynamic_graph][cpo][edges]", vo } SECTION("with parallel edges") { - using Graph_int_ev = typename Types::int_ev; Graph_int_ev g; g.resize_vertices(3); @@ -735,7 +733,6 @@ TEMPLATE_TEST_CASE("sorted CPO edges(g, uid)", "[dynamic_graph][cpo][edges]", vo } SECTION("consistency with edges(g, u)") { - using Graph_int_ev = typename Types::int_ev; Graph_int_ev g; g.resize_vertices(4); diff --git a/tests/container/dynamic_graph/test_dynamic_graph_cpo_unordered.cpp b/tests/container/dynamic_graph/test_dynamic_graph_cpo_unordered.cpp index 5e4f433..35c70d2 100644 --- a/tests/container/dynamic_graph/test_dynamic_graph_cpo_unordered.cpp +++ b/tests/container/dynamic_graph/test_dynamic_graph_cpo_unordered.cpp @@ -680,7 +680,6 @@ TEMPLATE_TEST_CASE("unordered CPO edges(g, uid)", "[dynamic_graph][cpo][edges]", } SECTION("with edge values") { - using Graph_int_ev = typename Types::int_ev; Graph_int_ev g; g.resize_vertices(3); @@ -722,7 +721,6 @@ TEMPLATE_TEST_CASE("unordered CPO edges(g, uid)", "[dynamic_graph][cpo][edges]", } SECTION("with parallel edges") { - using Graph_int_ev = typename Types::int_ev; Graph_int_ev g; g.resize_vertices(3); @@ -743,7 +741,6 @@ TEMPLATE_TEST_CASE("unordered CPO edges(g, uid)", "[dynamic_graph][cpo][edges]", } SECTION("consistency with edges(g, u)") { - using Graph_int_ev = typename Types::int_ev; Graph_int_ev g; g.resize_vertices(4); @@ -1152,7 +1149,7 @@ TEMPLATE_TEST_CASE("unordered CPO target(g, uv)", "[dynamic_graph][cpo][target]" std::vector targets; for (auto uv : edge_view) { auto target_vertex = target(g, uv); - targets.push_back(vertex_id(g, target_vertex)); + targets.push_back(static_cast(vertex_id(g, target_vertex))); } std::ranges::sort(targets); REQUIRE(targets.size() == 2); @@ -1222,7 +1219,7 @@ TEMPLATE_TEST_CASE("unordered CPO target(g, uv)", "[dynamic_graph][cpo][target]" // Unordered: collect targets std::vector targets; for (auto uv : edge_view) { - targets.push_back(vertex_id(g, target(g, uv))); + targets.push_back(static_cast(vertex_id(g, target(g, uv)))); } std::ranges::sort(targets); REQUIRE(targets.size() == 2); diff --git a/tests/container/dynamic_graph/test_dynamic_graph_dod.cpp b/tests/container/dynamic_graph/test_dynamic_graph_dod.cpp index c5a8fab..cb30c4c 100644 --- a/tests/container/dynamic_graph/test_dynamic_graph_dod.cpp +++ b/tests/container/dynamic_graph/test_dynamic_graph_dod.cpp @@ -19,7 +19,6 @@ #include #include #include -#include #include #include #include @@ -30,24 +29,14 @@ using namespace graph::container; // Type aliases for common test configurations -using dod_void_void_void = - dynamic_graph>; -using dod_int_void_void = - dynamic_graph>; -using dod_void_int_void = - dynamic_graph>; -using dod_int_int_void = - dynamic_graph>; -using dod_void_void_int = - dynamic_graph>; -using dod_int_int_int = dynamic_graph>; - -using dod_string_string_string = - dynamic_graph>; +using dod_void_void_void = dod_graph<>; +using dod_int_void_void = dod_graph; +using dod_void_int_void = dod_graph; +using dod_int_int_void = dod_graph; +using dod_void_void_int = dod_graph; +using dod_int_int_int = dod_graph; + +using dod_string_string_string = dod_graph; //================================================================================================== @@ -359,19 +348,19 @@ TEST_CASE("dod empty graph edge cases", "[dod][edge_cases]") { TEST_CASE("dod value types", "[dod][value_types]") { SECTION("with void edge value") { - using graph_t = dynamic_graph>; + using graph_t = dod_graph; graph_t g(100); REQUIRE(g.graph_value() == 100); } SECTION("with void vertex value") { - using graph_t = dynamic_graph>; + using graph_t = dod_graph; graph_t g(100); REQUIRE(g.graph_value() == 100); } SECTION("with void graph value") { - using graph_t = dynamic_graph>; + using graph_t = dod_graph; graph_t g; REQUIRE(g.size() == 0); } @@ -402,19 +391,19 @@ TEST_CASE("dod value types", "[dod][value_types]") { } SECTION("with string edge value type") { - using graph_t = dynamic_graph>; + using graph_t = dod_graph; graph_t g; REQUIRE(g.size() == 0); } SECTION("with string vertex value type") { - using graph_t = dynamic_graph>; + using graph_t = dod_graph; graph_t g; REQUIRE(g.size() == 0); } SECTION("with string graph value type") { - using graph_t = dynamic_graph>; + using graph_t = dod_graph; graph_t g(std::string("test")); REQUIRE(g.graph_value() == "test"); } @@ -432,32 +421,32 @@ TEST_CASE("dod value types", "[dod][value_types]") { TEST_CASE("dod vertex ID types", "[dod][vertex_id]") { SECTION("with uint32_t vertex id") { using graph_t = - dynamic_graph>; + dod_graph; graph_t g; REQUIRE(g.size() == 0); } SECTION("with uint64_t vertex id") { using graph_t = - dynamic_graph>; + dod_graph; graph_t g; REQUIRE(g.size() == 0); } SECTION("with int32_t vertex id") { - using graph_t = dynamic_graph>; + using graph_t = dod_graph; graph_t g; REQUIRE(g.size() == 0); } SECTION("with int8_t vertex id") { - using graph_t = dynamic_graph>; + using graph_t = dod_graph; graph_t g; REQUIRE(g.size() == 0); } SECTION("with int vertex id") { - using graph_t = dynamic_graph>; + using graph_t = dod_graph; graph_t g; REQUIRE(g.size() == 0); } @@ -874,7 +863,7 @@ TEST_CASE("dod load_vertices", "[dynamic_graph][dod][load_vertices]") { } SECTION("with custom projection from struct") { - using G2 = dynamic_graph>; + using G2 = dod_graph; using vertex_data2 = copyable_vertex_t; struct Person { @@ -1011,7 +1000,7 @@ TEST_CASE("dod load_edges", "[dynamic_graph][dod][load_edges]") { } SECTION("with custom projection") { - using G2 = dynamic_graph>; + using G2 = dod_graph; using vertex_data2 = copyable_vertex_t; using edge_data2 = copyable_edge_t; diff --git a/tests/container/dynamic_graph/test_dynamic_graph_dofl.cpp b/tests/container/dynamic_graph/test_dynamic_graph_dofl.cpp index 75d8b2c..3820e3d 100644 --- a/tests/container/dynamic_graph/test_dynamic_graph_dofl.cpp +++ b/tests/container/dynamic_graph/test_dynamic_graph_dofl.cpp @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include @@ -22,17 +21,17 @@ using namespace graph::container; // Type aliases for common test configurations using dofl_void_void_void = - dynamic_graph>; + dofl_graph; using dofl_int_void_void = - dynamic_graph>; + dofl_graph; using dofl_void_int_void = - dynamic_graph>; + dofl_graph; using dofl_int_int_void = - dynamic_graph>; + dofl_graph; using dofl_void_void_int = - dynamic_graph>; + dofl_graph; using dofl_int_int_int = - dynamic_graph>; + dofl_graph; using dofl_string_string_string = dynamic_graph>; + using graph_t = dofl_graph; graph_t g(100); REQUIRE(g.graph_value() == 100); } SECTION("with void vertex value") { - using graph_t = dynamic_graph>; + using graph_t = dofl_graph; graph_t g(100); REQUIRE(g.graph_value() == 100); } SECTION("with void graph value") { - using graph_t = dynamic_graph>; + using graph_t = dofl_graph; graph_t g; REQUIRE(g.size() == 0); } @@ -523,19 +522,19 @@ TEST_CASE("dofl value_types", "[dynamic_graph][dofl][value_types]") { } SECTION("with string edge value type") { - using graph_t = dynamic_graph>; + using graph_t = dofl_graph; graph_t g; REQUIRE(g.size() == 0); } SECTION("with string vertex value type") { - using graph_t = dynamic_graph>; + using graph_t = dofl_graph; graph_t g; REQUIRE(g.size() == 0); } SECTION("with string graph value type") { - using graph_t = dynamic_graph>; + using graph_t = dofl_graph; graph_t g(std::string("test")); REQUIRE(g.graph_value() == "test"); } @@ -553,33 +552,33 @@ TEST_CASE("dofl value_types", "[dynamic_graph][dofl][value_types]") { TEST_CASE("dofl vertex_id", "[dynamic_graph][dofl][vertex_id]") { SECTION("with uint32_t vertex id") { using graph_t = - dynamic_graph>; + dofl_graph; graph_t g; REQUIRE(g.size() == 0); } SECTION("with uint64_t vertex id") { using graph_t = - dynamic_graph>; + dofl_graph; graph_t g; REQUIRE(g.size() == 0); } SECTION("with int32_t vertex id") { using graph_t = - dynamic_graph>; + dofl_graph; graph_t g; REQUIRE(g.size() == 0); } SECTION("with int8_t vertex id") { - using graph_t = dynamic_graph>; + using graph_t = dofl_graph; graph_t g; REQUIRE(g.size() == 0); } SECTION("with int vertex id") { - using graph_t = dynamic_graph>; + using graph_t = dofl_graph; graph_t g; REQUIRE(g.size() == 0); } @@ -995,7 +994,7 @@ TEST_CASE("dofl load_vertices", "[dynamic_graph][dofl][load_vertices]") { } SECTION("custom projection - load with projection from struct") { - using G = dynamic_graph>; + using G = dofl_graph; using vertex_data = copyable_vertex_t; struct Person { uint32_t id; @@ -1140,7 +1139,7 @@ TEST_CASE("dofl load_edges", "[dynamic_graph][dofl][load_edges]") { } SECTION("custom projection - load with projection from custom struct") { - using G = dynamic_graph>; + using G = dofl_graph; using vertex_data = copyable_vertex_t; using edge_data = copyable_edge_t; struct Edge { diff --git a/tests/container/dynamic_graph/test_dynamic_graph_dol.cpp b/tests/container/dynamic_graph/test_dynamic_graph_dol.cpp index 1f59763..7d12a85 100644 --- a/tests/container/dynamic_graph/test_dynamic_graph_dol.cpp +++ b/tests/container/dynamic_graph/test_dynamic_graph_dol.cpp @@ -12,7 +12,6 @@ #include #include #include -#include #include #include #include @@ -24,16 +23,16 @@ using namespace graph::container; // Type aliases for common test configurations using dol_void_void_void = - dynamic_graph>; + dol_graph; using dol_int_void_void = - dynamic_graph>; + dol_graph; using dol_void_int_void = - dynamic_graph>; + dol_graph; using dol_int_int_void = - dynamic_graph>; + dol_graph; using dol_void_void_int = - dynamic_graph>; -using dol_int_int_int = dynamic_graph>; + dol_graph; +using dol_int_int_int = dol_graph; using dol_string_string_string = dynamic_graph>; + using graph_t = dol_graph; graph_t g(100); REQUIRE(g.graph_value() == 100); } SECTION("with void vertex value") { - using graph_t = dynamic_graph>; + using graph_t = dol_graph; graph_t g(100); REQUIRE(g.graph_value() == 100); } SECTION("with void graph value") { - using graph_t = dynamic_graph>; + using graph_t = dol_graph; graph_t g; REQUIRE(g.size() == 0); } @@ -395,19 +394,19 @@ TEST_CASE("dol value types", "[dol][value_types]") { } SECTION("with string edge value type") { - using graph_t = dynamic_graph>; + using graph_t = dol_graph; graph_t g; REQUIRE(g.size() == 0); } SECTION("with string vertex value type") { - using graph_t = dynamic_graph>; + using graph_t = dol_graph; graph_t g; REQUIRE(g.size() == 0); } SECTION("with string graph value type") { - using graph_t = dynamic_graph>; + using graph_t = dol_graph; graph_t g(std::string("test")); REQUIRE(g.graph_value() == "test"); } @@ -425,32 +424,32 @@ TEST_CASE("dol value types", "[dol][value_types]") { TEST_CASE("dol vertex ID types", "[dol][vertex_id]") { SECTION("with uint32_t vertex id") { using graph_t = - dynamic_graph>; + dol_graph; graph_t g; REQUIRE(g.size() == 0); } SECTION("with uint64_t vertex id") { using graph_t = - dynamic_graph>; + dol_graph; graph_t g; REQUIRE(g.size() == 0); } SECTION("with int32_t vertex id") { - using graph_t = dynamic_graph>; + using graph_t = dol_graph; graph_t g; REQUIRE(g.size() == 0); } SECTION("with int8_t vertex id") { - using graph_t = dynamic_graph>; + using graph_t = dol_graph; graph_t g; REQUIRE(g.size() == 0); } SECTION("with int vertex id") { - using graph_t = dynamic_graph>; + using graph_t = dol_graph; graph_t g; REQUIRE(g.size() == 0); } @@ -869,7 +868,7 @@ TEST_CASE("dol load_vertices", "[dynamic_graph][dol][load_vertices]") { } SECTION("load with custom projection from struct") { - using G2 = dynamic_graph>; + using G2 = dol_graph; using vertex_data2 = copyable_vertex_t; struct Person { @@ -1003,7 +1002,7 @@ TEST_CASE("dol load_edges", "[dynamic_graph][dol][load_edges]") { } SECTION("load with custom projection from struct") { - using G3 = dynamic_graph>; + using G3 = dol_graph; using vertex_data3 = copyable_vertex_t; using edge_data3 = copyable_edge_t; diff --git a/tests/container/dynamic_graph/test_dynamic_graph_dos.cpp b/tests/container/dynamic_graph/test_dynamic_graph_dos.cpp index 885c510..4119c6a 100644 --- a/tests/container/dynamic_graph/test_dynamic_graph_dos.cpp +++ b/tests/container/dynamic_graph/test_dynamic_graph_dos.cpp @@ -16,7 +16,6 @@ #include #include #include -#include #include #include #include @@ -28,16 +27,16 @@ using namespace graph::container; // Type aliases for common test configurations using dos_void_void_void = - dynamic_graph>; + dos_graph; using dos_int_void_void = - dynamic_graph>; + dos_graph; using dos_void_int_void = - dynamic_graph>; + dos_graph; using dos_int_int_void = - dynamic_graph>; + dos_graph; using dos_void_void_int = - dynamic_graph>; -using dos_int_int_int = dynamic_graph>; + dos_graph; +using dos_int_int_int = dos_graph; using dos_string_string_string = dynamic_graph #include #include -#include #include #include #include @@ -32,17 +31,17 @@ using namespace graph::container; // Type aliases for common test configurations using dous_void_void_void = - dynamic_graph>; + dous_graph; using dous_int_void_void = - dynamic_graph>; + dous_graph; using dous_void_int_void = - dynamic_graph>; + dous_graph; using dous_int_int_void = - dynamic_graph>; + dous_graph; using dous_void_void_int = - dynamic_graph>; + dous_graph; using dous_int_int_int = - dynamic_graph>; + dous_graph; using dous_string_string_string = dynamic_graph #include #include -#include #include #include #include @@ -26,16 +25,16 @@ using namespace graph::container; // Type aliases for common test configurations using dov_void_void_void = - dynamic_graph>; + dov_graph; using dov_int_void_void = - dynamic_graph>; + dov_graph; using dov_void_int_void = - dynamic_graph>; + dov_graph; using dov_int_int_void = - dynamic_graph>; + dov_graph; using dov_void_void_int = - dynamic_graph>; -using dov_int_int_int = dynamic_graph>; + dov_graph; +using dov_int_int_int = dov_graph; using dov_string_string_string = dynamic_graph>; + using graph_t = dov_graph; graph_t g(100); REQUIRE(g.graph_value() == 100); } SECTION("with void vertex value") { - using graph_t = dynamic_graph>; + using graph_t = dov_graph; graph_t g(100); REQUIRE(g.graph_value() == 100); } SECTION("with void graph value") { - using graph_t = dynamic_graph>; + using graph_t = dov_graph; graph_t g; REQUIRE(g.size() == 0); } @@ -397,19 +396,19 @@ TEST_CASE("dov value types", "[dov][value_types]") { } SECTION("with string edge value type") { - using graph_t = dynamic_graph>; + using graph_t = dov_graph; graph_t g; REQUIRE(g.size() == 0); } SECTION("with string vertex value type") { - using graph_t = dynamic_graph>; + using graph_t = dov_graph; graph_t g; REQUIRE(g.size() == 0); } SECTION("with string graph value type") { - using graph_t = dynamic_graph>; + using graph_t = dov_graph; graph_t g(std::string("test")); REQUIRE(g.graph_value() == "test"); } @@ -427,32 +426,32 @@ TEST_CASE("dov value types", "[dov][value_types]") { TEST_CASE("dov vertex ID types", "[dov][vertex_id]") { SECTION("with uint32_t vertex id") { using graph_t = - dynamic_graph>; + dov_graph; graph_t g; REQUIRE(g.size() == 0); } SECTION("with uint64_t vertex id") { using graph_t = - dynamic_graph>; + dov_graph; graph_t g; REQUIRE(g.size() == 0); } SECTION("with int32_t vertex id") { - using graph_t = dynamic_graph>; + using graph_t = dov_graph; graph_t g; REQUIRE(g.size() == 0); } SECTION("with int8_t vertex id") { - using graph_t = dynamic_graph>; + using graph_t = dov_graph; graph_t g; REQUIRE(g.size() == 0); } SECTION("with int vertex id") { - using graph_t = dynamic_graph>; + using graph_t = dov_graph; graph_t g; REQUIRE(g.size() == 0); } @@ -869,7 +868,7 @@ TEST_CASE("dov load_vertices", "[dynamic_graph][dov][load_vertices]") { } SECTION("with custom projection from struct") { - using G2 = dynamic_graph>; + using G2 = dov_graph; using vertex_data2 = copyable_vertex_t; struct Person { @@ -1006,7 +1005,7 @@ TEST_CASE("dov load_edges", "[dynamic_graph][dov][load_edges]") { } SECTION("with custom projection") { - using G2 = dynamic_graph>; + using G2 = dov_graph; using vertex_data2 = copyable_vertex_t; using edge_data2 = copyable_edge_t; diff --git a/tests/container/dynamic_graph/test_dynamic_graph_generic_queries.cpp b/tests/container/dynamic_graph/test_dynamic_graph_generic_queries.cpp index 6814c9b..902a9c3 100644 --- a/tests/container/dynamic_graph/test_dynamic_graph_generic_queries.cpp +++ b/tests/container/dynamic_graph/test_dynamic_graph_generic_queries.cpp @@ -9,7 +9,6 @@ #include #include -#include #include #include #include @@ -160,15 +159,15 @@ bool is_empty(const G& g) { //================================================================================================== // Sequential container graphs (integral VId) -using vov_void = dynamic_graph>; +using vov_void = vov_graph; using dofl_void = - dynamic_graph>; + dofl_graph; // Map-based graphs (string VId) using mos_void = - dynamic_graph>; + mos_graph; using mous_void = - dynamic_graph>; + mous_graph; //================================================================================================== // Phase 6.3.1: Generic Graph Queries Tests diff --git a/tests/container/dynamic_graph/test_dynamic_graph_heterogeneous.cpp b/tests/container/dynamic_graph/test_dynamic_graph_heterogeneous.cpp index febac2a..8d19176 100644 --- a/tests/container/dynamic_graph/test_dynamic_graph_heterogeneous.cpp +++ b/tests/container/dynamic_graph/test_dynamic_graph_heterogeneous.cpp @@ -1,5 +1,4 @@ #include -#include #include #include #include @@ -13,14 +12,14 @@ using namespace graph::adj_list; using namespace graph::container; // Type aliases for different graph types -using vov_uint = dynamic_graph>; +using vov_uint = vov_graph; using mos_string = - dynamic_graph>; + mos_graph; -using dofl_int = dynamic_graph>; +using dofl_int = dofl_graph; -using dov_uint = dynamic_graph>; +using dov_uint = dov_graph; // Type alias for graph containers using copyable_edge_uint = copyable_edge_t; @@ -133,10 +132,10 @@ TEST_CASE("Generic operations on variant collection", "[6.4.3]") { TEST_CASE("Check which graph type is stored in variant", "[6.4.3]") { using graph_variant = std::variant; - std::vector edges = {{"A", "B"}}; - std::vector vertices = {{"A"}, {"B"}}; + std::vector edge_data = {{"A", "B"}}; + std::vector vertex_data = {{"A"}, {"B"}}; std::vector partitions; - mos_string g(edges, vertices, identity{}, identity{}, partitions); + mos_string g(edge_data, vertex_data, identity{}, identity{}, partitions); graph_variant var = std::move(g); @@ -148,10 +147,10 @@ TEST_CASE("Check which graph type is stored in variant", "[6.4.3]") { TEST_CASE("Get specific graph type from variant", "[6.4.3]") { using graph_variant = std::variant; - std::vector edges = {{0, 1}, {1, 2}, {2, 3}}; - std::vector vertices = {{0}, {1}, {2}, {3}}; + std::vector edge_data = {{0, 1}, {1, 2}, {2, 3}}; + std::vector vertex_data = {{0}, {1}, {2}, {3}}; std::vector partitions; - vov_uint g(edges, vertices, identity{}, identity{}, partitions); + vov_uint g(edge_data, vertex_data, identity{}, identity{}, partitions); graph_variant var = std::move(g); @@ -308,16 +307,16 @@ TEST_CASE("Aggregate statistics across variant graphs", "[6.4.3]") { // Create multiple graphs for (int i = 0; i < 5; ++i) { - std::vector edges; - std::vector vertices; + std::vector edge_data; + std::vector vertex_data; for (uint64_t j = 0; j < static_cast(i + 1); ++j) { - vertices.push_back({j}); + vertex_data.push_back({j}); if (j > 0) { - edges.push_back({j - 1, j}); + edge_data.push_back({j - 1, j}); } } std::vector partitions; - graphs.emplace_back(vov_uint(edges, vertices, identity{}, identity{}, partitions)); + graphs.emplace_back(vov_uint(edge_data, vertex_data, identity{}, identity{}, partitions)); } // Calculate total vertices and edges @@ -367,10 +366,10 @@ TEST_CASE("Transform variant graphs", "[6.4.3]") { TEST_CASE("Conditional processing based on graph type", "[6.4.3]") { using graph_variant = std::variant; - std::vector edges = {{"node1", "node2"}}; - std::vector vertices = {{"node1"}, {"node2"}}; + std::vector edge_data = {{"node1", "node2"}}; + std::vector vertex_data = {{"node1"}, {"node2"}}; std::vector partitions; - mos_string g(edges, vertices, identity{}, identity{}, partitions); + mos_string g(edge_data, vertex_data, identity{}, identity{}, partitions); graph_variant var = std::move(g); @@ -392,10 +391,10 @@ TEST_CASE("Conditional processing based on graph type", "[6.4.3]") { TEST_CASE("Exception safety with variant graphs", "[6.4.3]") { using graph_variant = std::variant; - std::vector edges = {{0, 1}}; - std::vector vertices = {{0}, {1}}; + std::vector edge_data = {{0, 1}}; + std::vector vertex_data = {{0}, {1}}; std::vector partitions; - vov_uint g(edges, vertices, identity{}, identity{}, partitions); + vov_uint g(edge_data, vertex_data, identity{}, identity{}, partitions); graph_variant var = std::move(g); diff --git a/tests/container/dynamic_graph/test_dynamic_graph_integration.cpp b/tests/container/dynamic_graph/test_dynamic_graph_integration.cpp index 64c239a..a9dea80 100644 --- a/tests/container/dynamic_graph/test_dynamic_graph_integration.cpp +++ b/tests/container/dynamic_graph/test_dynamic_graph_integration.cpp @@ -7,7 +7,6 @@ */ #include -#include #include #include #include @@ -33,46 +32,46 @@ using namespace graph::container; //================================================================================================== // Sequential container graphs (integral VId) - void edges -using vov_void = dynamic_graph>; +using vov_void = vov_graph; using vofl_void = - dynamic_graph>; -using dol_void = dynamic_graph>; + vofl_graph; +using dol_void = dol_graph; using dofl_void = - dynamic_graph>; -using dov_void = dynamic_graph>; + dofl_graph; +using dov_void = dov_graph; // Sequential container graphs (integral VId) - int edges -using vov_int = dynamic_graph>; -using vofl_int = dynamic_graph>; -using dol_int = dynamic_graph>; -using dofl_int = dynamic_graph>; -using dov_int = dynamic_graph>; +using vov_int = vov_graph; +using vofl_int = vofl_graph; +using dol_int = dol_graph; +using dofl_int = dofl_graph; +using dov_int = dov_graph; // Map-based graphs (string VId) - void edges using mos_void = - dynamic_graph>; + mos_graph; using mol_void = - dynamic_graph>; + mol_graph; using mous_void = - dynamic_graph>; + mous_graph; // Map-based graphs (string VId) - int edges using mos_int = - dynamic_graph>; + mos_graph; using mol_int = - dynamic_graph>; + mol_graph; using mous_int = - dynamic_graph>; + mous_graph; // Set-based edge container graphs (integral VId) - void edges -using vos_void = dynamic_graph>; +using vos_void = vos_graph; // Unordered set-based edge container graphs (integral VId) - void edges using vous_void = - dynamic_graph>; + vous_graph; // Set-based edge container graphs (integral VId) - int edges -using vos_int = dynamic_graph>; +using vos_int = vos_graph; // String edge value types using vov_string = dynamic_graph> edge_list; - for (auto&& v : vertices(source)) { - for (auto&& e : edges(source, v)) { - edge_list.push_back({vertex_id(source, v), target_id(source, e)}); + for (auto&& v : vertices(src_graph)) { + for (auto&& e : edges(src_graph, v)) { + edge_list.push_back({vertex_id(src_graph, v), target_id(src_graph, e)}); } } - vov_void target; - target.load_edges(edge_list, std::identity{}); + vov_void dst_graph; + dst_graph.load_edges(edge_list, std::identity{}); - REQUIRE(target.size() == 0); - REQUIRE(count_edges(target) == 0); + REQUIRE(dst_graph.size() == 0); + REQUIRE(count_edges(dst_graph) == 0); } TEST_CASE("Empty vov to vofl - void edges", "[integration][6.5.1][empty]") { - vov_void source; + vov_void src_graph; std::vector> edge_list; - vofl_void target; - target.load_edges(edge_list, std::identity{}); + vofl_void dst_graph; + dst_graph.load_edges(edge_list, std::identity{}); - REQUIRE(target.size() == 0); - REQUIRE(count_edges(target) == 0); + REQUIRE(dst_graph.size() == 0); + REQUIRE(count_edges(dst_graph) == 0); } TEST_CASE("Empty dov to dol - void edges", "[integration][6.5.1][empty]") { - dov_void source; + dov_void src_graph; std::vector> edge_list; - dol_void target; - target.load_edges(edge_list, std::identity{}); + dol_void dst_graph; + dst_graph.load_edges(edge_list, std::identity{}); - REQUIRE(target.size() == 0); - REQUIRE(count_edges(target) == 0); + REQUIRE(dst_graph.size() == 0); + REQUIRE(count_edges(dst_graph) == 0); } TEST_CASE("Empty mos to mol - void edges", "[integration][6.5.1][empty]") { - mos_void source; + mos_void src_graph; std::vector> edge_list; - mol_void target; - target.load_edges(edge_list, std::identity{}); + mol_void dst_graph; + dst_graph.load_edges(edge_list, std::identity{}); - REQUIRE(target.size() == 0); - REQUIRE(count_edges(target) == 0); + REQUIRE(dst_graph.size() == 0); + REQUIRE(count_edges(dst_graph) == 0); } TEST_CASE("Empty vov to vov - int edges", "[integration][6.5.1][empty]") { - vov_int source; + vov_int src_graph; std::vector> edge_list; - vov_int target; - target.load_edges(edge_list, std::identity{}); + vov_int dst_graph; + dst_graph.load_edges(edge_list, std::identity{}); - REQUIRE(target.size() == 0); - REQUIRE(count_edges(target) == 0); + REQUIRE(dst_graph.size() == 0); + REQUIRE(count_edges(dst_graph) == 0); } TEST_CASE("Empty mos to mous - int edges", "[integration][6.5.1][empty]") { - mos_int source; + mos_int src_graph; std::vector> edge_list; - mous_int target; - target.load_edges(edge_list, std::identity{}); + mous_int dst_graph; + dst_graph.load_edges(edge_list, std::identity{}); - REQUIRE(target.size() == 0); - REQUIRE(count_edges(target) == 0); + REQUIRE(dst_graph.size() == 0); + REQUIRE(count_edges(dst_graph) == 0); } TEST_CASE("Empty graph - vertices range empty", "[integration][6.5.1][empty]") { @@ -892,77 +891,77 @@ TEST_CASE("Self-loop - mous with string IDs", "[integration][6.5.3][self_loop]") } TEST_CASE("Self-loop - copy vov to vofl preserves", "[integration][6.5.3][self_loop]") { - vov_void source({{0, 0}, {1, 1}}); + vov_void src_graph({{0, 0}, {1, 1}}); std::vector> edge_list; - for (auto&& v : vertices(source)) { - for (auto&& e : edges(source, v)) { - edge_list.push_back({vertex_id(source, v), target_id(source, e)}); + for (auto&& v : vertices(src_graph)) { + for (auto&& e : edges(src_graph, v)) { + edge_list.push_back({vertex_id(src_graph, v), target_id(src_graph, e)}); } } - vofl_void target; - target.load_edges(edge_list, std::identity{}); + vofl_void dst_graph; + dst_graph.load_edges(edge_list, std::identity{}); - REQUIRE(target.size() == 2); - REQUIRE(count_edges(target) == 2); + REQUIRE(dst_graph.size() == 2); + REQUIRE(count_edges(dst_graph) == 2); for (uint64_t v = 0; v < 2; ++v) { - auto edge_rng = edges(target, v); + auto edge_rng = edges(dst_graph, v); REQUIRE(std::ranges::distance(edge_rng) == 1); - REQUIRE(target_id(target, *edge_rng.begin()) == v); + REQUIRE(target_id(dst_graph, *edge_rng.begin()) == v); } } TEST_CASE("Self-loop - copy vov to dov preserves", "[integration][6.5.3][self_loop]") { - vov_void source({{0, 0}, {1, 1}, {2, 2}}); + vov_void src_graph({{0, 0}, {1, 1}, {2, 2}}); std::vector> edge_list; - for (auto&& v : vertices(source)) { - for (auto&& e : edges(source, v)) { - edge_list.push_back({vertex_id(source, v), target_id(source, e)}); + for (auto&& v : vertices(src_graph)) { + for (auto&& e : edges(src_graph, v)) { + edge_list.push_back({vertex_id(src_graph, v), target_id(src_graph, e)}); } } - dov_void target; - target.load_edges(edge_list, std::identity{}); + dov_void dst_graph; + dst_graph.load_edges(edge_list, std::identity{}); - REQUIRE(target.size() == 3); - REQUIRE(count_edges(target) == 3); + REQUIRE(dst_graph.size() == 3); + REQUIRE(count_edges(dst_graph) == 3); } TEST_CASE("Self-loop - copy mos to mol preserves", "[integration][6.5.3][self_loop]") { - mos_void source({{"a", "a"}, {"b", "b"}}); + mos_void src_graph({{"a", "a"}, {"b", "b"}}); std::vector> edge_list; - for (auto&& v : vertices(source)) { - for (auto&& e : edges(source, v)) { - edge_list.push_back({vertex_id(source, v), target_id(source, e)}); + for (auto&& v : vertices(src_graph)) { + for (auto&& e : edges(src_graph, v)) { + edge_list.push_back({vertex_id(src_graph, v), target_id(src_graph, e)}); } } - mol_void target; - target.load_edges(edge_list, std::identity{}); + mol_void dst_graph; + dst_graph.load_edges(edge_list, std::identity{}); - REQUIRE(target.size() == 2); - REQUIRE(count_edges(target) == 2); + REQUIRE(dst_graph.size() == 2); + REQUIRE(count_edges(dst_graph) == 2); } TEST_CASE("Self-loop - copy mos to mous preserves", "[integration][6.5.3][self_loop]") { - mos_void source({{"x", "x"}, {"y", "y"}, {"z", "z"}}); + mos_void src_graph({{"x", "x"}, {"y", "y"}, {"z", "z"}}); std::vector> edge_list; - for (auto&& v : vertices(source)) { - for (auto&& e : edges(source, v)) { - edge_list.push_back({vertex_id(source, v), target_id(source, e)}); + for (auto&& v : vertices(src_graph)) { + for (auto&& e : edges(src_graph, v)) { + edge_list.push_back({vertex_id(src_graph, v), target_id(src_graph, e)}); } } - mous_void target; - target.load_edges(edge_list, std::identity{}); + mous_void dst_graph; + dst_graph.load_edges(edge_list, std::identity{}); - REQUIRE(target.size() == 3); - REQUIRE(count_edges(target) == 3); + REQUIRE(dst_graph.size() == 3); + REQUIRE(count_edges(dst_graph) == 3); } TEST_CASE("Self-loop - vov with int edges", "[integration][6.5.3][self_loop]") { @@ -1085,75 +1084,75 @@ TEST_CASE("Parallel edges - dol allows duplicates", "[integration][6.5.4][parall } TEST_CASE("Parallel edges - copy vov to vos deduplicates", "[integration][6.5.4][parallel]") { - vov_void source({{0, 1}, {0, 1}, {0, 1}}); + vov_void src_graph({{0, 1}, {0, 1}, {0, 1}}); std::vector> edge_list; - for (auto&& v : vertices(source)) { - for (auto&& e : edges(source, v)) { - edge_list.push_back({vertex_id(source, v), target_id(source, e)}); + for (auto&& v : vertices(src_graph)) { + for (auto&& e : edges(src_graph, v)) { + edge_list.push_back({vertex_id(src_graph, v), target_id(src_graph, e)}); } } - vos_void target; - target.load_edges(edge_list, std::identity{}); + vos_void dst_graph; + dst_graph.load_edges(edge_list, std::identity{}); - REQUIRE(target.size() == 2); - REQUIRE(count_edges(target) == 1); // Deduplicated to 1 edge - REQUIRE(degree(target, 0) == 1); + REQUIRE(dst_graph.size() == 2); + REQUIRE(count_edges(dst_graph) == 1); // Deduplicated to 1 edge + REQUIRE(degree(dst_graph, 0) == 1); } TEST_CASE("Parallel edges - copy vofl to vos deduplicates", "[integration][6.5.4][parallel]") { - vofl_void source({{0, 1}, {0, 1}, {0, 2}, {0, 2}}); + vofl_void src_graph({{0, 1}, {0, 1}, {0, 2}, {0, 2}}); std::vector> edge_list; - for (auto&& v : vertices(source)) { - for (auto&& e : edges(source, v)) { - edge_list.push_back({vertex_id(source, v), target_id(source, e)}); + for (auto&& v : vertices(src_graph)) { + for (auto&& e : edges(src_graph, v)) { + edge_list.push_back({vertex_id(src_graph, v), target_id(src_graph, e)}); } } - vos_void target; - target.load_edges(edge_list, std::identity{}); + vos_void dst_graph; + dst_graph.load_edges(edge_list, std::identity{}); - REQUIRE(target.size() == 3); - REQUIRE(count_edges(target) == 2); // 4 edges -> 2 unique edges - REQUIRE(degree(target, 0) == 2); + REQUIRE(dst_graph.size() == 3); + REQUIRE(count_edges(dst_graph) == 2); // 4 edges -> 2 unique edges + REQUIRE(degree(dst_graph, 0) == 2); } TEST_CASE("Parallel edges - copy vov to vous deduplicates", "[integration][6.5.4][parallel]") { - vov_void source({{0, 1}, {0, 1}, {1, 2}, {1, 2}, {1, 2}}); + vov_void src_graph({{0, 1}, {0, 1}, {1, 2}, {1, 2}, {1, 2}}); std::vector> edge_list; - for (auto&& v : vertices(source)) { - for (auto&& e : edges(source, v)) { - edge_list.push_back({vertex_id(source, v), target_id(source, e)}); + for (auto&& v : vertices(src_graph)) { + for (auto&& e : edges(src_graph, v)) { + edge_list.push_back({vertex_id(src_graph, v), target_id(src_graph, e)}); } } - vous_void target; - target.load_edges(edge_list, std::identity{}); + vous_void dst_graph; + dst_graph.load_edges(edge_list, std::identity{}); - REQUIRE(target.size() == 3); - REQUIRE(count_edges(target) == 2); // 5 edges -> 2 unique - REQUIRE(degree(target, 0) == 1); - REQUIRE(degree(target, 1) == 1); + REQUIRE(dst_graph.size() == 3); + REQUIRE(count_edges(dst_graph) == 2); // 5 edges -> 2 unique + REQUIRE(degree(dst_graph, 0) == 1); + REQUIRE(degree(dst_graph, 1) == 1); } TEST_CASE("Parallel edges - copy dol to mos deduplicates", "[integration][6.5.4][parallel]") { - dol_void source({{0, 1}, {0, 1}, {0, 2}}); + dol_void src_graph({{0, 1}, {0, 1}, {0, 2}}); std::vector> edge_list; - for (auto&& v : vertices(source)) { - for (auto&& e : edges(source, v)) { - edge_list.push_back({std::to_string(vertex_id(source, v)), std::to_string(target_id(source, e))}); + for (auto&& v : vertices(src_graph)) { + for (auto&& e : edges(src_graph, v)) { + edge_list.push_back({std::to_string(vertex_id(src_graph, v)), std::to_string(target_id(src_graph, e))}); } } - mos_void target; - target.load_edges(edge_list, std::identity{}); + mos_void dst_graph; + dst_graph.load_edges(edge_list, std::identity{}); - REQUIRE(target.size() == 3); - REQUIRE(count_edges(target) == 2); // 3 edges -> 2 unique + REQUIRE(dst_graph.size() == 3); + REQUIRE(count_edges(dst_graph) == 2); // 3 edges -> 2 unique } TEST_CASE("Parallel edges - vos has no duplicates", "[integration][6.5.4][parallel]") { @@ -1180,54 +1179,54 @@ TEST_CASE("Parallel edges - mos has no duplicates", "[integration][6.5.4][parall } TEST_CASE("Parallel edges - copy vos to vov no duplicates", "[integration][6.5.4][parallel]") { - vos_void source({{0, 1}, {0, 2}}); + vos_void src_graph({{0, 1}, {0, 2}}); std::vector> edge_list; - for (auto&& v : vertices(source)) { - for (auto&& e : edges(source, v)) { - edge_list.push_back({vertex_id(source, v), target_id(source, e)}); + for (auto&& v : vertices(src_graph)) { + for (auto&& e : edges(src_graph, v)) { + edge_list.push_back({vertex_id(src_graph, v), target_id(src_graph, e)}); } } - vov_void target; - target.load_edges(edge_list, std::identity{}); + vov_void dst_graph; + dst_graph.load_edges(edge_list, std::identity{}); - REQUIRE(target.size() == 3); - REQUIRE(count_edges(target) == 2); // Still no duplicates + REQUIRE(dst_graph.size() == 3); + REQUIRE(count_edges(dst_graph) == 2); // Still no duplicates } TEST_CASE("Parallel edges - copy vous to vofl no duplicates", "[integration][6.5.4][parallel]") { - vous_void source({{0, 1}, {0, 2}, {1, 2}}); + vous_void src_graph({{0, 1}, {0, 2}, {1, 2}}); std::vector> edge_list; - for (auto&& v : vertices(source)) { - for (auto&& e : edges(source, v)) { - edge_list.push_back({vertex_id(source, v), target_id(source, e)}); + for (auto&& v : vertices(src_graph)) { + for (auto&& e : edges(src_graph, v)) { + edge_list.push_back({vertex_id(src_graph, v), target_id(src_graph, e)}); } } - vofl_void target; - target.load_edges(edge_list, std::identity{}); + vofl_void dst_graph; + dst_graph.load_edges(edge_list, std::identity{}); - REQUIRE(target.size() == 3); - REQUIRE(count_edges(target) == 3); + REQUIRE(dst_graph.size() == 3); + REQUIRE(count_edges(dst_graph) == 3); } TEST_CASE("Parallel edges - copy mos to mol no duplicates", "[integration][6.5.4][parallel]") { - mos_void source({{"a", "b"}, {"a", "c"}}); + mos_void src_graph({{"a", "b"}, {"a", "c"}}); std::vector> edge_list; - for (auto&& v : vertices(source)) { - for (auto&& e : edges(source, v)) { - edge_list.push_back({vertex_id(source, v), target_id(source, e)}); + for (auto&& v : vertices(src_graph)) { + for (auto&& e : edges(src_graph, v)) { + edge_list.push_back({vertex_id(src_graph, v), target_id(src_graph, e)}); } } - mol_void target; - target.load_edges(edge_list, std::identity{}); + mol_void dst_graph; + dst_graph.load_edges(edge_list, std::identity{}); - REQUIRE(target.size() == 3); - REQUIRE(count_edges(target) == 2); + REQUIRE(dst_graph.size() == 3); + REQUIRE(count_edges(dst_graph) == 2); } TEST_CASE("Parallel edges - vov with int edges allows duplicates", "[integration][6.5.4][parallel]") { @@ -1248,21 +1247,21 @@ TEST_CASE("Parallel edges - vov with int edges allows duplicates", "[integration REQUIRE(std::ranges::find(values, 30) != values.end()); } -TEST_CASE("Parallel edges - copy vov int to vos deduplicates by target", "[integration][6.5.4][parallel]") { - vov_int source({{0, 1, 10}, {0, 1, 20}, {0, 1, 30}}); +TEST_CASE("Parallel edges - copy vov int to vos deduplicates by dst_graph", "[integration][6.5.4][parallel]") { + vov_int src_graph({{0, 1, 10}, {0, 1, 20}, {0, 1, 30}}); std::vector> edge_list; - for (auto&& v : vertices(source)) { - for (auto&& e : edges(source, v)) { - edge_list.push_back({vertex_id(source, v), target_id(source, e), edge_value(source, e)}); + for (auto&& v : vertices(src_graph)) { + for (auto&& e : edges(src_graph, v)) { + edge_list.push_back({vertex_id(src_graph, v), target_id(src_graph, e), edge_value(src_graph, e)}); } } - vos_int target; - target.load_edges(edge_list, std::identity{}); + vos_int dst_graph; + dst_graph.load_edges(edge_list, std::identity{}); - REQUIRE(target.size() == 2); - REQUIRE(count_edges(target) == 1); // Deduplicated to 1 edge + REQUIRE(dst_graph.size() == 2); + REQUIRE(count_edges(dst_graph) == 1); // Deduplicated to 1 edge // Note: One of the edge values is kept (implementation-defined which one) } @@ -1276,22 +1275,22 @@ TEST_CASE("Parallel edges - mixed regular and parallel", "[integration][6.5.4][p } TEST_CASE("Parallel edges - copy mixed to vos partial deduplication", "[integration][6.5.4][parallel]") { - vov_void source({{0, 1}, {0, 1}, {0, 2}, {1, 2}, {1, 2}}); + vov_void src_graph({{0, 1}, {0, 1}, {0, 2}, {1, 2}, {1, 2}}); std::vector> edge_list; - for (auto&& v : vertices(source)) { - for (auto&& e : edges(source, v)) { - edge_list.push_back({vertex_id(source, v), target_id(source, e)}); + for (auto&& v : vertices(src_graph)) { + for (auto&& e : edges(src_graph, v)) { + edge_list.push_back({vertex_id(src_graph, v), target_id(src_graph, e)}); } } - vos_void target; - target.load_edges(edge_list, std::identity{}); + vos_void dst_graph; + dst_graph.load_edges(edge_list, std::identity{}); - REQUIRE(target.size() == 3); - REQUIRE(count_edges(target) == 3); // 5 edges -> 3 unique (0->1, 0->2, 1->2) - REQUIRE(degree(target, 0) == 2); - REQUIRE(degree(target, 1) == 1); + REQUIRE(dst_graph.size() == 3); + REQUIRE(count_edges(dst_graph) == 3); // 5 edges -> 3 unique (0->1, 0->2, 1->2) + REQUIRE(degree(dst_graph, 0) == 2); + REQUIRE(degree(dst_graph, 1) == 1); } TEST_CASE("Parallel edges - vofl self-loops can be parallel", "[integration][6.5.4][parallel]") { @@ -1303,27 +1302,27 @@ TEST_CASE("Parallel edges - vofl self-loops can be parallel", "[integration][6.5 } TEST_CASE("Parallel edges - copy vofl self-loops to vos deduplicates", "[integration][6.5.4][parallel]") { - vofl_void source({{0, 0}, {0, 0}}); + vofl_void src_graph({{0, 0}, {0, 0}}); std::vector> edge_list; - for (auto&& v : vertices(source)) { - for (auto&& e : edges(source, v)) { - edge_list.push_back({vertex_id(source, v), target_id(source, e)}); + for (auto&& v : vertices(src_graph)) { + for (auto&& e : edges(src_graph, v)) { + edge_list.push_back({vertex_id(src_graph, v), target_id(src_graph, e)}); } } - vos_void target; - target.load_edges(edge_list, std::identity{}); + vos_void dst_graph; + dst_graph.load_edges(edge_list, std::identity{}); - REQUIRE(target.size() == 1); - REQUIRE(count_edges(target) == 1); // Self-loop deduplicated - REQUIRE(degree(target, 0) == 1); + REQUIRE(dst_graph.size() == 1); + REQUIRE(count_edges(dst_graph) == 1); // Self-loop deduplicated + REQUIRE(degree(dst_graph, 0) == 1); } TEST_CASE("Parallel edges - count unique edges in vov", "[integration][6.5.4][parallel]") { vov_void g({{0, 1}, {0, 1}, {0, 2}, {1, 0}, {1, 0}}); - // Count unique (source, target) pairs + // Count unique (src_graph, dst_graph) pairs std::set> unique_edges; for (auto&& v : vertices(g)) { auto vid = vertex_id(g, v); @@ -1341,383 +1340,383 @@ TEST_CASE("Parallel edges - count unique edges in vov", "[integration][6.5.4][pa //================================================================================================== TEST_CASE("Value conversion - int to string edge values", "[integration][6.5.5][conversion]") { - vov_int source({{0, 1, 42}, {1, 2, 99}}); + vov_int src_graph({{0, 1, 42}, {1, 2, 99}}); std::vector> edge_list; - for (auto&& v : vertices(source)) { - for (auto&& e : edges(source, v)) { - edge_list.push_back({vertex_id(source, v), target_id(source, e), std::to_string(edge_value(source, e))}); + for (auto&& v : vertices(src_graph)) { + for (auto&& e : edges(src_graph, v)) { + edge_list.push_back({vertex_id(src_graph, v), target_id(src_graph, e), std::to_string(edge_value(src_graph, e))}); } } - vov_string target; - target.load_edges(edge_list, std::identity{}); + vov_string dst_graph; + dst_graph.load_edges(edge_list, std::identity{}); - REQUIRE(target.size() == 3); - REQUIRE(count_edges(target) == 2); + REQUIRE(dst_graph.size() == 3); + REQUIRE(count_edges(dst_graph) == 2); - auto edge_rng = edges(target, 0); - REQUIRE(edge_value(target, *edge_rng.begin()) == "42"); + auto edge_rng = edges(dst_graph, 0); + REQUIRE(edge_value(dst_graph, *edge_rng.begin()) == "42"); } TEST_CASE("Value conversion - string to int edge values", "[integration][6.5.5][conversion]") { - vov_string source({{0, 1, "123"}, {1, 2, "456"}}); + vov_string src_graph({{0, 1, "123"}, {1, 2, "456"}}); std::vector> edge_list; - for (auto&& v : vertices(source)) { - for (auto&& e : edges(source, v)) { - edge_list.push_back({vertex_id(source, v), target_id(source, e), std::stoi(edge_value(source, e))}); + for (auto&& v : vertices(src_graph)) { + for (auto&& e : edges(src_graph, v)) { + edge_list.push_back({vertex_id(src_graph, v), target_id(src_graph, e), std::stoi(edge_value(src_graph, e))}); } } - vov_int target; - target.load_edges(edge_list, std::identity{}); + vov_int dst_graph; + dst_graph.load_edges(edge_list, std::identity{}); - REQUIRE(target.size() == 3); - REQUIRE(count_edges(target) == 2); + REQUIRE(dst_graph.size() == 3); + REQUIRE(count_edges(dst_graph) == 2); - auto edge_rng = edges(target, 0); - REQUIRE(edge_value(target, *edge_rng.begin()) == 123); + auto edge_rng = edges(dst_graph, 0); + REQUIRE(edge_value(dst_graph, *edge_rng.begin()) == 123); } TEST_CASE("Value conversion - void to int (default values)", "[integration][6.5.5][conversion]") { - vov_void source({{0, 1}, {1, 2}, {2, 0}}); + vov_void src_graph({{0, 1}, {1, 2}, {2, 0}}); std::vector> edge_list; - for (auto&& v : vertices(source)) { - for (auto&& e : edges(source, v)) { + for (auto&& v : vertices(src_graph)) { + for (auto&& e : edges(src_graph, v)) { edge_list.push_back({ - vertex_id(source, v), target_id(source, e), + vertex_id(src_graph, v), target_id(src_graph, e), 100 // Default value }); } } - vov_int target; - target.load_edges(edge_list, std::identity{}); + vov_int dst_graph; + dst_graph.load_edges(edge_list, std::identity{}); - REQUIRE(target.size() == 3); - REQUIRE(count_edges(target) == 3); + REQUIRE(dst_graph.size() == 3); + REQUIRE(count_edges(dst_graph) == 3); - for (auto&& v : vertices(target)) { - for (auto&& e : edges(target, v)) { - REQUIRE(edge_value(target, e) == 100); + for (auto&& v : vertices(dst_graph)) { + for (auto&& e : edges(dst_graph, v)) { + REQUIRE(edge_value(dst_graph, e) == 100); } } } TEST_CASE("Value conversion - int to void (discard values)", "[integration][6.5.5][conversion]") { - vov_int source({{0, 1, 42}, {1, 2, 99}, {2, 0, 77}}); + vov_int src_graph({{0, 1, 42}, {1, 2, 99}, {2, 0, 77}}); std::vector> edge_list; - for (auto&& v : vertices(source)) { - for (auto&& e : edges(source, v)) { - edge_list.push_back({vertex_id(source, v), target_id(source, e)}); + for (auto&& v : vertices(src_graph)) { + for (auto&& e : edges(src_graph, v)) { + edge_list.push_back({vertex_id(src_graph, v), target_id(src_graph, e)}); } } - vov_void target; - target.load_edges(edge_list, std::identity{}); + vov_void dst_graph; + dst_graph.load_edges(edge_list, std::identity{}); - REQUIRE(target.size() == 3); - REQUIRE(count_edges(target) == 3); + REQUIRE(dst_graph.size() == 3); + REQUIRE(count_edges(dst_graph) == 3); } TEST_CASE("Value conversion - transform int values (* 2)", "[integration][6.5.5][conversion]") { - vov_int source({{0, 1, 10}, {1, 2, 20}, {2, 0, 30}}); + vov_int src_graph({{0, 1, 10}, {1, 2, 20}, {2, 0, 30}}); std::vector> edge_list; - for (auto&& v : vertices(source)) { - for (auto&& e : edges(source, v)) { - edge_list.push_back({vertex_id(source, v), target_id(source, e), edge_value(source, e) * 2}); + for (auto&& v : vertices(src_graph)) { + for (auto&& e : edges(src_graph, v)) { + edge_list.push_back({vertex_id(src_graph, v), target_id(src_graph, e), edge_value(src_graph, e) * 2}); } } - vov_int target; - target.load_edges(edge_list, std::identity{}); + vov_int dst_graph; + dst_graph.load_edges(edge_list, std::identity{}); - REQUIRE(target.size() == 3); - REQUIRE(count_edges(target) == 3); + REQUIRE(dst_graph.size() == 3); + REQUIRE(count_edges(dst_graph) == 3); - auto e0 = edges(target, 0); - REQUIRE(edge_value(target, *e0.begin()) == 20); + auto e0 = edges(dst_graph, 0); + REQUIRE(edge_value(dst_graph, *e0.begin()) == 20); } TEST_CASE("Value conversion - map graph int to string", "[integration][6.5.5][conversion]") { - mos_int source({{"a", "b", 1}, {"b", "c", 2}}); + mos_int src_graph({{"a", "b", 1}, {"b", "c", 2}}); std::vector> edge_list; - for (auto&& v : vertices(source)) { - for (auto&& e : edges(source, v)) { - edge_list.push_back({vertex_id(source, v), target_id(source, e), std::to_string(edge_value(source, e))}); + for (auto&& v : vertices(src_graph)) { + for (auto&& e : edges(src_graph, v)) { + edge_list.push_back({vertex_id(src_graph, v), target_id(src_graph, e), std::to_string(edge_value(src_graph, e))}); } } - mos_string target; - target.load_edges(edge_list, std::identity{}); + mos_string dst_graph; + dst_graph.load_edges(edge_list, std::identity{}); - REQUIRE(target.size() == 3); - REQUIRE(count_edges(target) == 2); + REQUIRE(dst_graph.size() == 3); + REQUIRE(count_edges(dst_graph) == 2); - auto e_rng = edges(target, "a"); - REQUIRE(edge_value(target, *e_rng.begin()) == "1"); + auto e_rng = edges(dst_graph, "a"); + REQUIRE(edge_value(dst_graph, *e_rng.begin()) == "1"); } TEST_CASE("Value conversion - map graph void to int", "[integration][6.5.5][conversion]") { - mos_void source({{"a", "b"}, {"b", "c"}}); + mos_void src_graph({{"a", "b"}, {"b", "c"}}); std::vector> edge_list; int counter = 1; - for (auto&& v : vertices(source)) { - for (auto&& e : edges(source, v)) { - edge_list.push_back({vertex_id(source, v), target_id(source, e), counter++}); + for (auto&& v : vertices(src_graph)) { + for (auto&& e : edges(src_graph, v)) { + edge_list.push_back({vertex_id(src_graph, v), target_id(src_graph, e), counter++}); } } - mos_int target; - target.load_edges(edge_list, std::identity{}); + mos_int dst_graph; + dst_graph.load_edges(edge_list, std::identity{}); - REQUIRE(target.size() == 3); - REQUIRE(count_edges(target) == 2); + REQUIRE(dst_graph.size() == 3); + REQUIRE(count_edges(dst_graph) == 2); } TEST_CASE("Value conversion - different trait types with conversion", "[integration][6.5.5][conversion]") { - vov_int source({{0, 1, 5}, {1, 2, 10}}); + vov_int src_graph({{0, 1, 5}, {1, 2, 10}}); std::vector> edge_list; - for (auto&& v : vertices(source)) { - for (auto&& e : edges(source, v)) { + for (auto&& v : vertices(src_graph)) { + for (auto&& e : edges(src_graph, v)) { edge_list.push_back( - {vertex_id(source, v), target_id(source, e), "value_" + std::to_string(edge_value(source, e))}); + {vertex_id(src_graph, v), target_id(src_graph, e), "value_" + std::to_string(edge_value(src_graph, e))}); } } - vofl_string target; - target.load_edges(edge_list, std::identity{}); + vofl_string dst_graph; + dst_graph.load_edges(edge_list, std::identity{}); - REQUIRE(target.size() == 3); - REQUIRE(count_edges(target) == 2); + REQUIRE(dst_graph.size() == 3); + REQUIRE(count_edges(dst_graph) == 2); } TEST_CASE("Value conversion - preserve structure discard values", "[integration][6.5.5][conversion]") { - vov_int source({{0, 1, 1}, {0, 2, 2}, {1, 2, 3}, {2, 0, 4}}); + vov_int src_graph({{0, 1, 1}, {0, 2, 2}, {1, 2, 3}, {2, 0, 4}}); std::vector> edge_list; - for (auto&& v : vertices(source)) { - for (auto&& e : edges(source, v)) { - edge_list.push_back({vertex_id(source, v), target_id(source, e)}); + for (auto&& v : vertices(src_graph)) { + for (auto&& e : edges(src_graph, v)) { + edge_list.push_back({vertex_id(src_graph, v), target_id(src_graph, e)}); } } - vov_void target; - target.load_edges(edge_list, std::identity{}); + vov_void dst_graph; + dst_graph.load_edges(edge_list, std::identity{}); - REQUIRE(target.size() == source.size()); - REQUIRE(count_edges(target) == count_edges(source)); + REQUIRE(dst_graph.size() == src_graph.size()); + REQUIRE(count_edges(dst_graph) == count_edges(src_graph)); } TEST_CASE("Value conversion - add default values to empty graph", "[integration][6.5.5][conversion]") { - vov_void source; + vov_void src_graph; std::vector> edge_list; - vov_int target; - target.load_edges(edge_list, std::identity{}); + vov_int dst_graph; + dst_graph.load_edges(edge_list, std::identity{}); - REQUIRE(target.size() == 0); - REQUIRE(count_edges(target) == 0); + REQUIRE(dst_graph.size() == 0); + REQUIRE(count_edges(dst_graph) == 0); } TEST_CASE("Value conversion - convert with self-loops", "[integration][6.5.5][conversion]") { - vov_int source({{0, 0, 111}, {1, 1, 222}}); + vov_int src_graph({{0, 0, 111}, {1, 1, 222}}); std::vector> edge_list; - for (auto&& v : vertices(source)) { - for (auto&& e : edges(source, v)) { - edge_list.push_back({vertex_id(source, v), target_id(source, e), std::to_string(edge_value(source, e))}); + for (auto&& v : vertices(src_graph)) { + for (auto&& e : edges(src_graph, v)) { + edge_list.push_back({vertex_id(src_graph, v), target_id(src_graph, e), std::to_string(edge_value(src_graph, e))}); } } - vov_string target; - target.load_edges(edge_list, std::identity{}); + vov_string dst_graph; + dst_graph.load_edges(edge_list, std::identity{}); - REQUIRE(target.size() == 2); - REQUIRE(count_edges(target) == 2); + REQUIRE(dst_graph.size() == 2); + REQUIRE(count_edges(dst_graph) == 2); - auto e0 = edges(target, 0); - REQUIRE(edge_value(target, *e0.begin()) == "111"); + auto e0 = edges(dst_graph, 0); + REQUIRE(edge_value(dst_graph, *e0.begin()) == "111"); } TEST_CASE("Value conversion - complex transformation", "[integration][6.5.5][conversion]") { - vov_int source({{0, 1, 10}, {1, 2, 20}, {2, 0, 30}}); + vov_int src_graph({{0, 1, 10}, {1, 2, 20}, {2, 0, 30}}); std::vector> edge_list; - for (auto&& v : vertices(source)) { - for (auto&& e : edges(source, v)) { - int val = edge_value(source, e); + for (auto&& v : vertices(src_graph)) { + for (auto&& e : edges(src_graph, v)) { + int val = edge_value(src_graph, e); edge_list.push_back({ - vertex_id(source, v), target_id(source, e), + vertex_id(src_graph, v), target_id(src_graph, e), val * val // Square the value }); } } - vov_int target; - target.load_edges(edge_list, std::identity{}); + vov_int dst_graph; + dst_graph.load_edges(edge_list, std::identity{}); - REQUIRE(target.size() == 3); + REQUIRE(dst_graph.size() == 3); - auto e0 = edges(target, 0); - REQUIRE(edge_value(target, *e0.begin()) == 100); + auto e0 = edges(dst_graph, 0); + REQUIRE(edge_value(dst_graph, *e0.begin()) == 100); - auto e1 = edges(target, 1); - REQUIRE(edge_value(target, *e1.begin()) == 400); + auto e1 = edges(dst_graph, 1); + REQUIRE(edge_value(dst_graph, *e1.begin()) == 400); } TEST_CASE("Value conversion - conditional transformation", "[integration][6.5.5][conversion]") { - vov_int source({{0, 1, 5}, {1, 2, 15}, {2, 0, 25}}); + vov_int src_graph({{0, 1, 5}, {1, 2, 15}, {2, 0, 25}}); std::vector> edge_list; - for (auto&& v : vertices(source)) { - for (auto&& e : edges(source, v)) { - int val = edge_value(source, e); - edge_list.push_back({vertex_id(source, v), target_id(source, e), val >= 10 ? "high" : "low"}); + for (auto&& v : vertices(src_graph)) { + for (auto&& e : edges(src_graph, v)) { + int val = edge_value(src_graph, e); + edge_list.push_back({vertex_id(src_graph, v), target_id(src_graph, e), val >= 10 ? "high" : "low"}); } } - vov_string target; - target.load_edges(edge_list, std::identity{}); + vov_string dst_graph; + dst_graph.load_edges(edge_list, std::identity{}); - REQUIRE(target.size() == 3); + REQUIRE(dst_graph.size() == 3); - auto e0 = edges(target, 0); - REQUIRE(edge_value(target, *e0.begin()) == "low"); + auto e0 = edges(dst_graph, 0); + REQUIRE(edge_value(dst_graph, *e0.begin()) == "low"); - auto e1 = edges(target, 1); - REQUIRE(edge_value(target, *e1.begin()) == "high"); + auto e1 = edges(dst_graph, 1); + REQUIRE(edge_value(dst_graph, *e1.begin()) == "high"); } TEST_CASE("Value conversion - aggregation during copy", "[integration][6.5.5][conversion]") { - vov_int source({{0, 1, 10}, {1, 2, 20}, {2, 0, 30}}); + vov_int src_graph({{0, 1, 10}, {1, 2, 20}, {2, 0, 30}}); int sum = 0; std::vector> edge_list; - for (auto&& v : vertices(source)) { - for (auto&& e : edges(source, v)) { - sum += edge_value(source, e); + for (auto&& v : vertices(src_graph)) { + for (auto&& e : edges(src_graph, v)) { + sum += edge_value(src_graph, e); edge_list.push_back({ - vertex_id(source, v), target_id(source, e), + vertex_id(src_graph, v), target_id(src_graph, e), sum // Running sum }); } } - vov_int target; - target.load_edges(edge_list, std::identity{}); + vov_int dst_graph; + dst_graph.load_edges(edge_list, std::identity{}); - REQUIRE(target.size() == 3); + REQUIRE(dst_graph.size() == 3); REQUIRE(sum == 60); } TEST_CASE("Value conversion - vofl to vov with transformation", "[integration][6.5.5][conversion]") { - vofl_int source({{0, 1, 1}, {1, 2, 2}}); + vofl_int src_graph({{0, 1, 1}, {1, 2, 2}}); std::vector> edge_list; - for (auto&& v : vertices(source)) { - for (auto&& e : edges(source, v)) { - edge_list.push_back({vertex_id(source, v), target_id(source, e), edge_value(source, e) + 100}); + for (auto&& v : vertices(src_graph)) { + for (auto&& e : edges(src_graph, v)) { + edge_list.push_back({vertex_id(src_graph, v), target_id(src_graph, e), edge_value(src_graph, e) + 100}); } } - vov_int target; - target.load_edges(edge_list, std::identity{}); + vov_int dst_graph; + dst_graph.load_edges(edge_list, std::identity{}); - REQUIRE(target.size() == 3); + REQUIRE(dst_graph.size() == 3); - auto e0 = edges(target, 0); - REQUIRE(edge_value(target, *e0.begin()) == 101); + auto e0 = edges(dst_graph, 0); + REQUIRE(edge_value(dst_graph, *e0.begin()) == 101); } TEST_CASE("Value conversion - multiple edges same value conversion", "[integration][6.5.5][conversion]") { - vov_int source({{0, 1, 7}, {0, 2, 7}, {1, 2, 7}}); + vov_int src_graph({{0, 1, 7}, {0, 2, 7}, {1, 2, 7}}); std::vector> edge_list; - for (auto&& v : vertices(source)) { - for (auto&& e : edges(source, v)) { + for (auto&& v : vertices(src_graph)) { + for (auto&& e : edges(src_graph, v)) { edge_list.push_back( - {vertex_id(source, v), target_id(source, e), "lucky_" + std::to_string(edge_value(source, e))}); + {vertex_id(src_graph, v), target_id(src_graph, e), "lucky_" + std::to_string(edge_value(src_graph, e))}); } } - vov_string target; - target.load_edges(edge_list, std::identity{}); + vov_string dst_graph; + dst_graph.load_edges(edge_list, std::identity{}); - REQUIRE(target.size() == 3); - REQUIRE(count_edges(target) == 3); + REQUIRE(dst_graph.size() == 3); + REQUIRE(count_edges(dst_graph) == 3); - for (auto&& v : vertices(target)) { - for (auto&& e : edges(target, v)) { - REQUIRE(edge_value(target, e) == "lucky_7"); + for (auto&& v : vertices(dst_graph)) { + for (auto&& e : edges(dst_graph, v)) { + REQUIRE(edge_value(dst_graph, e) == "lucky_7"); } } } TEST_CASE("Value conversion - large values", "[integration][6.5.5][conversion]") { - vov_int source({{0, 1, 1000000}, {1, 2, 2000000}}); + vov_int src_graph({{0, 1, 1000000}, {1, 2, 2000000}}); std::vector> edge_list; - for (auto&& v : vertices(source)) { - for (auto&& e : edges(source, v)) { - edge_list.push_back({vertex_id(source, v), target_id(source, e), std::to_string(edge_value(source, e))}); + for (auto&& v : vertices(src_graph)) { + for (auto&& e : edges(src_graph, v)) { + edge_list.push_back({vertex_id(src_graph, v), target_id(src_graph, e), std::to_string(edge_value(src_graph, e))}); } } - vov_string target; - target.load_edges(edge_list, std::identity{}); + vov_string dst_graph; + dst_graph.load_edges(edge_list, std::identity{}); - REQUIRE(target.size() == 3); + REQUIRE(dst_graph.size() == 3); - auto e0 = edges(target, 0); - REQUIRE(edge_value(target, *e0.begin()) == "1000000"); + auto e0 = edges(dst_graph, 0); + REQUIRE(edge_value(dst_graph, *e0.begin()) == "1000000"); } TEST_CASE("Value conversion - negative to positive", "[integration][6.5.5][conversion]") { - vov_int source({{0, 1, -10}, {1, 2, -20}}); + vov_int src_graph({{0, 1, -10}, {1, 2, -20}}); std::vector> edge_list; - for (auto&& v : vertices(source)) { - for (auto&& e : edges(source, v)) { - edge_list.push_back({vertex_id(source, v), target_id(source, e), std::abs(edge_value(source, e))}); + for (auto&& v : vertices(src_graph)) { + for (auto&& e : edges(src_graph, v)) { + edge_list.push_back({vertex_id(src_graph, v), target_id(src_graph, e), std::abs(edge_value(src_graph, e))}); } } - vov_int target; - target.load_edges(edge_list, std::identity{}); + vov_int dst_graph; + dst_graph.load_edges(edge_list, std::identity{}); - REQUIRE(target.size() == 3); + REQUIRE(dst_graph.size() == 3); - auto e0 = edges(target, 0); - REQUIRE(edge_value(target, *e0.begin()) == 10); + auto e0 = edges(dst_graph, 0); + REQUIRE(edge_value(dst_graph, *e0.begin()) == 10); } TEST_CASE("Value conversion - format string values", "[integration][6.5.5][conversion]") { - vov_int source({{0, 1, 42}, {1, 2, 99}}); + vov_int src_graph({{0, 1, 42}, {1, 2, 99}}); std::vector> edge_list; - for (auto&& v : vertices(source)) { - for (auto&& e : edges(source, v)) { + for (auto&& v : vertices(src_graph)) { + for (auto&& e : edges(src_graph, v)) { edge_list.push_back( - {vertex_id(source, v), target_id(source, e), "[" + std::to_string(edge_value(source, e)) + "]"}); + {vertex_id(src_graph, v), target_id(src_graph, e), "[" + std::to_string(edge_value(src_graph, e)) + "]"}); } } - vov_string target; - target.load_edges(edge_list, std::identity{}); + vov_string dst_graph; + dst_graph.load_edges(edge_list, std::identity{}); - REQUIRE(target.size() == 3); + REQUIRE(dst_graph.size() == 3); - auto e0 = edges(target, 0); - REQUIRE(edge_value(target, *e0.begin()) == "[42]"); + auto e0 = edges(dst_graph, 0); + REQUIRE(edge_value(dst_graph, *e0.begin()) == "[42]"); } TEST_CASE("Value conversion - chain transformations", "[integration][6.5.5][conversion]") { @@ -1752,38 +1751,38 @@ TEST_CASE("Value conversion - chain transformations", "[integration][6.5.5][conv } TEST_CASE("Value conversion - preserve edge count across conversion", "[integration][6.5.5][conversion]") { - vov_int source({{0, 1, 1}, {0, 2, 2}, {1, 2, 3}, {2, 0, 4}, {2, 1, 5}}); + vov_int src_graph({{0, 1, 1}, {0, 2, 2}, {1, 2, 3}, {2, 0, 4}, {2, 1, 5}}); - size_t original_count = count_edges(source); + size_t original_count = count_edges(src_graph); std::vector> edge_list; - for (auto&& v : vertices(source)) { - for (auto&& e : edges(source, v)) { - edge_list.push_back({vertex_id(source, v), target_id(source, e), std::to_string(edge_value(source, e))}); + for (auto&& v : vertices(src_graph)) { + for (auto&& e : edges(src_graph, v)) { + edge_list.push_back({vertex_id(src_graph, v), target_id(src_graph, e), std::to_string(edge_value(src_graph, e))}); } } - vov_string target; - target.load_edges(edge_list, std::identity{}); + vov_string dst_graph; + dst_graph.load_edges(edge_list, std::identity{}); - REQUIRE(count_edges(target) == original_count); + REQUIRE(count_edges(dst_graph) == original_count); } TEST_CASE("Value conversion - map to different container with values", "[integration][6.5.5][conversion]") { - mos_int source({{"a", "b", 10}, {"b", "c", 20}}); + mos_int src_graph({{"a", "b", 10}, {"b", "c", 20}}); std::vector> edge_list; - for (auto&& v : vertices(source)) { - for (auto&& e : edges(source, v)) { - edge_list.push_back({vertex_id(source, v), target_id(source, e), "val:" + std::to_string(edge_value(source, e))}); + for (auto&& v : vertices(src_graph)) { + for (auto&& e : edges(src_graph, v)) { + edge_list.push_back({vertex_id(src_graph, v), target_id(src_graph, e), "val:" + std::to_string(edge_value(src_graph, e))}); } } - mol_string target; - target.load_edges(edge_list, std::identity{}); + mol_string dst_graph; + dst_graph.load_edges(edge_list, std::identity{}); - REQUIRE(target.size() == 3); - REQUIRE(count_edges(target) == 2); + REQUIRE(dst_graph.size() == 3); + REQUIRE(count_edges(dst_graph) == 2); } //================================================================================================== diff --git a/tests/container/dynamic_graph/test_dynamic_graph_mixed_types.cpp b/tests/container/dynamic_graph/test_dynamic_graph_mixed_types.cpp index 1da0a29..47cf22c 100644 --- a/tests/container/dynamic_graph/test_dynamic_graph_mixed_types.cpp +++ b/tests/container/dynamic_graph/test_dynamic_graph_mixed_types.cpp @@ -1,6 +1,5 @@ #include #include -#include #include #include #include @@ -12,14 +11,14 @@ using namespace graph::adj_list; using namespace graph::container; // Graph type aliases with uint64_t IDs -using vov_void = dynamic_graph>; -using mos_void = dynamic_graph>; +using vov_void = vov_graph; +using mos_void = mos_graph; using dofl_void = - dynamic_graph>; + dofl_graph; // Graph type with string IDs using mos_string = - dynamic_graph>; + mos_graph; // Generic edge counting function template @@ -283,17 +282,17 @@ TEST_CASE("Bidirectional edges across types", "[6.4.1][mixed][bidirectional]") { } TEST_CASE("Large graph across types", "[6.4.1][mixed][large]") { - std::vector> edges; + std::vector> edge_data; for (uint64_t i = 0; i < 100; ++i) { - edges.push_back({.source_id = i, .target_id = i + 1}); + edge_data.push_back({.source_id = i, .target_id = i + 1}); } vov_void g1; - g1.load_edges(edges); + g1.load_edges(edge_data); mos_void g2; - g2.load_edges(edges); + g2.load_edges(edge_data); dofl_void g3; - g3.load_edges(edges); + g3.load_edges(edge_data); REQUIRE(count_vertices(g1) == 101); REQUIRE(count_vertices(g2) == 101); @@ -305,19 +304,19 @@ TEST_CASE("Large graph across types", "[6.4.1][mixed][large]") { } TEST_CASE("Generic function with dense graph", "[6.4.1][mixed][dense]") { - std::vector> edges; + std::vector> edge_data; for (uint64_t i = 0; i < 10; ++i) { for (uint64_t j = 0; j < 10; ++j) { if (i != j) { - edges.push_back({.source_id = i, .target_id = j}); + edge_data.push_back({.source_id = i, .target_id = j}); } } } vov_void g1; - g1.load_edges(edges); + g1.load_edges(edge_data); mos_void g2; - g2.load_edges(edges); + g2.load_edges(edge_data); REQUIRE(count_vertices(g1) == 10); REQUIRE(count_vertices(g2) == 10); @@ -384,20 +383,20 @@ TEST_CASE("All graph types with isolated vertex", "[6.4.1][mixed][isolated]") { // ============================================================================ TEST_CASE("vov graph constructed from range with identity projection", "[6.4.1][range-construct][identity]") { - std::vector> edges = { + std::vector> edge_list = { {.source_id = 0, .target_id = 1}, {.source_id = 1, .target_id = 2}, {.source_id = 0, .target_id = 2}}; std::vector partitions; - vov_void g(2ul, edges, identity{}, partitions); + vov_void g(2ul, edge_list, identity{}, partitions); REQUIRE(count_vertices(g) == 3); REQUIRE(count_edges(g) == 3); } TEST_CASE("mos graph constructed from range with identity projection", "[6.4.1][range-construct][mos]") { - std::vector> edges = {{.source_id = 10, .target_id = 20}, - {.source_id = 20, .target_id = 30}}; + std::vector> edge_list = {{.source_id = 10, .target_id = 20}, + {.source_id = 20, .target_id = 30}}; std::vector partitions; - mos_void g(30ul, edges, identity{}, partitions); + mos_void g(30ul, edge_list, identity{}, partitions); REQUIRE(count_vertices(g) == 3); REQUIRE(count_edges(g) == 2); @@ -406,10 +405,10 @@ TEST_CASE("mos graph constructed from range with identity projection", "[6.4.1][ } TEST_CASE("dofl graph constructed from range with identity projection", "[6.4.1][range-construct][dofl]") { - std::vector> edges = { + std::vector> edge_list = { {.source_id = 0, .target_id = 1}, {.source_id = 1, .target_id = 2}, {.source_id = 2, .target_id = 0}}; std::vector partitions; - dofl_void g(2ul, edges, identity{}, partitions); + dofl_void g(2ul, edge_list, identity{}, partitions); REQUIRE(count_vertices(g) == 3); REQUIRE(count_edges(g) == 3); @@ -481,18 +480,18 @@ TEST_CASE("mixed construction methods coexist", "[6.4.1][range-construct][mixed- vov_void g1({{.source_id = 0, .target_id = 1}, {.source_id = 1, .target_id = 2}}); // Range with identity projection - std::vector> edges = {{.source_id = 0, .target_id = 1}, - {.source_id = 1, .target_id = 2}}; + std::vector> edge_data = {{.source_id = 0, .target_id = 1}, + {.source_id = 1, .target_id = 2}}; std::vector partitions; - mos_void g2(2ul, edges, identity{}, partitions); + mos_void g2(2ul, edge_data, identity{}, partitions); // Custom projection struct Edge { uint64_t u, v; }; - std::vector edge_data = {{0, 1}, {1, 2}}; + std::vector edge_input = {{0, 1}, {1, 2}}; auto proj = [](const Edge& e) { return copyable_edge_t{.source_id = e.u, .target_id = e.v}; }; - dofl_void g3(2ul, edge_data, proj, partitions); + dofl_void g3(2ul, edge_input, proj, partitions); // All should have same structure REQUIRE(count_edges(g1) == 2); @@ -501,9 +500,9 @@ TEST_CASE("mixed construction methods coexist", "[6.4.1][range-construct][mixed- } TEST_CASE("range construction with empty range", "[6.4.1][range-construct][empty]") { - std::vector> edges; + std::vector> edge_data; vov_void g; - g.load_edges(edges); + g.load_edges(edge_data); REQUIRE(count_vertices(g) == 0); REQUIRE(count_edges(g) == 0); diff --git a/tests/container/dynamic_graph/test_dynamic_graph_mod.cpp b/tests/container/dynamic_graph/test_dynamic_graph_mod.cpp index 1622ac5..21a685b 100644 --- a/tests/container/dynamic_graph/test_dynamic_graph_mod.cpp +++ b/tests/container/dynamic_graph/test_dynamic_graph_mod.cpp @@ -23,7 +23,6 @@ #include #include #include -#include #include #include #include @@ -40,26 +39,26 @@ using namespace graph::container; // Format: mod_EV_VV_GV (Edge Value, Vertex Value, Graph Value) // "void" means no value (using graph::void_t) using mod_void_void_void = - dynamic_graph>; + mod_graph; using mod_int_void_void = - dynamic_graph>; + mod_graph; using mod_void_int_void = - dynamic_graph>; + mod_graph; using mod_int_int_void = - dynamic_graph>; + mod_graph; using mod_void_void_int = - dynamic_graph>; -using mod_int_int_int = dynamic_graph>; + mod_graph; +using mod_int_int_int = mod_graph; // String vertex ID variants using mod_str_void_void_void = - dynamic_graph>; + mod_graph; using mod_str_int_void_void = - dynamic_graph>; + mod_graph; using mod_str_void_int_void = - dynamic_graph>; + mod_graph; using mod_str_int_int_int = - dynamic_graph>; + mod_graph; // Sourced edge variants (store source vertex ID in edge) diff --git a/tests/container/dynamic_graph/test_dynamic_graph_mofl.cpp b/tests/container/dynamic_graph/test_dynamic_graph_mofl.cpp index 439f1b0..383c6fb 100644 --- a/tests/container/dynamic_graph/test_dynamic_graph_mofl.cpp +++ b/tests/container/dynamic_graph/test_dynamic_graph_mofl.cpp @@ -19,7 +19,6 @@ #include #include #include -#include #include #include #include @@ -31,27 +30,27 @@ using namespace graph::container; // Type aliases for common test configurations with uint32_t vertex IDs using mofl_void_void_void = - dynamic_graph>; + mofl_graph; using mofl_int_void_void = - dynamic_graph>; + mofl_graph; using mofl_void_int_void = - dynamic_graph>; + mofl_graph; using mofl_int_int_void = - dynamic_graph>; + mofl_graph; using mofl_void_void_int = - dynamic_graph>; + mofl_graph; using mofl_int_int_int = - dynamic_graph>; + mofl_graph; // Type aliases with string vertex IDs (the primary use case for map containers) using mofl_str_void_void_void = - dynamic_graph>; + mofl_graph; using mofl_str_int_void_void = - dynamic_graph>; + mofl_graph; using mofl_str_void_int_void = - dynamic_graph>; + mofl_graph; using mofl_str_int_int_int = - dynamic_graph>; + mofl_graph; diff --git a/tests/container/dynamic_graph/test_dynamic_graph_mol.cpp b/tests/container/dynamic_graph/test_dynamic_graph_mol.cpp index aac8359..a64c9ef 100644 --- a/tests/container/dynamic_graph/test_dynamic_graph_mol.cpp +++ b/tests/container/dynamic_graph/test_dynamic_graph_mol.cpp @@ -22,7 +22,6 @@ #include #include #include -#include #include #include #include @@ -34,26 +33,26 @@ using namespace graph::container; // Type aliases for common test configurations with uint32_t vertex IDs using mol_void_void_void = - dynamic_graph>; + mol_graph; using mol_int_void_void = - dynamic_graph>; + mol_graph; using mol_void_int_void = - dynamic_graph>; + mol_graph; using mol_int_int_void = - dynamic_graph>; + mol_graph; using mol_void_void_int = - dynamic_graph>; -using mol_int_int_int = dynamic_graph>; + mol_graph; +using mol_int_int_int = mol_graph; // Type aliases with string vertex IDs (the primary use case for map containers) using mol_str_void_void_void = - dynamic_graph>; + mol_graph; using mol_str_int_void_void = - dynamic_graph>; + mol_graph; using mol_str_void_int_void = - dynamic_graph>; + mol_graph; using mol_str_int_int_int = - dynamic_graph>; + mol_graph; diff --git a/tests/container/dynamic_graph/test_dynamic_graph_mom.cpp b/tests/container/dynamic_graph/test_dynamic_graph_mom.cpp index 628f3c5..44ebffa 100644 --- a/tests/container/dynamic_graph/test_dynamic_graph_mom.cpp +++ b/tests/container/dynamic_graph/test_dynamic_graph_mom.cpp @@ -19,7 +19,6 @@ #include #include #include -#include #include #include #include @@ -31,27 +30,27 @@ using namespace graph::container; // Type aliases for common test configurations with uint32_t vertex IDs using mos_void_void_void = - dynamic_graph>; + mom_graph; using mos_int_void_void = - dynamic_graph>; + mom_graph; using mos_void_int_void = - dynamic_graph>; + mom_graph; using mos_int_int_void = - dynamic_graph>; + mom_graph; using mos_void_void_int = - dynamic_graph>; + mom_graph; using mos_int_int_int = - dynamic_graph>; + mom_graph; // Type aliases with string vertex IDs (the primary use case for map containers) using mos_str_void_void_void = - dynamic_graph>; + mom_graph; using mos_str_int_void_void = - dynamic_graph>; + mom_graph; using mos_str_void_int_void = - dynamic_graph>; + mom_graph; using mos_str_int_int_int = - dynamic_graph>; + mom_graph; diff --git a/tests/container/dynamic_graph/test_dynamic_graph_mos.cpp b/tests/container/dynamic_graph/test_dynamic_graph_mos.cpp index e389e7e..6feb7af 100644 --- a/tests/container/dynamic_graph/test_dynamic_graph_mos.cpp +++ b/tests/container/dynamic_graph/test_dynamic_graph_mos.cpp @@ -19,7 +19,6 @@ #include #include #include -#include #include #include #include @@ -31,26 +30,26 @@ using namespace graph::container; // Type aliases for common test configurations with uint32_t vertex IDs using mos_void_void_void = - dynamic_graph>; + mos_graph; using mos_int_void_void = - dynamic_graph>; + mos_graph; using mos_void_int_void = - dynamic_graph>; + mos_graph; using mos_int_int_void = - dynamic_graph>; + mos_graph; using mos_void_void_int = - dynamic_graph>; -using mos_int_int_int = dynamic_graph>; + mos_graph; +using mos_int_int_int = mos_graph; // Type aliases with string vertex IDs (the primary use case for map containers) using mos_str_void_void_void = - dynamic_graph>; + mos_graph; using mos_str_int_void_void = - dynamic_graph>; + mos_graph; using mos_str_void_int_void = - dynamic_graph>; + mos_graph; using mos_str_int_int_int = - dynamic_graph>; + mos_graph; diff --git a/tests/container/dynamic_graph/test_dynamic_graph_mous.cpp b/tests/container/dynamic_graph/test_dynamic_graph_mous.cpp index e490b22..092fe9d 100644 --- a/tests/container/dynamic_graph/test_dynamic_graph_mous.cpp +++ b/tests/container/dynamic_graph/test_dynamic_graph_mous.cpp @@ -20,7 +20,6 @@ #include #include #include -#include #include #include #include @@ -32,27 +31,27 @@ using namespace graph::container; // Type aliases for common test configurations with uint32_t vertex IDs using mous_void_void_void = - dynamic_graph>; + mous_graph; using mous_int_void_void = - dynamic_graph>; + mous_graph; using mous_void_int_void = - dynamic_graph>; + mous_graph; using mous_int_int_void = - dynamic_graph>; + mous_graph; using mous_void_void_int = - dynamic_graph>; + mous_graph; using mous_int_int_int = - dynamic_graph>; + mous_graph; // Type aliases with string vertex IDs (the primary use case for map containers) using mous_str_void_void_void = - dynamic_graph>; + mous_graph; using mous_str_int_void_void = - dynamic_graph>; + mous_graph; using mous_str_void_int_void = - dynamic_graph>; + mous_graph; using mous_str_int_int_int = - dynamic_graph>; + mous_graph; diff --git a/tests/container/dynamic_graph/test_dynamic_graph_mov.cpp b/tests/container/dynamic_graph/test_dynamic_graph_mov.cpp index 0092961..1d0fd5b 100644 --- a/tests/container/dynamic_graph/test_dynamic_graph_mov.cpp +++ b/tests/container/dynamic_graph/test_dynamic_graph_mov.cpp @@ -27,7 +27,6 @@ #include #include #include -#include #include #include #include @@ -39,26 +38,26 @@ using namespace graph::container; // Type aliases for common test configurations with uint32_t vertex IDs using mov_void_void_void = - dynamic_graph>; + mov_graph; using mov_int_void_void = - dynamic_graph>; + mov_graph; using mov_void_int_void = - dynamic_graph>; + mov_graph; using mov_int_int_void = - dynamic_graph>; + mov_graph; using mov_void_void_int = - dynamic_graph>; -using mov_int_int_int = dynamic_graph>; + mov_graph; +using mov_int_int_int = mov_graph; // Type aliases with string vertex IDs (the primary use case for map containers) using mov_str_void_void_void = - dynamic_graph>; + mov_graph; using mov_str_int_void_void = - dynamic_graph>; + mov_graph; using mov_str_void_int_void = - dynamic_graph>; + mov_graph; using mov_str_int_int_int = - dynamic_graph>; + mov_graph; diff --git a/tests/container/dynamic_graph/test_dynamic_graph_nonintegral_ids.cpp b/tests/container/dynamic_graph/test_dynamic_graph_nonintegral_ids.cpp index 51820c9..0eec881 100644 --- a/tests/container/dynamic_graph/test_dynamic_graph_nonintegral_ids.cpp +++ b/tests/container/dynamic_graph/test_dynamic_graph_nonintegral_ids.cpp @@ -18,7 +18,6 @@ #include #include #include -#include #include #include #include @@ -59,24 +58,24 @@ struct std::hash { // String ID graphs (ordered and unordered) using mos_string = - dynamic_graph>; + mos_graph; using mous_string = - dynamic_graph>; + mous_graph; using mos_string_ev = - dynamic_graph>; + mos_graph; // Double ID graphs -using mos_double = dynamic_graph>; -using mous_double = dynamic_graph>; -using mos_double_ev = dynamic_graph>; +using mos_double = mos_graph; +using mous_double = mous_graph; +using mos_double_ev = mos_graph; // PersonId (compound type) graphs using mos_person = - dynamic_graph>; + mos_graph; using mous_person = - dynamic_graph>; + mous_graph; using mos_person_ev = - dynamic_graph>; + mos_graph; // Helper to count edges template diff --git a/tests/container/dynamic_graph/test_dynamic_graph_stl_algorithms.cpp b/tests/container/dynamic_graph/test_dynamic_graph_stl_algorithms.cpp index ba6388e..884567d 100644 --- a/tests/container/dynamic_graph/test_dynamic_graph_stl_algorithms.cpp +++ b/tests/container/dynamic_graph/test_dynamic_graph_stl_algorithms.cpp @@ -7,7 +7,6 @@ */ #include -#include #include #include #include @@ -27,39 +26,39 @@ using namespace graph::container; //================================================================================================== // Sequential container graphs (integral VId) - void values -using vov_void = dynamic_graph>; +using vov_void = vov_graph; using dofl_void = - dynamic_graph>; -using dol_void = dynamic_graph>; + dofl_graph; +using dol_void = dol_graph; // Sequential container graphs (integral VId) - int edges using vov_int_edges = - dynamic_graph>; + vov_graph; using dofl_int_edges = - dynamic_graph>; + dofl_graph; // Sequential container graphs (integral VId) - int vertices using vov_int_verts = - dynamic_graph>; + vov_graph; using dofl_int_verts = - dynamic_graph>; + dofl_graph; // Sequential container graphs (integral VId) - int edges and vertices -using vov_int_both = dynamic_graph>; +using vov_int_both = vov_graph; using dofl_int_both = - dynamic_graph>; + dofl_graph; // Map-based graphs (string VId) - void values using mos_void = - dynamic_graph>; + mos_graph; // Map-based graphs (string VId) - int edges using mos_int_edges = - dynamic_graph>; + mos_graph; // Map-based graphs (string VId) - int vertices using mos_int_verts = - dynamic_graph>; + mos_graph; //================================================================================================== // Helper Functions @@ -208,7 +207,7 @@ TEST_CASE("for_each - sum edge values in mos graph", "[stl][6.2.1][for_each]") { REQUIRE(sum == 600); } -TEST_CASE("for_each - collect edge target IDs in vov graph", "[stl][6.2.1][for_each]") { +TEST_CASE("for_each - collect edge target_vid IDs in vov graph", "[stl][6.2.1][for_each]") { vov_void g({{0, 1}, {0, 2}, {1, 3}}); std::vector targets; @@ -399,7 +398,7 @@ TEST_CASE("for_each - nested for_each with multiple graphs", "[stl][6.2.1][for_e REQUIRE(total_edges == 5); // 2 from g1 + 3 from g2 } -TEST_CASE("for_each - maximum degree vertex", "[stl][6.2.1][for_each]") { +TEST_CASE("for_each - maximum degree_count vertex", "[stl][6.2.1][for_each]") { vov_void g({{0, 1}, {0, 2}, {0, 3}, {1, 2}, {2, 3}}); uint64_t max_degree_vertex = 0; @@ -495,7 +494,7 @@ TEST_CASE("find_if - find vertex by value predicate in mos graph", "[stl][6.2.2] REQUIRE(vertex_value(g, *found) >= 200); } -TEST_CASE("find_if - find vertex with specific degree", "[stl][6.2.2][find_if]") { +TEST_CASE("find_if - find vertex with specific degree_count", "[stl][6.2.2][find_if]") { vov_void g({{0, 1}, {0, 2}, {1, 3}, {2, 3}}); auto verts = vertices(g); @@ -513,11 +512,11 @@ TEST_CASE("find_if - find isolated vertex", "[stl][6.2.2][find_if]") { auto it = std::ranges::find_if(verts, [&g](auto&& v) { return std::ranges::distance(edges(g, v)) == 0; }); REQUIRE(it != verts.end()); - // Could find vertex 2, 3, or 4 (all have out-degree 0) + // Could find vertex 2, 3, or 4 (all have out-degree_count 0) REQUIRE(std::ranges::distance(edges(g, *it)) == 0); } -TEST_CASE("find_if - find edge by target ID in vov graph", "[stl][6.2.2][find_if]") { +TEST_CASE("find_if - find edge by target_vid ID in vov graph", "[stl][6.2.2][find_if]") { vov_void g({{0, 1}, {0, 2}, {0, 3}}); auto v = *vertices(g).begin(); @@ -528,7 +527,7 @@ TEST_CASE("find_if - find edge by target ID in vov graph", "[stl][6.2.2][find_if REQUIRE(target_id(g, *it) == 2); } -TEST_CASE("find_if - find edge by target ID in mos graph", "[stl][6.2.2][find_if]") { +TEST_CASE("find_if - find edge by target_vid ID in mos graph", "[stl][6.2.2][find_if]") { mos_void g({{"A", "B"}, {"A", "C"}, {"A", "D"}}); auto v = *vertices(g).begin(); @@ -585,7 +584,7 @@ TEST_CASE("find_if - find edge by value predicate in dofl graph", "[stl][6.2.2][ REQUIRE(edge_value(g, *it) >= 10); } -TEST_CASE("find_if - find edge with specific target value", "[stl][6.2.2][find_if]") { +TEST_CASE("find_if - find edge with specific target_vid value", "[stl][6.2.2][find_if]") { vov_int_both g({{0, 1, 0}, {0, 2, 0}, {0, 3, 0}}); // Set vertex values @@ -603,10 +602,10 @@ TEST_CASE("find_if - find edge with specific target value", "[stl][6.2.2][find_i auto edge_range = edges(g, v0); auto it = std::ranges::find_if(edge_range, [&g](auto&& e) { - auto target = target_id(g, e); + auto target_vid = target_id(g, e); // Find edge pointing to vertex with value 200 for (auto&& v : vertices(g)) { - if (vertex_id(g, v) == target) { + if (vertex_id(g, v) == target_vid) { return vertex_value(g, v) == 200; } } @@ -716,7 +715,7 @@ TEST_CASE("find_if_not - find vertex with value not matching", "[stl][6.2.2][fin REQUIRE(vertex_value(g, *it) % 4 != 0); } -TEST_CASE("any_of - check if any vertex has high degree", "[stl][6.2.2][any_of]") { +TEST_CASE("any_of - check if any vertex has high degree_count", "[stl][6.2.2][any_of]") { vov_void g({{0, 1}, {0, 2}, {0, 3}, {1, 2}}); bool has_high_degree = @@ -782,12 +781,12 @@ TEST_CASE("none_of - check if no vertex has negative value", "[stl][6.2.2][none_ REQUIRE(none_negative); } -TEST_CASE("search - find sequence of target IDs in edge list", "[stl][6.2.2][search]") { +TEST_CASE("search - find sequence of target_vid IDs in edge list", "[stl][6.2.2][search]") { vov_void g({{0, 1}, {0, 2}, {0, 3}, {0, 4}}); auto v = *vertices(g).begin(); - // Collect target IDs + // Collect target_vid IDs std::vector targets; for (auto&& e : edges(g, v)) { targets.push_back(target_id(g, e)); @@ -805,7 +804,7 @@ TEST_CASE("search - sequence not found returns end", "[stl][6.2.2][search]") { auto v = *vertices(g).begin(); - // Collect target IDs + // Collect target_vid IDs std::vector targets; for (auto&& e : edges(g, v)) { targets.push_back(target_id(g, e)); @@ -839,7 +838,7 @@ TEST_CASE("count_if - count vertices with specific property (vov)", "[stl][6.2.3 REQUIRE(count == 2); // Vertices with values 20 and 30 } -TEST_CASE("count_if - count vertices with out-degree > 0 (dofl)", "[stl][6.2.3][count_if]") { +TEST_CASE("count_if - count vertices with out-degree_count > 0 (dofl)", "[stl][6.2.3][count_if]") { dofl_void g({{0, 1}, {0, 2}, {1, 3}}); g.resize_vertices(5); @@ -849,13 +848,13 @@ TEST_CASE("count_if - count vertices with out-degree > 0 (dofl)", "[stl][6.2.3][ REQUIRE(count == 2); // Vertices 0 and 1 have edges } -TEST_CASE("count_if - count vertices by degree threshold (vov)", "[stl][6.2.3][count_if]") { +TEST_CASE("count_if - count vertices by degree_count threshold (vov)", "[stl][6.2.3][count_if]") { vov_void g({{0, 1}, {0, 2}, {0, 3}, {1, 2}}); - // Count vertices with out-degree >= 2 + // Count vertices with out-degree_count >= 2 auto count = std::ranges::count_if(vertices(g), [&g](auto&& v) { return std::ranges::distance(edges(g, v)) >= 2; }); - REQUIRE(count == 1); // Only vertex 0 has degree >= 2 (degree 3) + REQUIRE(count == 1); // Only vertex 0 has degree_count >= 2 (degree_count 3) } TEST_CASE("count_if - count vertices with ID in range (mos)", "[stl][6.2.3][count_if]") { @@ -892,12 +891,12 @@ TEST_CASE("count_if - count edges with value above threshold (vov)", "[stl][6.2. REQUIRE(count == 2); // Edges with values 20 and 30 } -TEST_CASE("count_if - count edges by target range (dofl)", "[stl][6.2.3][count_if]") { +TEST_CASE("count_if - count edges by target_vid range (dofl)", "[stl][6.2.3][count_if]") { dofl_int_edges g({{0, 1, 100}, {0, 5, 200}, {0, 10, 300}}); auto v = *vertices(g).begin(); - // Count edges with target ID >= 5 + // Count edges with target_vid ID >= 5 auto count = std::ranges::count_if(edges(g, v), [&g](auto&& e) { return target_id(g, e) >= 5; }); REQUIRE(count == 2); // Edges to vertices 5 and 10 @@ -933,7 +932,7 @@ TEST_CASE("count_if - count edges with both conditions (vov)", "[stl][6.2.3][cou auto v = *vertices(g).begin(); - // Count edges with target ID > 1 AND value >= 20 + // Count edges with target_vid ID > 1 AND value >= 20 auto count = std::ranges::count_if(edges(g, v), [&g](auto&& e) { return target_id(g, e) > 1 && edge_value(g, e) >= 20; }); @@ -967,7 +966,7 @@ TEST_CASE("count - count edges to specific target (vov)", "[stl][6.2.3][count]") auto v = *vertices(g).begin(); - // Extract target IDs + // Extract target_vid IDs std::vector targets; for (auto&& e : edges(g, v)) { targets.push_back(target_id(g, e)); @@ -986,13 +985,13 @@ TEST_CASE("count_if - count isolated vertices (dofl)", "[stl][6.2.3][count_if]") REQUIRE(count == 4); // Vertices 2, 3, 4, 5 have no outgoing edges } -TEST_CASE("count_if - count high-degree vertices (vov)", "[stl][6.2.3][count_if]") { +TEST_CASE("count_if - count high-degree_count vertices (vov)", "[stl][6.2.3][count_if]") { vov_void g({{0, 1}, {0, 2}, {0, 3}, {0, 4}, {1, 2}, {1, 3}}); - // Count vertices with out-degree >= 3 + // Count vertices with out-degree_count >= 3 auto count = std::ranges::count_if(vertices(g), [&g](auto&& v) { return std::ranges::distance(edges(g, v)) >= 3; }); - REQUIRE(count == 1); // Only vertex 0 has degree >= 3 (degree 4) + REQUIRE(count == 1); // Only vertex 0 has degree_count >= 3 (degree_count 4) } TEST_CASE("count_if - empty graph returns zero (vov)", "[stl][6.2.3][count_if]") { @@ -1012,15 +1011,15 @@ TEST_CASE("count_if - count with complex predicate (vov)", "[stl][6.2.3][count_i // Set vertex values: vertex 0 = 5, vertex 1 = 15, vertex 2 = 25, others = 0 auto verts = vertices(g); auto it = verts.begin(); - vertex_value(g, *it++) = 5; // Vertex 0: value 5, out-degree 2 - vertex_value(g, *it++) = 15; // Vertex 1: value 15, out-degree 1 - vertex_value(g, *it++) = 25; // Vertex 2: value 25, out-degree 0 + vertex_value(g, *it++) = 5; // Vertex 0: value 5, out-degree_count 2 + vertex_value(g, *it++) = 15; // Vertex 1: value 15, out-degree_count 1 + vertex_value(g, *it++) = 25; // Vertex 2: value 25, out-degree_count 0 - // Count vertices with value >= 10 AND out-degree > 0 + // Count vertices with value >= 10 AND out-degree_count > 0 auto count = std::ranges::count_if( vertices(g), [&g](auto&& v) { return vertex_value(g, v) >= 10 && std::ranges::distance(edges(g, v)) > 0; }); - REQUIRE(count == 1); // Only vertex 1 (value 15, degree 1) matches both conditions + REQUIRE(count == 1); // Only vertex 1 (value 15, degree_count 1) matches both conditions } TEST_CASE("count_if - count edges with negative values (vov)", "[stl][6.2.3][count_if]") { @@ -1098,7 +1097,7 @@ TEST_CASE("count_if - count using views::transform (vov)", "[stl][6.2.3][count_i auto v = *vertices(g).begin(); - // Transform edges to target IDs, then count those >= 5 + // Transform edges to target_vid IDs, then count those >= 5 auto targets = edges(g, v) | std::views::transform([&g](auto&& e) { return target_id(g, e); }); auto count = std::ranges::count_if(targets, [](auto tid) { return tid >= 5; }); @@ -1143,7 +1142,7 @@ TEST_CASE("count_if - count vertices with even IDs (vov)", "[stl][6.2.3][count_i REQUIRE(count == 5); // Vertices 0, 2, 4, 6, 8 } -TEST_CASE("count_if - count edges with target divisible by 3 (dofl)", "[stl][6.2.3][count_if]") { +TEST_CASE("count_if - count edges with target_vid divisible by 3 (dofl)", "[stl][6.2.3][count_if]") { dofl_void g({{0, 1}, {0, 3}, {0, 6}, {0, 7}, {0, 9}}); auto v = *vertices(g).begin(); @@ -1169,7 +1168,7 @@ TEST_CASE("transform - extract vertex IDs to vector (vov)", "[stl][6.2.4][transf REQUIRE(ids[2] == 2); } -TEST_CASE("transform - extract edge target IDs to vector (vov)", "[stl][6.2.4][transform]") { +TEST_CASE("transform - extract edge target_vid IDs to vector (vov)", "[stl][6.2.4][transform]") { vov_void g({{0, 1}, {0, 2}, {0, 3}}); auto v = *vertices(g).begin(); @@ -1256,7 +1255,7 @@ TEST_CASE("transform - filter then extract IDs (vov)", "[stl][6.2.4][transform][ REQUIRE(even_targets[1] == 4); } -TEST_CASE("transform - vertex degree to vector (dofl)", "[stl][6.2.4][transform]") { +TEST_CASE("transform - vertex degree_count to vector (dofl)", "[stl][6.2.4][transform]") { dofl_void g({{0, 1}, {0, 2}, {1, 2}, {1, 3}}); std::vector degrees; @@ -1293,7 +1292,7 @@ TEST_CASE("transform - combine vertex ID and value (vov)", "[stl][6.2.4][transfo REQUIRE(id_value_pairs[2].second == 300); } -TEST_CASE("transform - edge source and target pairs (vov)", "[stl][6.2.4][transform]") { +TEST_CASE("transform - edge source and target_vid pairs (vov)", "[stl][6.2.4][transform]") { vov_void g({{0, 1}, {0, 2}, {1, 2}}); auto v = *vertices(g).begin(); @@ -1411,11 +1410,11 @@ TEST_CASE("transform - compute vertex ID differences (vov)", "[stl][6.2.4][trans vov_void g({{0, 3}, {0, 5}, {0, 7}}); auto v = *vertices(g).begin(); - size_t source_id = vertex_id(g, v); + size_t src_vid = vertex_id(g, v); std::vector differences; std::ranges::transform(edges(g, v), std::back_inserter(differences), - [&g, source_id](auto&& e) { return target_id(g, e) - source_id; }); + [&g, src_vid](auto&& e) { return target_id(g, e) - src_vid; }); REQUIRE(differences.size() == 3); REQUIRE(differences[0] == 3); @@ -1484,7 +1483,7 @@ TEST_CASE("transform - create edge descriptors with values (dofl)", "[stl][6.2.4 dofl_int_edges g({{0, 1, 100}, {0, 2, 200}}); struct EdgeInfo { - size_t target; + size_t target_vid; int value; }; @@ -1493,11 +1492,11 @@ TEST_CASE("transform - create edge descriptors with values (dofl)", "[stl][6.2.4 std::ranges::transform(edges(g, v), std::back_inserter(edge_datas), [&g](auto&& e) { return EdgeInfo{static_cast(target_id(g, e)), edge_value(g, e)}; }); - std::ranges::sort(edge_datas, {}, &EdgeInfo::target); + std::ranges::sort(edge_datas, {}, &EdgeInfo::target_vid); REQUIRE(edge_datas.size() == 2); - REQUIRE(edge_datas[0].target == size_t(1)); + REQUIRE(edge_datas[0].target_vid == size_t(1)); REQUIRE(edge_datas[0].value == 100); - REQUIRE(edge_datas[1].target == size_t(2)); + REQUIRE(edge_datas[1].target_vid == size_t(2)); REQUIRE(edge_datas[1].value == 200); } @@ -1533,9 +1532,9 @@ TEST_CASE("transform - check if edges exist to specific targets (vov)", "[stl][6 auto v = *vertices(g).begin(); std::vector target_checks; - for (size_t target : {1UL, 2UL, 3UL, 4UL, 5UL}) { + for (size_t target_vid : {1UL, 2UL, 3UL, 4UL, 5UL}) { auto found = std::ranges::any_of(edges(g, v), - [&g, target](auto&& e) { return target_id(g, e) == static_cast(target); }); + [&g, target_vid](auto&& e) { return target_id(g, e) == static_cast(target_vid); }); target_checks.push_back(found); } @@ -1577,12 +1576,12 @@ TEST_CASE("transform - extract max edge value per vertex (vov)", "[stl][6.2.4][t std::vector max_values; std::ranges::transform(vertices(g), std::back_inserter(max_values), [&g](auto&& v) { int max_val = std::numeric_limits::min(); - bool has_edges = false; + bool has_any_edges = false; for (auto&& e : edges(g, v)) { max_val = std::max(max_val, edge_value(g, e)); - has_edges = true; + has_any_edges = true; } - return has_edges ? max_val : 0; + return has_any_edges ? max_val : 0; }); REQUIRE(max_values.size() == 4); @@ -1613,25 +1612,25 @@ TEST_CASE("transform - concatenate vertex ID with value string (vov)", "[stl][6. REQUIRE(labels[2] == "V2:300"); } -TEST_CASE("transform - compute out-degree minus in-degree (vov)", "[stl][6.2.4][transform]") { +TEST_CASE("transform - compute out-degree_count minus in-degree (vov)", "[stl][6.2.4][transform]") { vov_void g({{0, 1}, {0, 2}, {1, 2}, {2, 0}}); std::vector degree_diff; std::ranges::transform(vertices(g), std::back_inserter(degree_diff), [&g](auto&& v) { - size_t out_degree = static_cast(std::ranges::distance(edges(g, v))); + size_t out_degree_count = static_cast(std::ranges::distance(edges(g, v))); - // Count in-degree by checking all edges - size_t in_degree = 0; + // Count in-degree_count by checking all edges + size_t in_degree_count = 0; size_t v_id = vertex_id(g, v); for (auto&& u : vertices(g)) { for (auto&& e : edges(g, u)) { if (target_id(g, e) == v_id) { - ++in_degree; + ++in_degree_count; } } } - return static_cast(out_degree) - static_cast(in_degree); + return static_cast(out_degree_count) - static_cast(in_degree_count); }); REQUIRE(degree_diff.size() == 3); @@ -1674,7 +1673,7 @@ TEST_CASE("transform - map vertices with complex struct (vov)", "[stl][6.2.4][tr struct VertexData { size_t id; int value; - size_t degree; + size_t degree_count; }; std::vector vertex_data; @@ -1685,22 +1684,22 @@ TEST_CASE("transform - map vertices with complex struct (vov)", "[stl][6.2.4][tr REQUIRE(vertex_data.size() == 3); REQUIRE(vertex_data[0].id == 0); REQUIRE(vertex_data[0].value == 100); - REQUIRE(vertex_data[0].degree == 2); + REQUIRE(vertex_data[0].degree_count == 2); REQUIRE(vertex_data[1].id == 1); REQUIRE(vertex_data[1].value == 200); - REQUIRE(vertex_data[1].degree == 1); + REQUIRE(vertex_data[1].degree_count == 1); REQUIRE(vertex_data[2].id == 2); REQUIRE(vertex_data[2].value == 300); - REQUIRE(vertex_data[2].degree == 0); + REQUIRE(vertex_data[2].degree_count == 0); } //============================================================================= // Phase 6.2.5: std::ranges::sort (where applicable) -// Tests sorting of edges by target ID and vertices by value +// Tests sorting of edges by target_vid ID and vertices by value // Note: Only works with random access containers (vov, vod, mov, mod) // forward_list and list-based containers don't support random access //============================================================================= -TEST_CASE("sort edge target IDs (vov)", "[stl][6.2.5][sort]") { +TEST_CASE("sort edge target_vid IDs (vov)", "[stl][6.2.5][sort]") { using G = vov_void; G g({{0, 2}, {0, 1}, {0, 3}}); @@ -1716,7 +1715,7 @@ TEST_CASE("sort edge target IDs (vov)", "[stl][6.2.5][sort]") { REQUIRE(targets[2] == 3); } -TEST_CASE("sort edge target IDs in descending order (vov)", "[stl][6.2.5][sort]") { +TEST_CASE("sort edge target_vid IDs in descending order (vov)", "[stl][6.2.5][sort]") { using G = vov_void; G g({{0, 2}, {0, 1}, {0, 3}}); @@ -1811,12 +1810,12 @@ TEST_CASE("sort by vertex value with projection (vov)", "[stl][6.2.5][sort]") { REQUIRE(infos[2].value == 300); } -TEST_CASE("sort edge infos by target then by value (vov)", "[stl][6.2.5][sort]") { +TEST_CASE("sort edge infos by target_vid then by value (vov)", "[stl][6.2.5][sort]") { using G = vov_int_edges; G g({{0, 1, 50}, {0, 2, 30}, {0, 2, 10}, {0, 1, 20}}); struct EdgeInfo { - vertex_id_t target; + vertex_id_t target_vid; int value; auto operator<=>(const EdgeInfo&) const = default; @@ -1830,13 +1829,13 @@ TEST_CASE("sort edge infos by target then by value (vov)", "[stl][6.2.5][sort]") std::ranges::sort(infos); REQUIRE(infos.size() == 4); - REQUIRE(infos[0].target == 1); + REQUIRE(infos[0].target_vid == 1); REQUIRE(infos[0].value == 20); - REQUIRE(infos[1].target == 1); + REQUIRE(infos[1].target_vid == 1); REQUIRE(infos[1].value == 50); - REQUIRE(infos[2].target == 2); + REQUIRE(infos[2].target_vid == 2); REQUIRE(infos[2].value == 10); - REQUIRE(infos[3].target == 2); + REQUIRE(infos[3].target_vid == 2); REQUIRE(infos[3].value == 30); } @@ -1851,9 +1850,9 @@ TEST_CASE("sort degrees in ascending order (vov)", "[stl][6.2.5][sort]") { std::ranges::sort(degrees); REQUIRE(degrees.size() == 3); - REQUIRE(degrees[0] == 0); // vertex 2 has out-degree 0 - REQUIRE(degrees[1] == 1); // vertex 1 has out-degree 1 - REQUIRE(degrees[2] == 2); // vertex 0 has out-degree 2 + REQUIRE(degrees[0] == 0); // vertex 2 has out-degree_count 0 + REQUIRE(degrees[1] == 1); // vertex 1 has out-degree_count 1 + REQUIRE(degrees[2] == 2); // vertex 0 has out-degree_count 2 } TEST_CASE("sort combined vertex ID and value pairs (vov)", "[stl][6.2.5][sort]") { @@ -1915,7 +1914,7 @@ TEST_CASE("stable_sort preserves relative order of equal elements (vov)", "[stl] struct EdgeData { size_t insertion_order; - vertex_id_t target; + vertex_id_t target_vid; int value; }; @@ -1931,13 +1930,13 @@ TEST_CASE("stable_sort preserves relative order of equal elements (vov)", "[stl] REQUIRE(data.size() == 5); // All edges with value 100 should appear first, in original order REQUIRE(data[0].value == 100); - REQUIRE(data[0].target == 1); + REQUIRE(data[0].target_vid == 1); REQUIRE(data[0].insertion_order == 0); REQUIRE(data[1].value == 100); - REQUIRE(data[1].target == 3); + REQUIRE(data[1].target_vid == 3); REQUIRE(data[1].insertion_order == 2); REQUIRE(data[2].value == 100); - REQUIRE(data[2].target == 5); + REQUIRE(data[2].target_vid == 5); REQUIRE(data[2].insertion_order == 4); REQUIRE(data[3].value == 200); REQUIRE(data[4].value == 300); @@ -2053,7 +2052,7 @@ TEST_CASE("sort with both vertex and edge values (vov)", "[stl][6.2.5][sort]") { struct GraphData { uint64_t vid; int vval; - uint64_t target; + uint64_t target_vid; int eval; }; @@ -2149,7 +2148,7 @@ TEST_CASE("views::transform on vertices to extract IDs (vov)", "[stl][6.2.6][vie REQUIRE(id_vec[3] == 3); } -TEST_CASE("views::transform on edges to extract target IDs (vov)", "[stl][6.2.6][views]") { +TEST_CASE("views::transform on edges to extract target_vid IDs (vov)", "[stl][6.2.6][views]") { using G = vov_void; G g({{0, 1}, {0, 2}, {0, 3}}); @@ -2442,7 +2441,7 @@ TEST_CASE("views::transform with complex lambda (vov)", "[stl][6.2.6][views]") { struct EdgeInfo { uint64_t source; - uint64_t target; + uint64_t target_vid; int value; int doubled; }; @@ -2453,14 +2452,14 @@ TEST_CASE("views::transform with complex lambda (vov)", "[stl][6.2.6][views]") { }); std::vector infos(result.begin(), result.end()); - std::ranges::sort(infos, [](const auto& a, const auto& b) { return a.target < b.target; }); + std::ranges::sort(infos, [](const auto& a, const auto& b) { return a.target_vid < b.target_vid; }); REQUIRE(infos.size() == 2); REQUIRE(infos[0].source == 0); - REQUIRE(infos[0].target == 1); + REQUIRE(infos[0].target_vid == 1); REQUIRE(infos[0].value == 10); REQUIRE(infos[0].doubled == 20); - REQUIRE(infos[1].target == 2); + REQUIRE(infos[1].target_vid == 2); REQUIRE(infos[1].value == 20); REQUIRE(infos[1].doubled == 40); } @@ -2639,7 +2638,7 @@ TEST_CASE("sum of all degrees equals edge count (vov)", "[stl][6.2.7][accumulate REQUIRE(edge_count == 5); } -TEST_CASE("find max degree vertex (vov)", "[stl][6.2.7][accumulate]") { +TEST_CASE("find max degree_count vertex (vov)", "[stl][6.2.7][accumulate]") { using G = vov_void; G g({{0, 1}, {0, 2}, {0, 3}, {1, 2}, {2, 3}}); @@ -2647,9 +2646,9 @@ TEST_CASE("find max degree vertex (vov)", "[stl][6.2.7][accumulate]") { size_t max_degree = 0; for (auto&& v : vertices(g)) { - size_t degree = static_cast(std::ranges::distance(edges(g, v))); - if (degree > max_degree) { - max_degree = degree; + size_t degree_count = static_cast(std::ranges::distance(edges(g, v))); + if (degree_count > max_degree) { + max_degree = degree_count; max_degree_id = vertex_id(g, v); } } @@ -2658,7 +2657,7 @@ TEST_CASE("find max degree vertex (vov)", "[stl][6.2.7][accumulate]") { REQUIRE(max_degree == 3); } -TEST_CASE("find min degree vertex (vov)", "[stl][6.2.7][accumulate]") { +TEST_CASE("find min degree_count vertex (vov)", "[stl][6.2.7][accumulate]") { using G = vov_void; G g({{0, 1}, {0, 2}, {1, 2}, {2, 3}}); @@ -2666,9 +2665,9 @@ TEST_CASE("find min degree vertex (vov)", "[stl][6.2.7][accumulate]") { size_t min_degree = std::numeric_limits::max(); for (auto&& v : vertices(g)) { - size_t degree = static_cast(std::ranges::distance(edges(g, v))); - if (degree < min_degree) { - min_degree = degree; + size_t degree_count = static_cast(std::ranges::distance(edges(g, v))); + if (degree_count < min_degree) { + min_degree = degree_count; min_degree_id = vertex_id(g, v); } } @@ -2725,7 +2724,7 @@ TEST_CASE("find edge with max value (vov)", "[stl][6.2.7][accumulate]") { struct EdgeRef { uint64_t source; - uint64_t target; + uint64_t target_vid; int value; }; @@ -2742,7 +2741,7 @@ TEST_CASE("find edge with max value (vov)", "[stl][6.2.7][accumulate]") { } REQUIRE(max_edge.source == 0); - REQUIRE(max_edge.target == 2); + REQUIRE(max_edge.target_vid == 2); REQUIRE(max_edge.value == 50); } @@ -2807,7 +2806,7 @@ TEST_CASE("product of vertex values (vov)", "[stl][6.2.7][accumulate]") { REQUIRE(product == 30); // 2 * 3 * 5 } -TEST_CASE("count vertices with degree > threshold (vov)", "[stl][6.2.7][accumulate]") { +TEST_CASE("count vertices with degree_count > threshold (vov)", "[stl][6.2.7][accumulate]") { using G = vov_void; G g({{0, 1}, {0, 2}, {0, 3}, {1, 2}, {2, 3}}); @@ -2818,7 +2817,7 @@ TEST_CASE("count vertices with degree > threshold (vov)", "[stl][6.2.7][accumula } } - REQUIRE(count == 1); // vertex 0 has degree 3 + REQUIRE(count == 1); // vertex 0 has degree_count 3 } TEST_CASE("sum vertex values with filter (vov)", "[stl][6.2.7][accumulate]") { diff --git a/tests/container/dynamic_graph/test_dynamic_graph_transformations.cpp b/tests/container/dynamic_graph/test_dynamic_graph_transformations.cpp index 1f20cbd..a43163a 100644 --- a/tests/container/dynamic_graph/test_dynamic_graph_transformations.cpp +++ b/tests/container/dynamic_graph/test_dynamic_graph_transformations.cpp @@ -18,7 +18,6 @@ #include #include -#include #include #include #include @@ -36,15 +35,15 @@ using namespace graph::adj_list; using namespace graph::container; // Type aliases for testing -using vov_void = dynamic_graph>; +using vov_void = vov_graph; using mos_void = - dynamic_graph>; + mos_graph; using dofl_void = - dynamic_graph>; + dofl_graph; -using dov_void = dynamic_graph>; +using dov_void = dov_graph; // ============================================================================ // Generic Transformation Functions (CPO-based) @@ -78,17 +77,17 @@ G extract_subgraph(const G& g, const std::vector& ve std::vector> subgraph_edges; for (auto&& v : vertices(g)) { - VId source_id = vertex_id(g, v); - if (included_vertices.contains(source_id)) { + VId src_vid = vertex_id(g, v); + if (included_vertices.contains(src_vid)) { for (auto&& e : edges(g, v)) { VId target_id_val = target_id(g, e); if (included_vertices.contains(target_id_val)) { if constexpr (std::is_integral_v) { // Remap IDs for integral types - subgraph_edges.push_back({id_mapping[source_id], id_mapping[target_id_val]}); + subgraph_edges.push_back({id_mapping[src_vid], id_mapping[target_id_val]}); } else { // Preserve string IDs - subgraph_edges.push_back({source_id, target_id_val}); + subgraph_edges.push_back({src_vid, target_id_val}); } } } @@ -142,11 +141,11 @@ G reverse_edges(const G& g) { // Collect all edges and reverse them std::vector> reversed_edges; for (auto&& v : vertices(g)) { - VId source_id = vertex_id(g, v); + VId src_vid = vertex_id(g, v); for (auto&& e : edges(g, v)) { VId target_id_val = target_id(g, e); // Reverse: target becomes source, source becomes target - reversed_edges.push_back({target_id_val, source_id}); + reversed_edges.push_back({target_id_val, src_vid}); } } @@ -171,11 +170,11 @@ G filter_edges(const G& g, Pred predicate) { // Collect edges that satisfy the predicate std::vector> filtered_edges; for (auto&& v : vertices(g)) { - VId source_id = vertex_id(g, v); + VId src_vid = vertex_id(g, v); for (auto&& e : edges(g, v)) { VId target_id_val = target_id(g, e); - if (predicate(source_id, target_id_val)) { - filtered_edges.push_back({source_id, target_id_val}); + if (predicate(src_vid, target_id_val)) { + filtered_edges.push_back({src_vid, target_id_val}); } } } diff --git a/tests/container/dynamic_graph/test_dynamic_graph_traversal_helpers.cpp b/tests/container/dynamic_graph/test_dynamic_graph_traversal_helpers.cpp index b76f692..9ac6962 100644 --- a/tests/container/dynamic_graph/test_dynamic_graph_traversal_helpers.cpp +++ b/tests/container/dynamic_graph/test_dynamic_graph_traversal_helpers.cpp @@ -18,7 +18,6 @@ #include #include -#include #include #include #include @@ -33,18 +32,18 @@ using namespace graph::adj_list; using namespace graph::container; // Type aliases for testing -using vov_void = dynamic_graph>; +using vov_void = vov_graph; using mos_void = - dynamic_graph>; + mos_graph; using dofl_void = - dynamic_graph>; + dofl_graph; using mous_void = - dynamic_graph>; + mous_graph; -using dov_void = dynamic_graph>; +using dov_void = dov_graph; // ============================================================================ // Generic Traversal Helper Functions (CPO-based) @@ -123,16 +122,16 @@ bool is_isolated(const G& g, const typename G::vertex_id_type& uid) { * @brief Count the number of self-loops in the graph * @tparam G Graph type * @param g The graph - * @return Number of edges where source_id == target_id + * @return Number of edges where src_vid == target_id */ template size_t count_self_loops(const G& g) { size_t count = 0; for (auto&& vertex : vertices(g)) { - auto source_id = vertex_id(g, vertex); + auto src_vid = vertex_id(g, vertex); for (auto&& edge : edges(g, vertex)) { - if (target_id(g, edge) == source_id) { + if (target_id(g, edge) == src_vid) { ++count; } } diff --git a/tests/container/dynamic_graph/test_dynamic_graph_type_erasure.cpp b/tests/container/dynamic_graph/test_dynamic_graph_type_erasure.cpp index e44985f..0dbf934 100644 --- a/tests/container/dynamic_graph/test_dynamic_graph_type_erasure.cpp +++ b/tests/container/dynamic_graph/test_dynamic_graph_type_erasure.cpp @@ -1,6 +1,5 @@ #include #include -#include #include #include #include @@ -95,10 +94,10 @@ std::unique_ptr::vertex_id_type>> mak } // Test fixtures -using vov_void = dynamic_graph>; -using mos_void = dynamic_graph>; +using vov_void = vov_graph; +using mos_void = mos_graph; using dofl_void = - dynamic_graph>; + dofl_graph; TEST_CASE("graph_view wraps empty graph", "[6.3.5][type-erasure][empty]") { vov_void g; @@ -160,13 +159,13 @@ TEST_CASE("graph_view get_edges returns all edges", "[6.3.5][type-erasure][get-e vov_void g({{0, 1}, {1, 0}}); auto view = make_graph_view(g); - auto edges = view->get_edges(); + auto edge_list = view->get_edges(); - REQUIRE(edges.size() == 2); + REQUIRE(edge_list.size() == 2); - std::sort(edges.begin(), edges.end()); - REQUIRE(edges[0] == std::pair{0ul, 1ul}); - REQUIRE(edges[1] == std::pair{1ul, 0ul}); + std::sort(edge_list.begin(), edge_list.end()); + REQUIRE(edge_list[0] == std::pair{0ul, 1ul}); + REQUIRE(edge_list[1] == std::pair{1ul, 0ul}); } TEST_CASE("graph_view with self-loop", "[6.3.5][type-erasure][self-loop]") { @@ -199,8 +198,8 @@ TEST_CASE("graph_view wraps dofl graph", "[6.3.5][type-erasure][dofl]") { REQUIRE(view->num_vertices() == 3); REQUIRE(view->num_edges() == 3); - auto edges = view->get_edges(); - REQUIRE(edges.size() == 3); + auto edge_list = view->get_edges(); + REQUIRE(edge_list.size() == 3); } TEST_CASE("multiple graph_views in container", "[6.3.5][type-erasure][container]") { @@ -299,8 +298,8 @@ TEST_CASE("graph_view with complex graph structure", "[6.3.5][type-erasure][comp REQUIRE(view->num_vertices() == 5); REQUIRE(view->num_edges() == 6); - auto edges = view->get_edges(); - REQUIRE(edges.size() == 6); + auto edge_list = view->get_edges(); + REQUIRE(edge_list.size() == 6); auto ids = view->get_vertex_ids(); REQUIRE(ids.size() == 5); @@ -314,8 +313,8 @@ TEST_CASE("graph_view empty edge list", "[6.3.5][type-erasure][no-edges]") { REQUIRE(view->num_vertices() == 3); REQUIRE(view->num_edges() == 2); - auto edges = view->get_edges(); - REQUIRE(edges.size() == 2); + auto edge_list = view->get_edges(); + REQUIRE(edge_list.size() == 2); } TEST_CASE("graph_view multiple self-loops", "[6.3.5][type-erasure][multi-self-loops]") { diff --git a/tests/container/dynamic_graph/test_dynamic_graph_uod.cpp b/tests/container/dynamic_graph/test_dynamic_graph_uod.cpp index db89a0c..438ad86 100644 --- a/tests/container/dynamic_graph/test_dynamic_graph_uod.cpp +++ b/tests/container/dynamic_graph/test_dynamic_graph_uod.cpp @@ -25,7 +25,6 @@ #include #include #include -#include #include #include #include @@ -37,26 +36,26 @@ using namespace graph::container; // Type aliases for common test configurations with uint32_t vertex IDs using uod_void_void_void = - dynamic_graph>; + uod_graph; using uod_int_void_void = - dynamic_graph>; + uod_graph; using uod_void_int_void = - dynamic_graph>; + uod_graph; using uod_int_int_void = - dynamic_graph>; + uod_graph; using uod_void_void_int = - dynamic_graph>; -using uod_int_int_int = dynamic_graph>; + uod_graph; +using uod_int_int_int = uod_graph; // Type aliases with string vertex IDs (a common use case for unordered_map containers) using uod_str_void_void_void = - dynamic_graph>; + uod_graph; using uod_str_int_void_void = - dynamic_graph>; + uod_graph; using uod_str_void_int_void = - dynamic_graph>; + uod_graph; using uod_str_int_int_int = - dynamic_graph>; + uod_graph; diff --git a/tests/container/dynamic_graph/test_dynamic_graph_uofl.cpp b/tests/container/dynamic_graph/test_dynamic_graph_uofl.cpp index d8148c8..4bf9992 100644 --- a/tests/container/dynamic_graph/test_dynamic_graph_uofl.cpp +++ b/tests/container/dynamic_graph/test_dynamic_graph_uofl.cpp @@ -25,7 +25,6 @@ #include #include #include -#include #include #include #include @@ -37,27 +36,27 @@ using namespace graph::container; // Type aliases for common test configurations with uint32_t vertex IDs using uofl_void_void_void = - dynamic_graph>; + uofl_graph; using uofl_int_void_void = - dynamic_graph>; + uofl_graph; using uofl_void_int_void = - dynamic_graph>; + uofl_graph; using uofl_int_int_void = - dynamic_graph>; + uofl_graph; using uofl_void_void_int = - dynamic_graph>; + uofl_graph; using uofl_int_int_int = - dynamic_graph>; + uofl_graph; // Type aliases with string vertex IDs (a common use case for unordered_map containers) using uofl_str_void_void_void = - dynamic_graph>; + uofl_graph; using uofl_str_int_void_void = - dynamic_graph>; + uofl_graph; using uofl_str_void_int_void = - dynamic_graph>; + uofl_graph; using uofl_str_int_int_int = - dynamic_graph>; + uofl_graph; diff --git a/tests/container/dynamic_graph/test_dynamic_graph_uol.cpp b/tests/container/dynamic_graph/test_dynamic_graph_uol.cpp index e14c045..dac2b54 100644 --- a/tests/container/dynamic_graph/test_dynamic_graph_uol.cpp +++ b/tests/container/dynamic_graph/test_dynamic_graph_uol.cpp @@ -25,7 +25,6 @@ #include #include #include -#include #include #include #include @@ -37,26 +36,26 @@ using namespace graph::container; // Type aliases for common test configurations with uint32_t vertex IDs using uol_void_void_void = - dynamic_graph>; + uol_graph; using uol_int_void_void = - dynamic_graph>; + uol_graph; using uol_void_int_void = - dynamic_graph>; + uol_graph; using uol_int_int_void = - dynamic_graph>; + uol_graph; using uol_void_void_int = - dynamic_graph>; -using uol_int_int_int = dynamic_graph>; + uol_graph; +using uol_int_int_int = uol_graph; // Type aliases with string vertex IDs (a common use case for unordered_map containers) using uol_str_void_void_void = - dynamic_graph>; + uol_graph; using uol_str_int_void_void = - dynamic_graph>; + uol_graph; using uol_str_void_int_void = - dynamic_graph>; + uol_graph; using uol_str_int_int_int = - dynamic_graph>; + uol_graph; diff --git a/tests/container/dynamic_graph/test_dynamic_graph_uos.cpp b/tests/container/dynamic_graph/test_dynamic_graph_uos.cpp index 19b7e36..cc8afc3 100644 --- a/tests/container/dynamic_graph/test_dynamic_graph_uos.cpp +++ b/tests/container/dynamic_graph/test_dynamic_graph_uos.cpp @@ -20,7 +20,6 @@ #include #include #include -#include #include #include #include @@ -32,26 +31,26 @@ using namespace graph::container; // Type aliases for common test configurations with uint32_t vertex IDs using uos_void_void_void = - dynamic_graph>; + uos_graph; using uos_int_void_void = - dynamic_graph>; + uos_graph; using uos_void_int_void = - dynamic_graph>; + uos_graph; using uos_int_int_void = - dynamic_graph>; + uos_graph; using uos_void_void_int = - dynamic_graph>; -using uos_int_int_int = dynamic_graph>; + uos_graph; +using uos_int_int_int = uos_graph; // Type aliases with string vertex IDs (the primary use case for unordered_map containers) using uos_str_void_void_void = - dynamic_graph>; + uos_graph; using uos_str_int_void_void = - dynamic_graph>; + uos_graph; using uos_str_void_int_void = - dynamic_graph>; + uos_graph; using uos_str_int_int_int = - dynamic_graph>; + uos_graph; @@ -537,13 +536,13 @@ TEST_CASE("uos graph iteration", "[dynamic_graph][uos][iteration]") { // unordered_map does NOT guarantee order (unlike map) // Just verify all vertices are present REQUIRE(vertex_ids.size() == 7); // 1, 2, 3, 4, 5, 6, 7 - REQUIRE(std::find(vertex_ids.begin(), vertex_ids.end(), 1) != vertex_ids.end()); - REQUIRE(std::find(vertex_ids.begin(), vertex_ids.end(), 2) != vertex_ids.end()); - REQUIRE(std::find(vertex_ids.begin(), vertex_ids.end(), 3) != vertex_ids.end()); - REQUIRE(std::find(vertex_ids.begin(), vertex_ids.end(), 4) != vertex_ids.end()); - REQUIRE(std::find(vertex_ids.begin(), vertex_ids.end(), 5) != vertex_ids.end()); - REQUIRE(std::find(vertex_ids.begin(), vertex_ids.end(), 6) != vertex_ids.end()); - REQUIRE(std::find(vertex_ids.begin(), vertex_ids.end(), 7) != vertex_ids.end()); + REQUIRE(std::find(vertex_ids.begin(), vertex_ids.end(), 1u) != vertex_ids.end()); + REQUIRE(std::find(vertex_ids.begin(), vertex_ids.end(), 2u) != vertex_ids.end()); + REQUIRE(std::find(vertex_ids.begin(), vertex_ids.end(), 3u) != vertex_ids.end()); + REQUIRE(std::find(vertex_ids.begin(), vertex_ids.end(), 4u) != vertex_ids.end()); + REQUIRE(std::find(vertex_ids.begin(), vertex_ids.end(), 5u) != vertex_ids.end()); + REQUIRE(std::find(vertex_ids.begin(), vertex_ids.end(), 6u) != vertex_ids.end()); + REQUIRE(std::find(vertex_ids.begin(), vertex_ids.end(), 7u) != vertex_ids.end()); } } diff --git a/tests/container/dynamic_graph/test_dynamic_graph_uous.cpp b/tests/container/dynamic_graph/test_dynamic_graph_uous.cpp index e5db30f..43e952b 100644 --- a/tests/container/dynamic_graph/test_dynamic_graph_uous.cpp +++ b/tests/container/dynamic_graph/test_dynamic_graph_uous.cpp @@ -20,7 +20,6 @@ #include #include #include -#include #include #include #include @@ -32,27 +31,27 @@ using namespace graph::container; // Type aliases for common test configurations with uint32_t vertex IDs using uous_void_void_void = - dynamic_graph>; + uous_graph; using uous_int_void_void = - dynamic_graph>; + uous_graph; using uous_void_int_void = - dynamic_graph>; + uous_graph; using uous_int_int_void = - dynamic_graph>; + uous_graph; using uous_void_void_int = - dynamic_graph>; + uous_graph; using uous_int_int_int = - dynamic_graph>; + uous_graph; // Type aliases with string vertex IDs (the primary use case for map containers) using uous_str_void_void_void = - dynamic_graph>; + uous_graph; using uous_str_int_void_void = - dynamic_graph>; + uous_graph; using uous_str_void_int_void = - dynamic_graph>; + uous_graph; using uous_str_int_int_int = - dynamic_graph>; + uous_graph; diff --git a/tests/container/dynamic_graph/test_dynamic_graph_uov.cpp b/tests/container/dynamic_graph/test_dynamic_graph_uov.cpp index 0bf8c75..66a93b6 100644 --- a/tests/container/dynamic_graph/test_dynamic_graph_uov.cpp +++ b/tests/container/dynamic_graph/test_dynamic_graph_uov.cpp @@ -25,7 +25,6 @@ #include #include #include -#include #include #include #include @@ -37,26 +36,26 @@ using namespace graph::container; // Type aliases for common test configurations with uint32_t vertex IDs using uov_void_void_void = - dynamic_graph>; + uov_graph; using uov_int_void_void = - dynamic_graph>; + uov_graph; using uov_void_int_void = - dynamic_graph>; + uov_graph; using uov_int_int_void = - dynamic_graph>; + uov_graph; using uov_void_void_int = - dynamic_graph>; -using uov_int_int_int = dynamic_graph>; + uov_graph; +using uov_int_int_int = uov_graph; // Type aliases with string vertex IDs (a common use case for unordered_map containers) using uov_str_void_void_void = - dynamic_graph>; + uov_graph; using uov_str_int_void_void = - dynamic_graph>; + uov_graph; using uov_str_void_int_void = - dynamic_graph>; + uov_graph; using uov_str_int_int_int = - dynamic_graph>; + uov_graph; diff --git a/tests/container/dynamic_graph/test_dynamic_graph_validation.cpp b/tests/container/dynamic_graph/test_dynamic_graph_validation.cpp index 5083f5d..acaad50 100644 --- a/tests/container/dynamic_graph/test_dynamic_graph_validation.cpp +++ b/tests/container/dynamic_graph/test_dynamic_graph_validation.cpp @@ -17,7 +17,6 @@ #include #include -#include #include #include #include @@ -34,15 +33,15 @@ using namespace graph::adj_list; using namespace graph::container; // Type aliases for testing -using vov_void = dynamic_graph>; +using vov_void = vov_graph; using mos_void = - dynamic_graph>; + mos_graph; using dofl_void = - dynamic_graph>; + dofl_graph; -using dov_void = dynamic_graph>; +using dov_void = dov_graph; // ============================================================================ // Generic Validation Functions (CPO-based, simplified) @@ -143,9 +142,9 @@ bool is_weakly_connected(const G& g) { undirected_adj[vid]; // Ensure all vertices are in the map for (auto&& e : edges(g, v)) { - VId target = target_id(g, e); - undirected_adj[vid].insert(target); - undirected_adj[target].insert(vid); // Add reverse edge + VId target_vid = target_id(g, e); + undirected_adj[vid].insert(target_vid); + undirected_adj[target_vid].insert(vid); // Add reverse edge } } diff --git a/tests/container/dynamic_graph/test_dynamic_graph_vod.cpp b/tests/container/dynamic_graph/test_dynamic_graph_vod.cpp index f7423f3..781b3c1 100644 --- a/tests/container/dynamic_graph/test_dynamic_graph_vod.cpp +++ b/tests/container/dynamic_graph/test_dynamic_graph_vod.cpp @@ -19,7 +19,6 @@ #include #include #include -#include #include #include #include @@ -32,16 +31,16 @@ using namespace graph::container; // Type aliases for common test configurations using vod_void_void_void = - dynamic_graph>; + vod_graph; using vod_int_void_void = - dynamic_graph>; + vod_graph; using vod_void_int_void = - dynamic_graph>; + vod_graph; using vod_int_int_void = - dynamic_graph>; + vod_graph; using vod_void_void_int = - dynamic_graph>; -using vod_int_int_int = dynamic_graph>; + vod_graph; +using vod_int_int_int = vod_graph; using vod_string_string_string = dynamic_graph>; + using graph_t = vod_graph; graph_t g(100); REQUIRE(g.graph_value() == 100); } SECTION("with void vertex value") { - using graph_t = dynamic_graph>; + using graph_t = vod_graph; graph_t g(100); REQUIRE(g.graph_value() == 100); } SECTION("with void graph value") { - using graph_t = dynamic_graph>; + using graph_t = vod_graph; graph_t g; REQUIRE(g.size() == 0); } @@ -403,19 +402,19 @@ TEST_CASE("vod value types", "[vod][value_types]") { } SECTION("with string edge value type") { - using graph_t = dynamic_graph>; + using graph_t = vod_graph; graph_t g; REQUIRE(g.size() == 0); } SECTION("with string vertex value type") { - using graph_t = dynamic_graph>; + using graph_t = vod_graph; graph_t g; REQUIRE(g.size() == 0); } SECTION("with string graph value type") { - using graph_t = dynamic_graph>; + using graph_t = vod_graph; graph_t g(std::string("test")); REQUIRE(g.graph_value() == "test"); } @@ -433,32 +432,32 @@ TEST_CASE("vod value types", "[vod][value_types]") { TEST_CASE("vod vertex ID types", "[vod][vertex_id]") { SECTION("with uint32_t vertex id") { using graph_t = - dynamic_graph>; + vod_graph; graph_t g; REQUIRE(g.size() == 0); } SECTION("with uint64_t vertex id") { using graph_t = - dynamic_graph>; + vod_graph; graph_t g; REQUIRE(g.size() == 0); } SECTION("with int32_t vertex id") { - using graph_t = dynamic_graph>; + using graph_t = vod_graph; graph_t g; REQUIRE(g.size() == 0); } SECTION("with int8_t vertex id") { - using graph_t = dynamic_graph>; + using graph_t = vod_graph; graph_t g; REQUIRE(g.size() == 0); } SECTION("with int vertex id") { - using graph_t = dynamic_graph>; + using graph_t = vod_graph; graph_t g; REQUIRE(g.size() == 0); } @@ -875,7 +874,7 @@ TEST_CASE("vod load_vertices", "[dynamic_graph][vod][load_vertices]") { } SECTION("with custom projection from struct") { - using G2 = dynamic_graph>; + using G2 = vod_graph; using vertex_data2 = copyable_vertex_t; struct Person { @@ -1012,7 +1011,7 @@ TEST_CASE("vod load_edges", "[dynamic_graph][vod][load_edges]") { } SECTION("with custom projection") { - using G2 = dynamic_graph>; + using G2 = vod_graph; using vertex_data2 = copyable_vertex_t; using edge_data2 = copyable_edge_t; diff --git a/tests/container/dynamic_graph/test_dynamic_graph_vofl.cpp b/tests/container/dynamic_graph/test_dynamic_graph_vofl.cpp index e4d38e6..65d7ca5 100644 --- a/tests/container/dynamic_graph/test_dynamic_graph_vofl.cpp +++ b/tests/container/dynamic_graph/test_dynamic_graph_vofl.cpp @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include @@ -22,17 +21,17 @@ using namespace graph::container; // Type aliases for common test configurations using vofl_void_void_void = - dynamic_graph>; + vofl_graph; using vofl_int_void_void = - dynamic_graph>; + vofl_graph; using vofl_void_int_void = - dynamic_graph>; + vofl_graph; using vofl_int_int_void = - dynamic_graph>; + vofl_graph; using vofl_void_void_int = - dynamic_graph>; + vofl_graph; using vofl_int_int_int = - dynamic_graph>; + vofl_graph; using vofl_string_string_string = dynamic_graph>; + using graph_t = vofl_graph; graph_t g(100); REQUIRE(g.graph_value() == 100); } SECTION("with void vertex value") { - using graph_t = dynamic_graph>; + using graph_t = vofl_graph; graph_t g(100); REQUIRE(g.graph_value() == 100); } SECTION("with void graph value") { - using graph_t = dynamic_graph>; + using graph_t = vofl_graph; graph_t g; REQUIRE(g.size() == 0); } @@ -523,19 +522,19 @@ TEST_CASE("vofl value_types", "[dynamic_graph][vofl][value_types]") { } SECTION("with string edge value type") { - using graph_t = dynamic_graph>; + using graph_t = vofl_graph; graph_t g; REQUIRE(g.size() == 0); } SECTION("with string vertex value type") { - using graph_t = dynamic_graph>; + using graph_t = vofl_graph; graph_t g; REQUIRE(g.size() == 0); } SECTION("with string graph value type") { - using graph_t = dynamic_graph>; + using graph_t = vofl_graph; graph_t g(std::string("test")); REQUIRE(g.graph_value() == "test"); } @@ -553,33 +552,33 @@ TEST_CASE("vofl value_types", "[dynamic_graph][vofl][value_types]") { TEST_CASE("vofl vertex_id", "[dynamic_graph][vofl][vertex_id]") { SECTION("with uint32_t vertex id") { using graph_t = - dynamic_graph>; + vofl_graph; graph_t g; REQUIRE(g.size() == 0); } SECTION("with uint64_t vertex id") { using graph_t = - dynamic_graph>; + vofl_graph; graph_t g; REQUIRE(g.size() == 0); } SECTION("with int32_t vertex id") { using graph_t = - dynamic_graph>; + vofl_graph; graph_t g; REQUIRE(g.size() == 0); } SECTION("with int8_t vertex id") { - using graph_t = dynamic_graph>; + using graph_t = vofl_graph; graph_t g; REQUIRE(g.size() == 0); } SECTION("with int vertex id") { - using graph_t = dynamic_graph>; + using graph_t = vofl_graph; graph_t g; REQUIRE(g.size() == 0); } @@ -995,7 +994,7 @@ TEST_CASE("vofl load_vertices", "[dynamic_graph][vofl][load_vertices]") { } SECTION("custom projection - load with projection from struct") { - using G = dynamic_graph>; + using G = vofl_graph; using vertex_data = copyable_vertex_t; struct Person { uint32_t id; @@ -1140,7 +1139,7 @@ TEST_CASE("vofl load_edges", "[dynamic_graph][vofl][load_edges]") { } SECTION("custom projection - load with projection from custom struct") { - using G = dynamic_graph>; + using G = vofl_graph; using vertex_data = copyable_vertex_t; using edge_data = copyable_edge_t; struct Edge { diff --git a/tests/container/dynamic_graph/test_dynamic_graph_vol.cpp b/tests/container/dynamic_graph/test_dynamic_graph_vol.cpp index faee524..ad6c911 100644 --- a/tests/container/dynamic_graph/test_dynamic_graph_vol.cpp +++ b/tests/container/dynamic_graph/test_dynamic_graph_vol.cpp @@ -12,7 +12,6 @@ #include #include #include -#include #include #include #include @@ -24,16 +23,16 @@ using namespace graph::container; // Type aliases for common test configurations using vol_void_void_void = - dynamic_graph>; + vol_graph; using vol_int_void_void = - dynamic_graph>; + vol_graph; using vol_void_int_void = - dynamic_graph>; + vol_graph; using vol_int_int_void = - dynamic_graph>; + vol_graph; using vol_void_void_int = - dynamic_graph>; -using vol_int_int_int = dynamic_graph>; + vol_graph; +using vol_int_int_int = vol_graph; using vol_string_string_string = dynamic_graph>; + using graph_t = vol_graph; graph_t g(100); REQUIRE(g.graph_value() == 100); } SECTION("with void vertex value") { - using graph_t = dynamic_graph>; + using graph_t = vol_graph; graph_t g(100); REQUIRE(g.graph_value() == 100); } SECTION("with void graph value") { - using graph_t = dynamic_graph>; + using graph_t = vol_graph; graph_t g; REQUIRE(g.size() == 0); } @@ -395,19 +394,19 @@ TEST_CASE("vol value types", "[vol][value_types]") { } SECTION("with string edge value type") { - using graph_t = dynamic_graph>; + using graph_t = vol_graph; graph_t g; REQUIRE(g.size() == 0); } SECTION("with string vertex value type") { - using graph_t = dynamic_graph>; + using graph_t = vol_graph; graph_t g; REQUIRE(g.size() == 0); } SECTION("with string graph value type") { - using graph_t = dynamic_graph>; + using graph_t = vol_graph; graph_t g(std::string("test")); REQUIRE(g.graph_value() == "test"); } @@ -425,32 +424,32 @@ TEST_CASE("vol value types", "[vol][value_types]") { TEST_CASE("vol vertex ID types", "[vol][vertex_id]") { SECTION("with uint32_t vertex id") { using graph_t = - dynamic_graph>; + vol_graph; graph_t g; REQUIRE(g.size() == 0); } SECTION("with uint64_t vertex id") { using graph_t = - dynamic_graph>; + vol_graph; graph_t g; REQUIRE(g.size() == 0); } SECTION("with int32_t vertex id") { - using graph_t = dynamic_graph>; + using graph_t = vol_graph; graph_t g; REQUIRE(g.size() == 0); } SECTION("with int8_t vertex id") { - using graph_t = dynamic_graph>; + using graph_t = vol_graph; graph_t g; REQUIRE(g.size() == 0); } SECTION("with int vertex id") { - using graph_t = dynamic_graph>; + using graph_t = vol_graph; graph_t g; REQUIRE(g.size() == 0); } @@ -869,7 +868,7 @@ TEST_CASE("vol load_vertices", "[dynamic_graph][vol][load_vertices]") { } SECTION("load with custom projection from struct") { - using G2 = dynamic_graph>; + using G2 = vol_graph; using vertex_data2 = copyable_vertex_t; struct Person { @@ -1003,7 +1002,7 @@ TEST_CASE("vol load_edges", "[dynamic_graph][vol][load_edges]") { } SECTION("load with custom projection from struct") { - using G3 = dynamic_graph>; + using G3 = vol_graph; using vertex_data3 = copyable_vertex_t; using edge_data3 = copyable_edge_t; diff --git a/tests/container/dynamic_graph/test_dynamic_graph_vom.cpp b/tests/container/dynamic_graph/test_dynamic_graph_vom.cpp index b334e5b..b526ca9 100644 --- a/tests/container/dynamic_graph/test_dynamic_graph_vom.cpp +++ b/tests/container/dynamic_graph/test_dynamic_graph_vom.cpp @@ -16,7 +16,6 @@ #include #include #include -#include #include #include #include @@ -28,17 +27,17 @@ using namespace graph::container; // Type aliases for common test configurations using vos_void_void_void = - dynamic_graph>; + vom_graph; using vos_int_void_void = - dynamic_graph>; + vom_graph; using vos_void_int_void = - dynamic_graph>; + vom_graph; using vos_int_int_void = - dynamic_graph>; + vom_graph; using vos_void_void_int = - dynamic_graph>; + vom_graph; using vos_int_int_int = - dynamic_graph>; + vom_graph; using vos_string_string_string = dynamic_graph #include #include -#include #include #include #include @@ -28,16 +27,16 @@ using namespace graph::container; // Type aliases for common test configurations using vos_void_void_void = - dynamic_graph>; + vos_graph; using vos_int_void_void = - dynamic_graph>; + vos_graph; using vos_void_int_void = - dynamic_graph>; + vos_graph; using vos_int_int_void = - dynamic_graph>; + vos_graph; using vos_void_void_int = - dynamic_graph>; -using vos_int_int_int = dynamic_graph>; + vos_graph; +using vos_int_int_int = vos_graph; using vos_string_string_string = dynamic_graph #include #include -#include #include #include #include @@ -28,24 +27,19 @@ using namespace graph::container; // Type aliases for common test configurations using voum_void_void_void = - dynamic_graph>; + voum_graph; using voum_int_void_void = - dynamic_graph>; + voum_graph; using voum_void_int_void = - dynamic_graph>; + voum_graph; using voum_int_int_void = - dynamic_graph>; + voum_graph; using voum_void_void_int = - dynamic_graph>; + voum_graph; using voum_int_int_int = - dynamic_graph>; - -using voum_string_string_string = - dynamic_graph>; + voum_graph; + +using voum_string_string_string = voum_graph; // Edge and vertex data types for loading diff --git a/tests/container/dynamic_graph/test_dynamic_graph_vous.cpp b/tests/container/dynamic_graph/test_dynamic_graph_vous.cpp index 05e2ba3..da2fc07 100644 --- a/tests/container/dynamic_graph/test_dynamic_graph_vous.cpp +++ b/tests/container/dynamic_graph/test_dynamic_graph_vous.cpp @@ -20,7 +20,6 @@ #include #include #include -#include #include #include #include @@ -32,17 +31,17 @@ using namespace graph::container; // Type aliases for common test configurations using vous_void_void_void = - dynamic_graph>; + vous_graph; using vous_int_void_void = - dynamic_graph>; + vous_graph; using vous_void_int_void = - dynamic_graph>; + vous_graph; using vous_int_int_void = - dynamic_graph>; + vous_graph; using vous_void_void_int = - dynamic_graph>; + vous_graph; using vous_int_int_int = - dynamic_graph>; + vous_graph; using vous_string_string_string = dynamic_graph #include #include -#include #include #include #include @@ -25,16 +24,16 @@ using namespace graph::container; // Type aliases for common test configurations using vov_void_void_void = - dynamic_graph>; + vov_graph; using vov_int_void_void = - dynamic_graph>; + vov_graph; using vov_void_int_void = - dynamic_graph>; + vov_graph; using vov_int_int_void = - dynamic_graph>; + vov_graph; using vov_void_void_int = - dynamic_graph>; -using vov_int_int_int = dynamic_graph>; + vov_graph; +using vov_int_int_int = vov_graph; using vov_string_string_string = dynamic_graph>; + using graph_t = vov_graph; graph_t g(100); REQUIRE(g.graph_value() == 100); } SECTION("with void vertex value") { - using graph_t = dynamic_graph>; + using graph_t = vov_graph; graph_t g(100); REQUIRE(g.graph_value() == 100); } SECTION("with void graph value") { - using graph_t = dynamic_graph>; + using graph_t = vov_graph; graph_t g; REQUIRE(g.size() == 0); } @@ -396,19 +395,19 @@ TEST_CASE("vov value types", "[vov][value_types]") { } SECTION("with string edge value type") { - using graph_t = dynamic_graph>; + using graph_t = vov_graph; graph_t g; REQUIRE(g.size() == 0); } SECTION("with string vertex value type") { - using graph_t = dynamic_graph>; + using graph_t = vov_graph; graph_t g; REQUIRE(g.size() == 0); } SECTION("with string graph value type") { - using graph_t = dynamic_graph>; + using graph_t = vov_graph; graph_t g(std::string("test")); REQUIRE(g.graph_value() == "test"); } @@ -426,32 +425,32 @@ TEST_CASE("vov value types", "[vov][value_types]") { TEST_CASE("vov vertex ID types", "[vov][vertex_id]") { SECTION("with uint32_t vertex id") { using graph_t = - dynamic_graph>; + vov_graph; graph_t g; REQUIRE(g.size() == 0); } SECTION("with uint64_t vertex id") { using graph_t = - dynamic_graph>; + vov_graph; graph_t g; REQUIRE(g.size() == 0); } SECTION("with int32_t vertex id") { - using graph_t = dynamic_graph>; + using graph_t = vov_graph; graph_t g; REQUIRE(g.size() == 0); } SECTION("with int8_t vertex id") { - using graph_t = dynamic_graph>; + using graph_t = vov_graph; graph_t g; REQUIRE(g.size() == 0); } SECTION("with int vertex id") { - using graph_t = dynamic_graph>; + using graph_t = vov_graph; graph_t g; REQUIRE(g.size() == 0); } @@ -868,7 +867,7 @@ TEST_CASE("vov load_vertices", "[dynamic_graph][vov][load_vertices]") { } SECTION("with custom projection from struct") { - using G2 = dynamic_graph>; + using G2 = vov_graph; using vertex_data2 = copyable_vertex_t; struct Person { @@ -1005,7 +1004,7 @@ TEST_CASE("vov load_edges", "[dynamic_graph][vov][load_edges]") { } SECTION("with custom projection") { - using G2 = dynamic_graph>; + using G2 = vov_graph; using vertex_data2 = copyable_vertex_t; using edge_data2 = copyable_edge_t; diff --git a/tests/container/undirected_adjacency_list/test_undirected_adjacency_list.cpp b/tests/container/undirected_adjacency_list/test_undirected_adjacency_list.cpp index de00d44..219b069 100644 --- a/tests/container/undirected_adjacency_list/test_undirected_adjacency_list.cpp +++ b/tests/container/undirected_adjacency_list/test_undirected_adjacency_list.cpp @@ -476,11 +476,11 @@ TEST_CASE("edge_iterator comparison", "[undirected_adjacency_list][iterators][ed auto& vertex = g.vertices()[k1]; auto it1 = vertex.edges(g, k1).begin(); auto it2 = vertex.edges(g, k1).begin(); - auto end = vertex.edges(g, k1).end(); + auto end_it = vertex.edges(g, k1).end(); REQUIRE(it1 == it2); REQUIRE_FALSE(it1 != it2); - REQUIRE(it1 != end); + REQUIRE(it1 != end_it); } TEST_CASE("edge_iterator range-for", "[undirected_adjacency_list][iterators][edge]") { diff --git a/tests/container/undirected_adjacency_list/test_undirected_adjacency_list_cpo.cpp b/tests/container/undirected_adjacency_list/test_undirected_adjacency_list_cpo.cpp index 5c425dd..ff7dfd0 100644 --- a/tests/container/undirected_adjacency_list/test_undirected_adjacency_list_cpo.cpp +++ b/tests/container/undirected_adjacency_list/test_undirected_adjacency_list_cpo.cpp @@ -275,8 +275,8 @@ TEST_CASE("edge target_id CPO via ADL", "[undirected_adjacency_list][cpo][target // Edges from vertex 0 should go to vertices 1 and 2 REQUIRE(targets.size() == 2); // Order may vary, so check both are present - REQUIRE((std::find(targets.begin(), targets.end(), 1) != targets.end())); - REQUIRE((std::find(targets.begin(), targets.end(), 2) != targets.end())); + REQUIRE((std::find(targets.begin(), targets.end(), 1u) != targets.end())); + REQUIRE((std::find(targets.begin(), targets.end(), 2u) != targets.end())); } TEST_CASE("edge source_id CPO via ADL", "[undirected_adjacency_list][cpo][source_id]") { diff --git a/tests/generators/CMakeLists.txt b/tests/generators/CMakeLists.txt index 0639dd5..f0fe8fb 100644 --- a/tests/generators/CMakeLists.txt +++ b/tests/generators/CMakeLists.txt @@ -7,4 +7,5 @@ add_executable(graph3_generator_tests target_link_libraries(graph3_generator_tests PRIVATE graph3 Catch2::Catch2WithMain) -catch_discover_tests(graph3_generator_tests) +catch_discover_tests(graph3_generator_tests + DISCOVERY_MODE PRE_TEST) diff --git a/tests/io/CMakeLists.txt b/tests/io/CMakeLists.txt index ac4abbe..2d51e7b 100644 --- a/tests/io/CMakeLists.txt +++ b/tests/io/CMakeLists.txt @@ -7,4 +7,5 @@ add_executable(graph3_io_tests target_link_libraries(graph3_io_tests PRIVATE graph3 Catch2::Catch2WithMain) -catch_discover_tests(graph3_io_tests) +catch_discover_tests(graph3_io_tests + DISCOVERY_MODE PRE_TEST) diff --git a/tests/io/test_io.cpp b/tests/io/test_io.cpp index 1553631..8b60f19 100644 --- a/tests/io/test_io.cpp +++ b/tests/io/test_io.cpp @@ -6,7 +6,6 @@ #include #include -#include #include #include @@ -26,9 +25,9 @@ using weighted_graph_t = container::dynamic_graph1 (1.5), 0->2 (2.5), 1->2 (3.5) using edge_t = graph::copyable_edge_t; - std::vector edges = {{0, 1, 1.5}, {0, 2, 2.5}, {1, 2, 3.5}}; + std::vector edge_list = {{0, 1, 1.5}, {0, 2, 2.5}, {1, 2, 3.5}}; weighted_graph_t g; - g.load_edges(edges, std::identity{}, uint32_t{3}); + g.load_edges(edge_list, std::identity{}, uint32_t{3}); return g; } @@ -38,9 +37,9 @@ using plain_graph_t = container::dynamic_graph; - std::vector edges = {{0, 1}, {0, 2}, {1, 2}, {2, 0}}; + std::vector edge_list = {{0, 1}, {0, 2}, {1, 2}, {2, 0}}; plain_graph_t g; - g.load_edges(edges, std::identity{}, uint32_t{3}); + g.load_edges(edge_list, std::identity{}, uint32_t{3}); return g; } diff --git a/tests/views/test_adaptors.cpp b/tests/views/test_adaptors.cpp index 4da5b0a..e888320 100644 --- a/tests/views/test_adaptors.cpp +++ b/tests/views/test_adaptors.cpp @@ -19,10 +19,10 @@ using std::ranges::size; using test_graph = std::vector>; inline auto make_test_graph() { - test_graph g(3); // 3 vertices - g[0] = {1, 2}; // vertex 0 connects to vertices 1 and 2 + test_graph g(3); // 3 vertex_items + g[0] = {1, 2}; // vertex 0 connects to vertex_items 1 and 2 g[1] = {2}; // vertex 1 connects to vertex 2 - g[2] = {}; // vertex 2 has no outgoing edges + g[2] = {}; // vertex 2 has no outgoing edge_pairs return g; } @@ -40,7 +40,7 @@ TEST_CASE("vertexlist adaptor - basic pipe syntax", "[adaptors][vertexlist]") { std::vector vertex_ids; for (auto [id, v] : view) { - vertex_ids.push_back(id); + vertex_ids.push_back(static_cast(id)); REQUIRE(id == vertex_id(g, v)); // Verify id matches } @@ -51,14 +51,14 @@ TEST_CASE("vertexlist adaptor - with value function", "[adaptors][vertexlist]") auto g = make_test_graph(); // Test pipe syntax with value function: g | vertexlist(vvf) - auto vvf = [](const auto& g, auto&& v) { return vertex_id(g, v) * 10; }; // Simple transform + auto vvf = [](const auto& gr, auto&& v) { return vertex_id(gr, v) * 10; }; // Simple transform auto view = g | vertexlist(vvf); REQUIRE(size(view) == 3); std::vector values; for (auto [id, v, val] : view) { - values.push_back(val); + values.push_back(static_cast(val)); REQUIRE(id == vertex_id(g, v)); // Verify id matches } @@ -73,7 +73,7 @@ TEST_CASE("vertexlist adaptor - chaining with std::views::take", "[adaptors][ver std::vector vertex_ids; for (auto [id, v] : view) { - vertex_ids.push_back(id); + vertex_ids.push_back(static_cast(id)); REQUIRE(id == vertex_id(g, v)); // Verify id matches } @@ -97,7 +97,7 @@ TEST_CASE("vertexlist adaptor - chaining with transform", "[adaptors][vertexlist std::vector values; for (auto [id, v, val] : view) { - values.push_back(val); + values.push_back(static_cast(val)); } REQUIRE(values == std::vector{10, 20}); @@ -124,11 +124,11 @@ TEST_CASE("incidence adaptor - basic pipe syntax", "[adaptors][incidence]") { // Test basic pipe syntax: g | incidence(uid) auto view = g | incidence(0); - REQUIRE(size(view) == 2); // vertex 0 has 2 outgoing edges + REQUIRE(size(view) == 2); // vertex 0 has 2 outgoing edge_pairs std::vector target_ids; for (auto [tid, e] : view) { - target_ids.push_back(tid); + target_ids.push_back(static_cast(tid)); } REQUIRE(target_ids == std::vector{1, 2}); @@ -138,14 +138,14 @@ TEST_CASE("incidence adaptor - with value function", "[adaptors][incidence]") { auto g = make_test_graph(); // Test pipe syntax with value function: g | incidence(uid, evf) - auto evf = [](const auto& g, auto&& e) { return target_id(g, e) * 10; }; // Transform target ID + auto evf = [](const auto& gr, auto&& e) { return target_id(gr, e) * 10; }; // Transform target ID auto view = g | incidence(0, evf); REQUIRE(size(view) == 2); std::vector values; for (auto [tid, e, val] : view) { - values.push_back(val); + values.push_back(static_cast(val)); } REQUIRE(values == std::vector{10, 20}); // targets 1 and 2 @@ -159,7 +159,7 @@ TEST_CASE("incidence adaptor - chaining with std::views::take", "[adaptors][inci std::vector target_ids; for (auto [tid, e] : view) { - target_ids.push_back(tid); + target_ids.push_back(static_cast(tid)); } REQUIRE(target_ids.size() == 1); @@ -179,7 +179,7 @@ TEST_CASE("incidence adaptor - chaining with transform", "[adaptors][incidence]" std::vector values; for (auto val : view) { - values.push_back(val); + values.push_back(static_cast(val)); } REQUIRE(values == std::vector{20, 40}); // (1*10*2, 2*10*2) @@ -210,7 +210,7 @@ TEST_CASE("neighbors adaptor - basic pipe syntax", "[adaptors][neighbors]") { std::vector neighbor_ids; for (auto [tid, v] : view) { - neighbor_ids.push_back(tid); + neighbor_ids.push_back(static_cast(tid)); } REQUIRE(neighbor_ids == std::vector{1, 2}); @@ -220,14 +220,14 @@ TEST_CASE("neighbors adaptor - with value function", "[adaptors][neighbors]") { auto g = make_test_graph(); // Test pipe syntax with value function: g | neighbors(uid, vvf) - auto vvf = [](const auto& g, auto&& v) { return vertex_id(g, v) * 10; }; + auto vvf = [](const auto& gr, auto&& v) { return vertex_id(gr, v) * 10; }; auto view = g | neighbors(0, vvf); REQUIRE(size(view) == 2); std::vector values; for (auto [tid, v, val] : view) { - values.push_back(val); + values.push_back(static_cast(val)); } REQUIRE(values == std::vector{10, 20}); @@ -244,7 +244,7 @@ TEST_CASE("neighbors adaptor - chaining with std::views::filter", "[adaptors][ne std::vector neighbor_ids; for (auto [tid, v] : view) { - neighbor_ids.push_back(tid); + neighbor_ids.push_back(static_cast(tid)); } REQUIRE(neighbor_ids == std::vector{2}); @@ -273,10 +273,10 @@ TEST_CASE("edgelist adaptor - basic pipe syntax", "[adaptors][edgelist]") { std::vector> edge_pairs; for (auto [sid, tid, e] : view) { - edge_pairs.emplace_back(sid, tid); + edge_pairs.emplace_back(static_cast(sid), static_cast(tid)); } - REQUIRE(edge_pairs.size() == 3); // 3 edges total + REQUIRE(edge_pairs.size() == 3); // 3 edge_pairs total REQUIRE(edge_pairs == std::vector>{{0, 1}, {0, 2}, {1, 2}}); } @@ -284,12 +284,12 @@ TEST_CASE("edgelist adaptor - with value function", "[adaptors][edgelist]") { auto g = make_test_graph(); // Test pipe syntax with value function: g | edgelist(evf) - auto evf = [](const auto& g, auto&& e) { return target_id(g, e) * 10; }; + auto evf = [](const auto& gr, auto&& e) { return target_id(gr, e) * 10; }; auto view = g | edgelist(evf); std::vector values; for (auto [sid, tid, e, val] : view) { - values.push_back(val); + values.push_back(static_cast(val)); } REQUIRE(values.size() == 3); @@ -304,7 +304,7 @@ TEST_CASE("edgelist adaptor - chaining with std::views::take", "[adaptors][edgel std::vector> edge_pairs; for (auto [sid, tid, e] : view) { - edge_pairs.emplace_back(sid, tid); + edge_pairs.emplace_back(static_cast(sid), static_cast(tid)); } REQUIRE(edge_pairs.size() == 2); @@ -327,10 +327,10 @@ TEST_CASE("edgelist adaptor - chaining with transform and filter", "[adaptors][e std::vector values; for (auto [e, val] : view) { - values.push_back(val); + values.push_back(static_cast(val)); } - REQUIRE(values == std::vector{20, 20}); // Two edges with target ID 2 + REQUIRE(values == std::vector{20, 20}); // Two edge_pairs with target ID 2 } TEST_CASE("edgelist adaptor - direct call compatibility", "[adaptors][edgelist]") { @@ -361,12 +361,12 @@ TEST_CASE("multiple views can be used independently with pipe syntax", "[adaptor auto g = make_test_graph(); // Use multiple different adaptors on same graph - auto vertices = g | vertexlist(); + auto vertex_items = g | vertexlist(); auto edges_from_0 = g | incidence(0); auto neighbors_of_0 = g | neighbors(0); auto all_edges = g | edgelist(); - REQUIRE(size(vertices) == 3); + REQUIRE(size(vertex_items) == 3); REQUIRE(size(edges_from_0) == 2); REQUIRE(size(neighbors_of_0) == 2); @@ -394,7 +394,7 @@ TEST_CASE("adaptors work with std::views algorithms", "[adaptors][composition]") std::vector values; for (auto [id, v, val] : view) { - values.push_back(val); + values.push_back(static_cast(val)); } REQUIRE(values == std::vector{10, 20}); @@ -403,7 +403,7 @@ TEST_CASE("adaptors work with std::views algorithms", "[adaptors][composition]") TEST_CASE("complex chaining scenario", "[adaptors][composition]") { auto g = make_test_graph(); - // Complex chain: get vertices, compute values, take first 2, transform values + // Complex chain: get vertex_items, compute values, take first 2, transform values // Pattern: use vertexlist() then std::views::transform for value computation auto view = g | vertexlist() | std::views::transform([&g](auto&& tuple) { auto [id, v] = tuple; @@ -413,7 +413,7 @@ TEST_CASE("complex chaining scenario", "[adaptors][composition]") { std::vector results; for (auto val : view) { - results.push_back(val); + results.push_back(static_cast(val)); } REQUIRE(results == std::vector{1, 11}); @@ -431,10 +431,10 @@ TEST_CASE("vertices_dfs adaptor - basic pipe syntax", "[adaptors][dfs][vertices_ std::vector visited; for (auto [v] : view) { - visited.push_back(vertex_id(g, v)); + visited.push_back(static_cast(vertex_id(g, v))); } - REQUIRE(visited.size() == 3); // All vertices reachable + REQUIRE(visited.size() == 3); // All vertex_items reachable REQUIRE(visited[0] == 0); // Starts at seed } @@ -442,12 +442,12 @@ TEST_CASE("vertices_dfs adaptor - with value function", "[adaptors][dfs][vertice auto g = make_test_graph(); // Test pipe syntax with value function: g | vertices_dfs(seed, vvf) - auto vvf = [](const auto& g, auto&& v) { return vertex_id(g, v) * 10; }; + auto vvf = [](const auto& gr, auto&& v) { return vertex_id(gr, v) * 10; }; auto view = g | vertices_dfs(0, vvf); std::vector values; for (auto [v, val] : view) { - values.push_back(val); + values.push_back(static_cast(val)); } REQUIRE(values.size() == 3); @@ -460,12 +460,12 @@ TEST_CASE("vertices_dfs adaptor - chaining with std::views", "[adaptors][dfs][ve // Test chaining: g | vertices_dfs(seed) | std::views::transform auto view = g | vertices_dfs(0) | std::views::transform([&g](auto&& tuple) { auto [v] = tuple; - return vertex_id(g, v); + return static_cast(vertex_id(g, v)); }); std::vector visited; for (auto id : view) { - visited.push_back(id); + visited.push_back(static_cast(id)); } REQUIRE(visited.size() == 3); @@ -478,26 +478,26 @@ TEST_CASE("edges_dfs adaptor - basic pipe syntax", "[adaptors][dfs][edges_dfs]") // Test basic pipe syntax: g | edges_dfs(seed) auto view = g | edges_dfs(0); - std::vector> edges; + std::vector> edge_pairs; for (auto [e] : view) { - edges.emplace_back(vertex_id(g, source(g, e)), vertex_id(g, target(g, e))); + edge_pairs.emplace_back(static_cast(vertex_id(g, source(g, e))), static_cast(vertex_id(g, target(g, e)))); } - REQUIRE(edges.size() >= 2); // At least 2 edges traversed + REQUIRE(edge_pairs.size() >= 2); // At least 2 edge_pairs traversed // First edge should be from seed vertex 0 - REQUIRE((edges[0].first == 0 || edges[1].first == 0)); + REQUIRE((edge_pairs[0].first == 0 || edge_pairs[1].first == 0)); } TEST_CASE("edges_dfs adaptor - with value function", "[adaptors][dfs][edges_dfs]") { auto g = make_test_graph(); // Test pipe syntax with value function: g | edges_dfs(seed, evf) - auto evf = [](const auto& g, auto&& e) { return target_id(g, e) * 10; }; + auto evf = [](const auto& gr, auto&& e) { return target_id(gr, e) * 10; }; auto view = g | edges_dfs(0, evf); std::vector values; for (auto [e, val] : view) { - values.push_back(val); + values.push_back(static_cast(val)); } REQUIRE(values.size() >= 2); @@ -515,10 +515,10 @@ TEST_CASE("vertices_bfs adaptor - basic pipe syntax", "[adaptors][bfs][vertices_ std::vector visited; for (auto [v] : view) { - visited.push_back(vertex_id(g, v)); + visited.push_back(static_cast(vertex_id(g, v))); } - REQUIRE(visited.size() == 3); // All vertices reachable + REQUIRE(visited.size() == 3); // All vertex_items reachable REQUIRE(visited[0] == 0); // Starts at seed } @@ -526,12 +526,12 @@ TEST_CASE("vertices_bfs adaptor - with value function", "[adaptors][bfs][vertice auto g = make_test_graph(); // Test pipe syntax with value function: g | vertices_bfs(seed, vvf) - auto vvf = [](const auto& g, auto&& v) { return vertex_id(g, v) * 10; }; + auto vvf = [](const auto& gr, auto&& v) { return vertex_id(gr, v) * 10; }; auto view = g | vertices_bfs(0, vvf); std::vector values; for (auto [v, val] : view) { - values.push_back(val); + values.push_back(static_cast(val)); } REQUIRE(values.size() == 3); @@ -544,16 +544,16 @@ TEST_CASE("vertices_bfs adaptor - chaining with std::views", "[adaptors][bfs][ve // Test chaining: g | vertices_bfs(seed) | std::views::filter auto view = g | vertices_bfs(0) | std::views::transform([&g](auto&& tuple) { auto [v] = tuple; - return vertex_id(g, v); + return static_cast(vertex_id(g, v)); }) | std::views::filter([](int id) { return id > 0; }); std::vector visited; for (auto id : view) { - visited.push_back(id); + visited.push_back(static_cast(id)); } - REQUIRE(visited.size() == 2); // Only vertices 1 and 2 + REQUIRE(visited.size() == 2); // Only vertex_items 1 and 2 REQUIRE(std::ranges::all_of(visited, [](int id) { return id > 0; })); } @@ -563,26 +563,26 @@ TEST_CASE("edges_bfs adaptor - basic pipe syntax", "[adaptors][bfs][edges_bfs]") // Test basic pipe syntax: g | edges_bfs(seed) auto view = g | edges_bfs(0); - std::vector> edges; + std::vector> edge_pairs; for (auto [e] : view) { - edges.emplace_back(vertex_id(g, source(g, e)), vertex_id(g, target(g, e))); + edge_pairs.emplace_back(static_cast(vertex_id(g, source(g, e))), static_cast(vertex_id(g, target(g, e)))); } - REQUIRE(edges.size() >= 2); // At least 2 edges traversed - // First edges should be from seed vertex 0 - REQUIRE(edges[0].first == 0); + REQUIRE(edge_pairs.size() >= 2); // At least 2 edge_pairs traversed + // First edge_pairs should be from seed vertex 0 + REQUIRE(edge_pairs[0].first == 0); } TEST_CASE("edges_bfs adaptor - with value function", "[adaptors][bfs][edges_bfs]") { auto g = make_test_graph(); // Test pipe syntax with value function: g | edges_bfs(seed, evf) - auto evf = [](const auto& g, auto&& e) { return target_id(g, e) * 10; }; + auto evf = [](const auto& gr, auto&& e) { return target_id(gr, e) * 10; }; auto view = g | edges_bfs(0, evf); std::vector values; for (auto [e, val] : view) { - values.push_back(val); + values.push_back(static_cast(val)); } REQUIRE(values.size() >= 2); @@ -601,9 +601,9 @@ TEST_CASE("search adaptors - direct call compatibility", "[adaptors][dfs][bfs]") std::vector visited1, visited2; for (auto [v] : dfs_view1) - visited1.push_back(vertex_id(g, v)); + visited1.push_back(static_cast(vertex_id(g, v))); for (auto [v] : dfs_view2) - visited2.push_back(vertex_id(g, v)); + visited2.push_back(static_cast(vertex_id(g, v))); REQUIRE(visited1 == visited2); @@ -614,9 +614,9 @@ TEST_CASE("search adaptors - direct call compatibility", "[adaptors][dfs][bfs]") visited1.clear(); visited2.clear(); for (auto [v] : bfs_view1) - visited1.push_back(vertex_id(g, v)); + visited1.push_back(static_cast(vertex_id(g, v))); for (auto [v] : bfs_view2) - visited2.push_back(vertex_id(g, v)); + visited2.push_back(static_cast(vertex_id(g, v))); REQUIRE(visited1 == visited2); } @@ -625,36 +625,36 @@ TEST_CASE("vertices_topological_sort adaptor - basic pipe syntax", "[adaptors][t auto g = make_test_graph(); // Use pipe syntax - std::vector vertices; + std::vector vertex_items; for (auto [v] : g | vertices_topological_sort()) { - vertices.push_back(vertex_id(g, v)); + vertex_items.push_back(static_cast(vertex_id(g, v))); } - // Should visit all vertices - REQUIRE(vertices.size() == num_vertices(g)); + // Should visit all vertex_items + REQUIRE(vertex_items.size() == num_vertices(g)); // Check topological order property: for each edge (u,v), u comes after v in the order // (reverse post-order means sources come after targets) std::unordered_map pos; - for (size_t i = 0; i < vertices.size(); ++i) { - pos[vertices[i]] = i; + for (size_t i = 0; i < vertex_items.size(); ++i) { + pos[vertex_items[i]] = i; } for (auto [sid, tid, e] : g | edgelist()) { - // In topological sort, each vertex appears before all vertices it has edges to + // In topological sort, each vertex appears before all vertex_items it has edge_pairs to // so source comes before target: pos[sid] < pos[tid] - REQUIRE(pos[sid] < pos[tid]); + REQUIRE(pos[static_cast(sid)] < pos[static_cast(tid)]); } } TEST_CASE("vertices_topological_sort adaptor - with value function", "[adaptors][topological_sort]") { auto g = make_test_graph(); - auto vvf = [](const auto& g, auto v) { return vertex_id(g, v) * 10; }; + auto vvf = [](const auto& gr, auto v) { return vertex_id(gr, v) * 10; }; std::vector> results; for (auto [v, val] : g | vertices_topological_sort(vvf)) { - results.push_back({vertex_id(g, v), val}); + results.push_back({static_cast(vertex_id(g, v)), static_cast(val)}); } REQUIRE(results.size() == num_vertices(g)); @@ -668,24 +668,24 @@ TEST_CASE("vertices_topological_sort adaptor - with value function", "[adaptors] TEST_CASE("edges_topological_sort adaptor - basic pipe syntax", "[adaptors][topological_sort]") { auto g = make_test_graph(); - std::vector> edges; + std::vector> edge_pairs; for (auto [e] : g | edges_topological_sort()) { auto src = vertex_id(g, source(g, e)); auto tgt = vertex_id(g, target(g, e)); - edges.push_back({src, tgt}); + edge_pairs.push_back({static_cast(src), static_cast(tgt)}); } - REQUIRE(edges.size() == num_edges(g)); + REQUIRE(edge_pairs.size() == num_edges(g)); } TEST_CASE("edges_topological_sort adaptor - with value function", "[adaptors][topological_sort]") { auto g = make_test_graph(); - auto evf = [](const auto& g, auto e) { return vertex_id(g, source(g, e)) + vertex_id(g, target(g, e)); }; + auto evf = [](const auto& gr, auto e) { return vertex_id(gr, source(gr, e)) + vertex_id(gr, target(gr, e)); }; std::vector values; for (auto [e, val] : g | edges_topological_sort(evf)) { - values.push_back(val); + values.push_back(static_cast(val)); } REQUIRE(values.size() == num_edges(g)); @@ -702,9 +702,9 @@ TEST_CASE("topological_sort adaptors - chaining with std::views", "[adaptors][to std::vector ids; for (auto id : g | vertices_topological_sort() | std::views::transform([&g](auto tup) { auto [v] = tup; - return vertex_id(g, v); + return static_cast(vertex_id(g, v)); })) { - ids.push_back(id); + ids.push_back(static_cast(id)); } REQUIRE(ids.size() == num_vertices(g)); @@ -719,9 +719,9 @@ TEST_CASE("topological_sort adaptors - direct call compatibility", "[adaptors][t std::vector visited1, visited2; for (auto [v] : topo_view1) - visited1.push_back(vertex_id(g, v)); + visited1.push_back(static_cast(vertex_id(g, v))); for (auto [v] : topo_view2) - visited2.push_back(vertex_id(g, v)); + visited2.push_back(static_cast(vertex_id(g, v))); REQUIRE(visited1 == visited2); } @@ -736,10 +736,10 @@ TEST_CASE("complex chaining - multiple transforms", "[adaptors][chaining]") { std::vector results; for (auto id : g | vertexlist() | std::views::transform([&g](auto info) { auto [id, v] = info; - return id; + return static_cast(id); }) | std::views::transform([](int id) { return id * 10; }) | std::views::transform([](int val) { return val + 5; })) { - results.push_back(id); + results.push_back(static_cast(id)); } REQUIRE(results.size() == 3); @@ -752,14 +752,14 @@ TEST_CASE("complex chaining - multiple transforms", "[adaptors][chaining]") { TEST_CASE("complex chaining - filter and transform", "[adaptors][chaining]") { auto g = make_test_graph(); - // Filter vertices, then transform the results + // Filter vertex_items, then transform the results std::vector results; for (auto val : g | vertexlist() | std::views::transform([&g](auto info) { auto [id, v] = info; - return id; + return static_cast(id); }) | std::views::filter([](int id) { return id > 0; }) | std::views::transform([](int id) { return id * 100; })) { - results.push_back(val); + results.push_back(static_cast(val)); } REQUIRE(results.size() == 2); @@ -774,10 +774,10 @@ TEST_CASE("complex chaining - transform, filter, transform", "[adaptors][chainin std::vector results; for (auto val : g | edgelist() | std::views::transform([&g](auto info) { auto [sid, tid, e] = info; - return tid; + return static_cast(tid); }) | std::views::filter([](int tgt) { return tgt == 2; }) | std::views::transform([](int id) { return id * 7; })) { - results.push_back(val); + results.push_back(static_cast(val)); } // Edges: 0->1, 0->2, 1->2. After filter (tgt==2): 0->2, 1->2 @@ -793,9 +793,9 @@ TEST_CASE("chaining with std::views::take", "[adaptors][chaining]") { std::vector results; for (auto val : g | vertexlist() | std::views::transform([&g](auto info) { auto [id, v] = info; - return id; + return static_cast(id); }) | std::views::take(2)) { - results.push_back(val); + results.push_back(static_cast(val)); } REQUIRE(results.size() == 2); @@ -808,13 +808,13 @@ TEST_CASE("chaining with std::views::drop", "[adaptors][chaining]") { std::vector results; for (auto val : g | vertexlist() | std::views::transform([&g](auto info) { auto [id, v] = info; - return id; + return static_cast(id); }) | std::views::drop(1)) { - results.push_back(val); + results.push_back(static_cast(val)); } REQUIRE(results.size() == 2); - // After dropping first element, should have vertices 1 and 2 + // After dropping first element, should have vertex_items 1 and 2 } TEST_CASE("chaining incidence with transforms", "[adaptors][chaining]") { @@ -824,13 +824,13 @@ TEST_CASE("chaining incidence with transforms", "[adaptors][chaining]") { std::vector results; for (auto val : g | incidence(0) | std::views::transform([&g](auto info) { auto [tid, e] = info; - return tid; + return static_cast(tid); }) | std::views::filter([](int tgt) { return tgt < 2; }) | std::views::transform([](int id) { return id * 3; })) { - results.push_back(val); + results.push_back(static_cast(val)); } - // Vertex 0's edges: 0->1, 0->2 + // Vertex 0's edge_pairs: 0->1, 0->2 // After filter (tgt < 2): only 0->1 REQUIRE(results.size() == 1); REQUIRE(results[0] == 3); // 1 * 3 @@ -843,9 +843,9 @@ TEST_CASE("chaining neighbors with filter", "[adaptors][chaining]") { std::vector results; for (auto id : g | neighbors(0) | std::views::transform([&g](auto info) { auto [tid, v] = info; - return tid; + return static_cast(tid); }) | std::views::filter([](int id) { return id % 2 == 0; })) { - results.push_back(id); + results.push_back(static_cast(id)); } // Neighbors of 0: {1, 2}, filter even: {2} @@ -860,7 +860,7 @@ TEST_CASE("const correctness - const graph with pipe", "[adaptors][const]") { std::vector results; for (auto [id, v] : g | vertexlist()) { REQUIRE(id == vertex_id(g, v)); - results.push_back(id); + results.push_back(static_cast(id)); } REQUIRE(results.size() == 3); @@ -873,9 +873,9 @@ TEST_CASE("const correctness - const graph with chaining", "[adaptors][const]") std::vector results; for (auto id : g | vertexlist() | std::views::transform([&g](auto info) { auto [id, v] = info; - return id; + return static_cast(id); }) | std::views::filter([](int id) { return id < 3; })) { - results.push_back(id); + results.push_back(static_cast(id)); } REQUIRE(results.size() == 3); @@ -884,15 +884,15 @@ TEST_CASE("const correctness - const graph with chaining", "[adaptors][const]") TEST_CASE("mixing different view types in chains", "[adaptors][chaining]") { auto g = make_test_graph(); - // Get all neighbors of all vertices using chains + // Get all neighbors of all vertex_items using chains std::vector all_neighbors; for (auto vid : g | vertexlist() | std::views::transform([&g](auto info) { auto [id, v] = info; - return id; + return static_cast(id); })) { // For each vertex, get its neighbors for (auto [tid, n] : g | neighbors(vid)) { - all_neighbors.push_back(tid); + all_neighbors.push_back(static_cast(tid)); } } @@ -907,14 +907,14 @@ TEST_CASE("search views - complex chaining with multiple filters", "[adaptors][c std::vector results; for (auto id : g | vertices_dfs(0) | std::views::transform([&g](auto info) { auto [v] = info; - return vertex_id(g, v); + return static_cast(vertex_id(g, v)); }) | std::views::filter([](int id) { return id >= 0; }) | std::views::filter([](int id) { return id < 10; }) | std::views::transform([](int id) { return id + 1; })) { - results.push_back(id); + results.push_back(static_cast(id)); } - // All 3 vertices pass both filters, then +1 applied + // All 3 vertex_items pass both filters, then +1 applied REQUIRE(results.size() == 3); REQUIRE(results[0] == 1); // 0 + 1 } @@ -922,18 +922,18 @@ TEST_CASE("search views - complex chaining with multiple filters", "[adaptors][c TEST_CASE("edgelist chaining with reverse", "[adaptors][chaining]") { auto g = make_test_graph(); - // Collect edges, reverse the order - std::vector> edges; + // Collect edge_pairs, reverse the order + std::vector> edge_pairs; auto edge_view = g | edgelist() | std::views::transform([&g](auto info) { auto [sid, tid, e] = info; - return std::make_pair(sid, tid); + return std::make_pair(static_cast(sid), static_cast(tid)); }); for (auto edge : edge_view) { - edges.push_back(edge); + edge_pairs.push_back(edge); } - REQUIRE(edges.size() == 3); + REQUIRE(edge_pairs.size() == 3); } //============================================================================= @@ -958,14 +958,14 @@ TEST_CASE("basic_vertexlist adaptor - basic pipe syntax", "[adaptors][basic_vert TEST_CASE("basic_vertexlist adaptor - with value function", "[adaptors][basic_vertexlist]") { auto g = make_test_graph(); - auto vvf = [](const auto& g, auto&& v) { return static_cast(vertex_id(g, v)) * 10; }; + auto vvf = [](const auto& gr, auto&& v) { return static_cast(vertex_id(gr, v)) * 10; }; auto view = g | basic_vertexlist(vvf); REQUIRE(size(view) == 3); std::vector values; for (auto [uid, val] : view) { - values.push_back(val); + values.push_back(static_cast(val)); } REQUIRE(values == std::vector{0, 10, 20}); @@ -1017,14 +1017,14 @@ TEST_CASE("basic_incidence adaptor - basic pipe syntax", "[adaptors][basic_incid TEST_CASE("basic_incidence adaptor - with value function", "[adaptors][basic_incidence]") { auto g = make_test_graph(); - auto evf = [](const auto& g, auto&& e) { return static_cast(target_id(g, e)) * 10; }; + auto evf = [](const auto& gr, auto&& e) { return static_cast(target_id(gr, e)) * 10; }; auto view = g | basic_incidence(0, evf); REQUIRE(size(view) == 2); std::vector values; for (auto [tid, val] : view) { - values.push_back(val); + values.push_back(static_cast(val)); } REQUIRE(values == std::vector{10, 20}); @@ -1076,14 +1076,14 @@ TEST_CASE("basic_neighbors adaptor - basic pipe syntax", "[adaptors][basic_neigh TEST_CASE("basic_neighbors adaptor - with value function", "[adaptors][basic_neighbors]") { auto g = make_test_graph(); - auto vvf = [](const auto& g, auto&& v) { return static_cast(vertex_id(g, v)) * 10; }; + auto vvf = [](const auto& gr, auto&& v) { return static_cast(vertex_id(gr, v)) * 10; }; auto view = g | basic_neighbors(0, vvf); REQUIRE(size(view) == 2); std::vector values; for (auto [tid, val] : view) { - values.push_back(val); + values.push_back(static_cast(val)); } REQUIRE(values == std::vector{10, 20}); @@ -1122,27 +1122,27 @@ TEST_CASE("basic_edgelist adaptor - basic pipe syntax", "[adaptors][basic_edgeli auto view = g | basic_edgelist(); - std::vector> edges; + std::vector> edge_pairs; for (auto [sid, tid] : view) { - edges.push_back({static_cast(sid), static_cast(tid)}); + edge_pairs.push_back({static_cast(sid), static_cast(tid)}); } - // edges: 0->1, 0->2, 1->2 - REQUIRE(edges.size() == 3); - REQUIRE(edges[0] == std::pair{0, 1}); - REQUIRE(edges[1] == std::pair{0, 2}); - REQUIRE(edges[2] == std::pair{1, 2}); + // edge_pairs: 0->1, 0->2, 1->2 + REQUIRE(edge_pairs.size() == 3); + REQUIRE(edge_pairs[0] == std::pair{0, 1}); + REQUIRE(edge_pairs[1] == std::pair{0, 2}); + REQUIRE(edge_pairs[2] == std::pair{1, 2}); } TEST_CASE("basic_edgelist adaptor - with value function", "[adaptors][basic_edgelist]") { auto g = make_test_graph(); - auto evf = [](const auto& g, auto&& e) { return static_cast(source_id(g, e) + target_id(g, e)); }; + auto evf = [](const auto& gr, auto&& e) { return static_cast(source_id(gr, e) + target_id(gr, e)); }; auto view = g | basic_edgelist(evf); std::vector values; for (auto [sid, tid, val] : view) { - values.push_back(val); + values.push_back(static_cast(val)); } REQUIRE(values == std::vector{1, 2, 3}); // 0+1, 0+2, 1+2 @@ -1153,14 +1153,14 @@ TEST_CASE("basic_edgelist adaptor - chaining with std::views::take", "[adaptors] auto view = g | basic_edgelist() | std::views::take(2); - std::vector> edges; + std::vector> edge_pairs; for (auto [sid, tid] : view) { - edges.push_back({static_cast(sid), static_cast(tid)}); + edge_pairs.push_back({static_cast(sid), static_cast(tid)}); } - REQUIRE(edges.size() == 2); - REQUIRE(edges[0] == std::pair{0, 1}); - REQUIRE(edges[1] == std::pair{0, 2}); + REQUIRE(edge_pairs.size() == 2); + REQUIRE(edge_pairs[0] == std::pair{0, 1}); + REQUIRE(edge_pairs[1] == std::pair{0, 2}); } TEST_CASE("basic_edgelist adaptor - direct call compatibility", "[adaptors][basic_edgelist]") { @@ -1202,7 +1202,7 @@ static BiGraph make_bi_graph() { TEST_CASE("pipe: g | out_incidence(uid)", "[adaptors][out_incidence]") { auto bg = make_bi_graph(); auto view = bg | out_incidence(0u); - REQUIRE(size(view) == 2); // vertex 0 has 2 edges + REQUIRE(size(view) == 2); // vertex 0 has 2 edge_pairs // Also verify it matches the free-function factory auto ref = graph::views::out_incidence(bg, 0u); @@ -1211,7 +1211,7 @@ TEST_CASE("pipe: g | out_incidence(uid)", "[adaptors][out_incidence]") { TEST_CASE("pipe: g | out_incidence(uid, evf)", "[adaptors][out_incidence]") { auto bg = make_bi_graph(); - auto evf = [](const auto& g, auto e) { return adj_list::edge_value(g, e); }; + auto evf = [](const auto& gr, auto e) { return adj_list::edge_value(gr, e); }; auto view = bg | out_incidence(0u, evf); REQUIRE(size(view) == 2); @@ -1236,7 +1236,7 @@ TEST_CASE("pipe: g | in_incidence(uid)", "[adaptors][in_incidence]") { TEST_CASE("pipe: g | in_incidence(uid, evf)", "[adaptors][in_incidence]") { auto bg = make_bi_graph(); - auto evf = [](const auto& g, auto e) { return adj_list::edge_value(g, e); }; + auto evf = [](const auto& gr, auto e) { return adj_list::edge_value(gr, e); }; auto view = bg | in_incidence(0u, evf); REQUIRE(size(view) == 2); @@ -1257,7 +1257,7 @@ TEST_CASE("pipe: g | basic_in_incidence(uid)", "[adaptors][basic_in_incidence]") TEST_CASE("pipe: g | basic_in_incidence(uid, evf)", "[adaptors][basic_in_incidence]") { auto bg = make_bi_graph(); - auto evf = [](const auto& g, auto e) { return adj_list::edge_value(g, e); }; + auto evf = [](const auto& gr, auto e) { return adj_list::edge_value(gr, e); }; auto view = bg | basic_in_incidence(0u, evf); REQUIRE(size(view) == 2); } @@ -1342,4 +1342,5 @@ TEST_CASE("in_neighbors adaptor - direct call", "[adaptors][in_neighbors]") { auto bg = make_bi_graph(); auto view = in_neighbors(bg, 0u); REQUIRE(size(view) == 2); -} \ No newline at end of file +} + diff --git a/tests/views/test_basic_edgelist.cpp b/tests/views/test_basic_edgelist.cpp index 9f2ced9..c709ad9 100644 --- a/tests/views/test_basic_edgelist.cpp +++ b/tests/views/test_basic_edgelist.cpp @@ -45,7 +45,7 @@ TEST_CASE("basic_edgelist - empty graph", "[basic_edgelist][empty]") { } } -TEST_CASE("basic_edgelist - vertices with no edges", "[basic_edgelist][empty]") { +TEST_CASE("basic_edgelist - vertices with no edge_pairs", "[basic_edgelist][empty]") { using Graph = std::vector>; Graph g = {{}, {}, {}}; @@ -79,8 +79,8 @@ TEST_CASE("basic_edgelist - single edge", "[basic_edgelist][single]") { } SECTION("with value function") { - auto el = basic_edgelist(g, [](const auto& g, auto e) { - return static_cast(adj_list::target_id(g, e)) * 10; + auto el = basic_edgelist(g, [](const auto& gr, auto e) { + return static_cast(adj_list::target_id(gr, e)) * 10; }); auto it = el.begin(); @@ -95,31 +95,31 @@ TEST_CASE("basic_edgelist - single edge", "[basic_edgelist][single]") { } } -TEST_CASE("basic_edgelist - multiple edges", "[basic_edgelist][multiple]") { +TEST_CASE("basic_edgelist - multiple edge_pairs", "[basic_edgelist][multiple]") { using Graph = std::vector>; Graph g = { - {1, 2}, // vertex 0 → edges to 1, 2 + {1, 2}, // vertex 0 → edge_pairs to 1, 2 {2}, // vertex 1 → edge to 2 - {} // vertex 2 → no edges + {} // vertex 2 → no edge_pairs }; - SECTION("no value function - collects all edges") { + SECTION("no value function - collects all edge_pairs") { auto el = basic_edgelist(g); - std::vector> edges; + std::vector> edge_pairs; for (auto [sid, tid] : el) { - edges.emplace_back(sid, tid); + edge_pairs.emplace_back(sid, tid); } - REQUIRE(edges.size() == 3); - REQUIRE(edges[0] == std::pair{0, 1}); - REQUIRE(edges[1] == std::pair{0, 2}); - REQUIRE(edges[2] == std::pair{1, 2}); + REQUIRE(edge_pairs.size() == 3); + REQUIRE(edge_pairs[0] == std::pair{0, 1}); + REQUIRE(edge_pairs[1] == std::pair{0, 2}); + REQUIRE(edge_pairs[2] == std::pair{1, 2}); } SECTION("with value function") { - auto el = basic_edgelist(g, [](const auto& g, auto e) { - return static_cast(adj_list::target_id(g, e)) * 10; + auto el = basic_edgelist(g, [](const auto& gr, auto e) { + return static_cast(adj_list::target_id(gr, e)) * 10; }); std::vector values; @@ -134,24 +134,24 @@ TEST_CASE("basic_edgelist - multiple edges", "[basic_edgelist][multiple]") { TEST_CASE("basic_edgelist - skips empty vertices", "[basic_edgelist][skip]") { using Graph = std::vector>; Graph g = { - {}, // vertex 0 → no edges - {}, // vertex 1 → no edges - {0, 1}, // vertex 2 → edges to 0, 1 - {}, // vertex 3 → no edges + {}, // vertex 0 → no edge_pairs + {}, // vertex 1 → no edge_pairs + {0, 1}, // vertex 2 → edge_pairs to 0, 1 + {}, // vertex 3 → no edge_pairs {3} // vertex 4 → edge to 3 }; auto el = basic_edgelist(g); - std::vector> edges; + std::vector> edge_pairs; for (auto [sid, tid] : el) { - edges.emplace_back(sid, tid); + edge_pairs.emplace_back(sid, tid); } - REQUIRE(edges.size() == 3); - REQUIRE(edges[0] == std::pair{2, 0}); - REQUIRE(edges[1] == std::pair{2, 1}); - REQUIRE(edges[2] == std::pair{4, 3}); + REQUIRE(edge_pairs.size() == 3); + REQUIRE(edge_pairs[0] == std::pair{2, 0}); + REQUIRE(edge_pairs[1] == std::pair{2, 1}); + REQUIRE(edge_pairs[2] == std::pair{4, 3}); } TEST_CASE("basic_edgelist - info_type has no edge field", "[basic_edgelist][info]") { @@ -209,22 +209,22 @@ TEST_CASE("basic_edgelist - deque-based graph", "[basic_edgelist][deque]") { SECTION("no value function") { auto el = basic_edgelist(g); - std::vector> edges; + std::vector> edge_pairs; for (auto [sid, tid] : el) { - edges.emplace_back(sid, tid); + edge_pairs.emplace_back(sid, tid); } - REQUIRE(edges.size() == 5); - REQUIRE(edges[0] == std::pair{0, 1}); - REQUIRE(edges[1] == std::pair{0, 2}); - REQUIRE(edges[2] == std::pair{1, 0}); - REQUIRE(edges[3] == std::pair{2, 0}); - REQUIRE(edges[4] == std::pair{2, 1}); + REQUIRE(edge_pairs.size() == 5); + REQUIRE(edge_pairs[0] == std::pair{0, 1}); + REQUIRE(edge_pairs[1] == std::pair{0, 2}); + REQUIRE(edge_pairs[2] == std::pair{1, 0}); + REQUIRE(edge_pairs[3] == std::pair{2, 0}); + REQUIRE(edge_pairs[4] == std::pair{2, 1}); } SECTION("with value function") { - auto el = basic_edgelist(g, [](const auto& g, auto e) { - return static_cast(adj_list::target_id(g, e)); + auto el = basic_edgelist(g, [](const auto& gr, auto e) { + return static_cast(adj_list::target_id(gr, e)); }); std::vector targets; @@ -243,15 +243,15 @@ TEST_CASE("basic_edgelist - const graph", "[basic_edgelist][const]") { SECTION("no value function") { auto el = basic_edgelist(g); - std::vector> edges; + std::vector> edge_pairs; for (auto [sid, tid] : el) { - edges.emplace_back(sid, tid); + edge_pairs.emplace_back(sid, tid); } - REQUIRE(edges.size() == 3); - REQUIRE(edges[0] == std::pair{0, 1}); - REQUIRE(edges[1] == std::pair{0, 2}); - REQUIRE(edges[2] == std::pair{1, 0}); + REQUIRE(edge_pairs.size() == 3); + REQUIRE(edge_pairs[0] == std::pair{0, 1}); + REQUIRE(edge_pairs[1] == std::pair{0, 2}); + REQUIRE(edge_pairs[2] == std::pair{1, 0}); } } @@ -316,8 +316,8 @@ TEST_CASE("basic_edgelist - value function types", "[basic_edgelist][evf]") { Graph g = {{1, 2}, {0}, {}}; SECTION("returning string") { - auto el = basic_edgelist(g, [](const auto& g, auto e) { - return std::to_string(adj_list::target_id(g, e)); + auto el = basic_edgelist(g, [](const auto& gr, auto e) { + return std::to_string(adj_list::target_id(gr, e)); }); std::vector names; @@ -329,8 +329,8 @@ TEST_CASE("basic_edgelist - value function types", "[basic_edgelist][evf]") { } SECTION("returning double") { - auto el = basic_edgelist(g, [](const auto& g, auto e) { - return static_cast(adj_list::target_id(g, e)) * 1.5; + auto el = basic_edgelist(g, [](const auto& gr, auto e) { + return static_cast(adj_list::target_id(gr, e)) * 1.5; }); std::vector values; @@ -362,23 +362,23 @@ TEST_CASE("basic_edgelist - undirected_adjacency_list", "[basic_edgelist][undire SECTION("basic_edgelist(g) - basic iteration") { auto el = basic_edgelist(g); - std::set> edges; + std::set> edge_pairs; for (auto [sid, tid] : el) { - edges.emplace(sid, tid); + edge_pairs.emplace(static_cast(sid), static_cast(tid)); } // Undirected: each edge appears in both directions - REQUIRE(edges.size() == 6); - REQUIRE(edges.count({0, 1}) == 1); - REQUIRE(edges.count({1, 0}) == 1); - REQUIRE(edges.count({0, 2}) == 1); - REQUIRE(edges.count({2, 0}) == 1); - REQUIRE(edges.count({1, 2}) == 1); - REQUIRE(edges.count({2, 1}) == 1); + REQUIRE(edge_pairs.size() == 6); + REQUIRE(edge_pairs.count({0, 1}) == 1); + REQUIRE(edge_pairs.count({1, 0}) == 1); + REQUIRE(edge_pairs.count({0, 2}) == 1); + REQUIRE(edge_pairs.count({2, 0}) == 1); + REQUIRE(edge_pairs.count({1, 2}) == 1); + REQUIRE(edge_pairs.count({2, 1}) == 1); } SECTION("basic_edgelist(g, evf) - with value function") { - auto el = basic_edgelist(g, [](const auto& g, auto e) { return edge_value(g, e); }); + auto el = basic_edgelist(g, [](const auto& gr, auto e) { return edge_value(gr, e); }); std::vector weights; for (auto [sid, tid, w] : el) { diff --git a/tests/views/test_basic_incidence.cpp b/tests/views/test_basic_incidence.cpp index 8add956..704cb44 100644 --- a/tests/views/test_basic_incidence.cpp +++ b/tests/views/test_basic_incidence.cpp @@ -58,7 +58,7 @@ TEST_CASE("basic_incidence - single edge", "[basic_incidence][single]") { SECTION("with value function") { auto inc = basic_incidence(g, std::size_t(0), - [](const auto& g, auto e) { return static_cast(adj_list::target_id(g, e)); }); + [](const auto& gr, auto e) { return static_cast(adj_list::target_id(gr, e)); }); auto it = inc.begin(); REQUIRE(it != inc.end()); @@ -106,7 +106,7 @@ TEST_CASE("basic_incidence - multiple edges", "[basic_incidence][multiple]") { SECTION("with value function") { auto inc = basic_incidence(g, std::size_t(0), - [](const auto& g, auto e) { return static_cast(adj_list::target_id(g, e)) * 10; }); + [](const auto& gr, auto e) { return static_cast(adj_list::target_id(gr, e)) * 10; }); std::vector values; for (auto [tid, val] : inc) { @@ -181,7 +181,7 @@ TEST_CASE("basic_incidence - deque-based graph", "[basic_incidence][deque]") { SECTION("with value function") { auto inc = basic_incidence(g, std::size_t(2), - [](const auto& g, auto e) { return static_cast(adj_list::target_id(g, e)); }); + [](const auto& gr, auto e) { return static_cast(adj_list::target_id(gr, e)); }); std::vector targets; for (auto [tid, val] : inc) { @@ -260,7 +260,7 @@ TEST_CASE("basic_incidence - value function types", "[basic_incidence][evf]") { SECTION("returning string") { auto inc = basic_incidence(g, std::size_t(0), - [](const auto& g, auto e) { return "edge_to_" + std::to_string(adj_list::target_id(g, e)); }); + [](const auto& gr, auto e) { return "edge_to_" + std::to_string(adj_list::target_id(gr, e)); }); std::vector names; for (auto [tid, name] : inc) { @@ -272,7 +272,7 @@ TEST_CASE("basic_incidence - value function types", "[basic_incidence][evf]") { SECTION("returning double") { auto inc = basic_incidence(g, std::size_t(0), - [](const auto& g, auto e) { return static_cast(adj_list::target_id(g, e)) * 1.5; }); + [](const auto& gr, auto e) { return static_cast(adj_list::target_id(gr, e)) * 1.5; }); std::vector values; for (auto [tid, val] : inc) { @@ -305,14 +305,14 @@ TEST_CASE("basic_incidence - undirected_adjacency_list", "[basic_incidence][undi std::set targets; for (auto [tid] : inc) { - targets.insert(tid); + targets.insert(static_cast(tid)); } REQUIRE(targets.count(1) == 1); REQUIRE(targets.count(2) == 1); } SECTION("basic_incidence(g, uid, evf) - with value function") { - auto inc = basic_incidence(g, 0u, [](const auto& g, auto e) { return edge_value(g, e); }); + auto inc = basic_incidence(g, 0u, [](const auto& gr, auto e) { return edge_value(gr, e); }); std::vector weights; for (auto [tid, w] : inc) { diff --git a/tests/views/test_basic_neighbors.cpp b/tests/views/test_basic_neighbors.cpp index 3ac3870..d83002a 100644 --- a/tests/views/test_basic_neighbors.cpp +++ b/tests/views/test_basic_neighbors.cpp @@ -305,14 +305,14 @@ TEST_CASE("basic_neighbors - undirected_adjacency_list", "[basic_neighbors][undi std::set targets; for (auto [tid] : nbrs) { - targets.insert(tid); + targets.insert(static_cast(tid)); } REQUIRE(targets.count(1) == 1); REQUIRE(targets.count(2) == 1); } SECTION("basic_neighbors(g, uid, vvf) - with value function") { - auto nbrs = basic_neighbors(g, 0u, [](const auto& g, auto v) { return vertex_value(g, v); }); + auto nbrs = basic_neighbors(g, 0u, [](const auto& gr, auto v) { return vertex_value(gr, v); }); std::vector values; for (auto [tid, val] : nbrs) { diff --git a/tests/views/test_basic_vertexlist.cpp b/tests/views/test_basic_vertexlist.cpp index d8c03e1..27bee2a 100644 --- a/tests/views/test_basic_vertexlist.cpp +++ b/tests/views/test_basic_vertexlist.cpp @@ -116,8 +116,8 @@ TEST_CASE("basic_vertexlist - multiple vertices", "[basic_vertexlist][multiple]" } SECTION("structured binding - with value function") { - auto vlist = basic_vertexlist(g, [](const auto& g, auto v) { - return g[v.vertex_id()].size(); // number of edges + auto vlist = basic_vertexlist(g, [](const auto& gr, auto v) { + return gr[v.vertex_id()].size(); // number of edges }); std::vector edge_counts; @@ -198,13 +198,13 @@ TEST_CASE("basic_vertexlist - deque-based graph", "[basic_vertexlist][deque]") { } SECTION("with value function") { - auto vlist = basic_vertexlist(g, [](const auto& g, auto v) { - return g[v.vertex_id()].front(); + auto vlist = basic_vertexlist(g, [](const auto& gr, auto v) { + return gr[v.vertex_id()].front(); }); std::vector targets; - for (auto [uid, target] : vlist) { - targets.push_back(target); + for (auto [uid, target_val] : vlist) { + targets.push_back(target_val); } REQUIRE(targets == std::vector{1, 2, 0}); @@ -263,8 +263,8 @@ TEST_CASE("basic_vertexlist - map-based graph", "[basic_vertexlist][map]") { } SECTION("with value function") { - auto vlist = basic_vertexlist(g, [](const auto& g, auto v) { - return g.at(v.vertex_id()).size(); + auto vlist = basic_vertexlist(g, [](const auto& gr, auto v) { + return gr.at(v.vertex_id()).size(); }); std::vector edge_counts; @@ -394,7 +394,7 @@ TEST_CASE("basic_vertexlist - id subrange", "[basic_vertexlist][subrange]") { SECTION("subrange with value function") { auto vlist = basic_vertexlist(g, std::size_t(1), std::size_t(4), - [](const auto& g, auto v) { return g[v.vertex_id()].size(); }); + [](const auto& gr, auto v) { return gr[v.vertex_id()].size(); }); REQUIRE(vlist.size() == 3); @@ -494,7 +494,7 @@ TEST_CASE("vertexlist - descriptor subrange", "[vertexlist][subrange]") { auto last_u = *std::ranges::next(std::ranges::begin(vr), 4); auto vlist = vertexlist(g, first_u, last_u, - [](const auto& g, auto v) { return g[v.vertex_id()].size(); }); + [](const auto& gr, auto v) { return gr[v.vertex_id()].size(); }); REQUIRE(vlist.size() == 3); diff --git a/tests/views/test_bfs.cpp b/tests/views/test_bfs.cpp index fb5b7c7..3cc7ae4 100644 --- a/tests/views/test_bfs.cpp +++ b/tests/views/test_bfs.cpp @@ -1,6 +1,5 @@ #include #include -#include #include #include #include @@ -90,7 +89,7 @@ TEST_CASE("vertices_bfs - with value function", "[bfs][vertices]") { {} // 2 (leaf) }; - auto value_fn = [](const auto& g, auto v) { return static_cast(vertex_id(g, v)) * 10; }; + auto value_fn = [](const auto& gr, auto v) { return static_cast(vertex_id(gr, v)) * 10; }; std::vector values; for (auto [v, val] : vertices_bfs(g, 0, value_fn)) { @@ -209,11 +208,11 @@ TEST_CASE("vertices_bfs - empty iteration", "[bfs][vertices]") { auto bfs = vertices_bfs(g, 0); auto it = bfs.begin(); - auto end = bfs.end(); + auto end_it = bfs.end(); - REQUIRE(it != end); // Has seed + REQUIRE(it != end_it); // Has seed ++it; - REQUIRE(it == end); // No more vertices + REQUIRE(it == end_it); // No more vertices } TEST_CASE("vertices_bfs - cancel_all", "[bfs][vertices][cancel]") { @@ -343,9 +342,9 @@ TEST_CASE("edges_bfs - with value function", "[bfs][edges]") { {} // 2 (leaf) }; - auto value_fn = [](const auto& g, auto edge) { - auto target_v = target(g, edge); - return static_cast(vertex_id(g, target_v)) * 10; + auto value_fn = [](const auto& gr, auto edge) { + auto target_v = target(gr, edge); + return static_cast(vertex_id(gr, target_v)) * 10; }; std::vector values; @@ -428,9 +427,9 @@ TEST_CASE("edges_bfs - cancel_all", "[bfs][edges][cancel]") { for (auto [edge] : bfs) { auto target_v = target(g, edge); - int target_id = static_cast(vertex_id(g, target_v)); - targets.push_back(target_id); - if (target_id == 1) { + int target_vid = static_cast(vertex_id(g, target_v)); + targets.push_back(target_vid); + if (target_vid == 1) { bfs.cancel(cancel_search::cancel_all); } } @@ -457,9 +456,9 @@ TEST_CASE("edges_bfs - cancel_branch", "[bfs][edges][cancel]") { for (auto [edge] : bfs) { auto target_v = target(g, edge); - int target_id = static_cast(vertex_id(g, target_v)); - targets.push_back(target_id); - if (target_id == 1) { + int target_vid = static_cast(vertex_id(g, target_v)); + targets.push_back(target_vid); + if (target_vid == 1) { bfs.cancel(cancel_search::cancel_branch); // Skip exploring children of vertex 1 } } @@ -580,7 +579,7 @@ TEST_CASE("vertices_bfs - depth on wide tree", "[bfs][vertices][depth]") { auto bfs = vertices_bfs(g, 0); - for (auto [v] : bfs) { + for ([[maybe_unused]] auto entry : bfs) { // Just iterate } @@ -602,7 +601,7 @@ TEST_CASE("vertices_bfs - depth on deep chain", "[bfs][vertices][depth]") { auto bfs = vertices_bfs(g, 0); - for (auto [v] : bfs) { + for ([[maybe_unused]] auto entry : bfs) { // Just iterate } @@ -623,7 +622,7 @@ TEST_CASE("vertices_bfs - size on disconnected graph", "[bfs][vertices][size]") auto bfs = vertices_bfs(g, 0); - for (auto [v] : bfs) { + for ([[maybe_unused]] auto entry : bfs) { // Just iterate } @@ -644,7 +643,7 @@ TEST_CASE("edges_bfs - depth tracks edge depth", "[bfs][edges][depth]") { auto bfs = edges_bfs(g, 0); - for (auto [edge] : bfs) { + for ([[maybe_unused]] auto entry : bfs) { // Just iterate } @@ -668,7 +667,7 @@ TEST_CASE("edges_bfs - size counts edges", "[bfs][edges][size]") { auto bfs = edges_bfs(g, 0); int edge_count = 0; - for (auto [edge] : bfs) { + for ([[maybe_unused]] auto entry : bfs) { ++edge_count; // Size should equal edges discovered so far REQUIRE(bfs.num_visited() == static_cast(edge_count)); @@ -688,10 +687,10 @@ TEST_CASE("vertices_bfs - depth/size with value function", "[bfs][vertices][dept {} // 3 }; - auto value_fn = [](const auto& g, auto v) { return static_cast(vertex_id(g, v)) * 10; }; + auto value_fn = [](const auto& gr, auto v) { return static_cast(vertex_id(gr, v)) * 10; }; auto bfs = vertices_bfs(g, 0, value_fn); - for (auto [v, val] : bfs) { + for ([[maybe_unused]] auto entry : bfs) { // Just iterate } @@ -708,10 +707,10 @@ TEST_CASE("edges_bfs - depth/size with value function", "[bfs][edges][depth]") { {} // 3 }; - auto value_fn = [](const auto& g, auto e) { return static_cast(vertex_id(g, target(g, e))) * 10; }; + auto value_fn = [](const auto& gr, auto e) { return static_cast(vertex_id(gr, target(gr, e))) * 10; }; auto bfs = edges_bfs(g, 0, value_fn); - for (auto [e, val] : bfs) { + for ([[maybe_unused]] auto entry : bfs) { // Just iterate } @@ -728,13 +727,13 @@ using StrGraph = dynamic_adjacency_graph& vertex_names, - const std::vector>& edges) { + const std::vector>& edge_pairs) { using VD = copyable_vertex_t; using ED = copyable_edge_t; StrGraph g; g.load_vertices(vertex_names, [](const std::string& name) -> VD { return {name}; }); - g.load_edges(edges, [](const auto& e) -> ED { return {e.first, e.second}; }); + g.load_edges(edge_pairs, [](const auto& e) -> ED { return {e.first, e.second}; }); return g; } diff --git a/tests/views/test_dfs.cpp b/tests/views/test_dfs.cpp index ee1561c..4967f05 100644 --- a/tests/views/test_dfs.cpp +++ b/tests/views/test_dfs.cpp @@ -6,7 +6,6 @@ #include #include #include -#include #include #include #include @@ -88,11 +87,11 @@ TEST_CASE("vertices_dfs - structured bindings", "[dfs][vertices][bindings]") { } SECTION("structured binding [v, val] with value function") { - auto dfs = vertices_dfs(g, 0, [](const auto& g, auto v) { return vertex_id(g, v) * 10; }); + auto dfs = vertices_dfs(g, 0, [](const auto& gr, auto v) { return vertex_id(gr, v) * 10; }); std::vector> results; for (auto [v, val] : dfs) { - results.emplace_back(static_cast(vertex_id(g, v)), val); + results.emplace_back(static_cast(vertex_id(g, v)), static_cast(val)); } REQUIRE(results.size() == 3); @@ -136,7 +135,7 @@ TEST_CASE("vertices_dfs - value function types", "[dfs][vertices][vvf]") { Graph g = {{1, 2}, {}, {}}; SECTION("returning int") { - auto dfs = vertices_dfs(g, 0, [](const auto& g, auto v) { return static_cast(vertex_id(g, v)); }); + auto dfs = vertices_dfs(g, 0, [](const auto& gr, auto v) { return static_cast(vertex_id(gr, v)); }); int sum = 0; for (auto [v, val] : dfs) { @@ -146,7 +145,7 @@ TEST_CASE("vertices_dfs - value function types", "[dfs][vertices][vvf]") { } SECTION("returning string") { - auto dfs = vertices_dfs(g, 0, [](const auto& g, auto v) { return "v" + std::to_string(vertex_id(g, v)); }); + auto dfs = vertices_dfs(g, 0, [](const auto& gr, auto v) { return "v" + std::to_string(vertex_id(gr, v)); }); std::vector names; for (auto [v, name] : dfs) { @@ -162,7 +161,7 @@ TEST_CASE("vertices_dfs - value function types", "[dfs][vertices][vvf]") { SECTION("capturing lambda") { int multiplier = 5; auto dfs = vertices_dfs( - g, 0, [multiplier](const auto& g, auto v) { return static_cast(vertex_id(g, v)) * multiplier; }); + g, 0, [multiplier](const auto& gr, auto v) { return static_cast(vertex_id(gr, v)) * multiplier; }); std::vector values; for (auto [v, val] : dfs) { @@ -351,8 +350,8 @@ TEST_CASE("vertices_dfs - search_view concept", "[dfs][vertices][concepts]") { // Verify accessors exist and return correct types REQUIRE(dfs.cancel() == cancel_search::continue_search); - REQUIRE(dfs.depth() >= 0); - REQUIRE(dfs.num_visited() >= 0); + REQUIRE(dfs.depth() == 1); + REQUIRE(dfs.num_visited() == 0); } // ============================================================================= @@ -574,7 +573,7 @@ TEST_CASE("edges_dfs - structured bindings", "[dfs][edges][bindings]") { } SECTION("structured binding [e, val] with value function") { - auto dfs = edges_dfs(g, 0, [](const auto& g, auto e) { return target_id(g, e) * 10; }); + auto dfs = edges_dfs(g, 0, [](const auto& gr, auto e) { return target_id(gr, e) * 10; }); std::vector> results; for (auto [e, val] : dfs) { @@ -597,7 +596,7 @@ TEST_CASE("edges_dfs - value function types", "[dfs][edges][evf]") { Graph g = {{1, 2}, {}, {}}; SECTION("returning int") { - auto dfs = edges_dfs(g, 0, [](const auto& g, auto e) { return static_cast(target_id(g, e)); }); + auto dfs = edges_dfs(g, 0, [](const auto& gr, auto e) { return static_cast(target_id(gr, e)); }); int sum = 0; for (auto [e, val] : dfs) { @@ -607,8 +606,8 @@ TEST_CASE("edges_dfs - value function types", "[dfs][edges][evf]") { } SECTION("returning string") { - auto dfs = edges_dfs(g, 0, [](const auto& g, auto e) { - return "e" + std::to_string(source_id(g, e)) + "_" + std::to_string(target_id(g, e)); + auto dfs = edges_dfs(g, 0, [](const auto& gr, auto e) { + return "e" + std::to_string(source_id(gr, e)) + "_" + std::to_string(target_id(gr, e)); }); std::vector names; @@ -625,7 +624,7 @@ TEST_CASE("edges_dfs - value function types", "[dfs][edges][evf]") { SECTION("capturing lambda") { int multiplier = 5; auto dfs = edges_dfs( - g, 0, [multiplier](const auto& g, auto e) { return static_cast(target_id(g, e)) * multiplier; }); + g, 0, [multiplier](const auto& gr, auto e) { return static_cast(target_id(gr, e)) * multiplier; }); std::vector values; for (auto [e, val] : dfs) { @@ -767,8 +766,8 @@ TEST_CASE("edges_dfs - search_view concept", "[dfs][edges][concepts]") { // Verify accessors exist and return correct types REQUIRE(dfs.cancel() == cancel_search::continue_search); - REQUIRE(dfs.depth() >= 0); - REQUIRE(dfs.num_visited() >= 0); + REQUIRE(dfs.depth() == 1); + REQUIRE(dfs.num_visited() == 0); } // ============================================================================= @@ -843,7 +842,7 @@ TEST_CASE("edges_dfs - large linear graph", "[dfs][edges][performance]") { } int edge_count = 0; - for (auto [e] : edges_dfs(g, 0)) { + for ([[maybe_unused]] auto entry : edges_dfs(g, 0)) { ++edge_count; } @@ -1187,7 +1186,7 @@ TEST_CASE("vertices_dfs - cancel with value function", "[dfs][vertices][cancel]" Graph g = {{1, 2}, {3, 4}, {}, {}, {}}; std::vector> results; - auto dfs = vertices_dfs(g, 0, [](const auto& g, auto v) { return static_cast(vertex_id(g, v)) * 10; }); + auto dfs = vertices_dfs(g, 0, [](const auto& gr, auto v) { return static_cast(vertex_id(gr, v)) * 10; }); for (auto [v, val] : dfs) { int vid = static_cast(vertex_id(g, v)); @@ -1215,13 +1214,13 @@ using StrGraph = dynamic_adjacency_graph& vertex_names, - const std::vector>& edges) { + const std::vector>& edge_pairs) { using VD = copyable_vertex_t; using ED = copyable_edge_t; StrGraph g; g.load_vertices(vertex_names, [](const std::string& name) -> VD { return {name}; }); - g.load_edges(edges, [](const auto& e) -> ED { return {e.first, e.second}; }); + g.load_edges(edge_pairs, [](const auto& e) -> ED { return {e.first, e.second}; }); return g; } @@ -1376,3 +1375,4 @@ TEST_CASE("vertices_dfs cancel_branch - string ids", "[dfs][cancel][non_integral REQUIRE(ids == std::vector{"a"}); } } + diff --git a/tests/views/test_edge_cases.cpp b/tests/views/test_edge_cases.cpp index 566ef79..565afa2 100644 --- a/tests/views/test_edge_cases.cpp +++ b/tests/views/test_edge_cases.cpp @@ -420,7 +420,7 @@ TEST_CASE("Value function - capturing lambda", "[views][edge_cases][value_functi std::vector> g{{1, 2}, {2}, {}}; std::map names{{0, "A"}, {1, "B"}, {2, "C"}}; - auto vvf = [&names](const auto& g, auto v) { return names[vertex_id(g, v)]; }; + auto vvf = [&names](const auto& gr, auto v) { return names[vertex_id(gr, v)]; }; auto view = g | vertexlist(vvf); @@ -434,7 +434,7 @@ TEST_CASE("Value function - mutable lambda", "[views][edge_cases][value_function std::vector> g{{1}, {2}, {}}; int counter = 0; - auto vvf = [counter](const auto& g, auto v) mutable { return vertex_id(g, v) + counter++; }; + auto vvf = [counter](const auto& gr, auto v) mutable { return vertex_id(gr, v) + counter++; }; auto view = g | vertexlist(vvf); @@ -451,7 +451,7 @@ TEST_CASE("Value function - mutable lambda", "[views][edge_cases][value_function TEST_CASE("Value function - with structured binding", "[views][edge_cases][value_function]") { std::vector> g{{1, 2}, {2}, {}}; - auto vvf = [](const auto& g, auto v) { return vertex_id(g, v) * 10; }; + auto vvf = [](const auto& gr, auto v) { return vertex_id(gr, v) * 10; }; auto view = g | vertexlist(vvf); @@ -468,8 +468,8 @@ TEST_CASE("Value function - with structured binding", "[views][edge_cases][value TEST_CASE("Exception safety - value function throws", "[views][edge_cases][exception]") { std::vector> g{{1, 2}, {2}, {}}; - auto throwing_vvf = [](const auto& g, auto v) -> int { - auto id = vertex_id(g, v); + auto throwing_vvf = [](const auto& gr, auto v) -> int { + auto id = vertex_id(gr, v); if (id == 1) { throw std::runtime_error("Test exception"); } diff --git a/tests/views/test_edgelist.cpp b/tests/views/test_edgelist.cpp index 0a62828..18831f7 100644 --- a/tests/views/test_edgelist.cpp +++ b/tests/views/test_edgelist.cpp @@ -47,12 +47,12 @@ TEST_CASE("edgelist - empty graph", "[edgelist][empty]") { // Test 2: Graph with Vertices but No Edges // ============================================================================= -TEST_CASE("edgelist - vertices with no edges", "[edgelist][empty]") { +TEST_CASE("edgelist - vertices with no edge_pairs", "[edgelist][empty]") { using Graph = std::vector>; Graph g = { - {}, // vertex 0 - no edges - {}, // vertex 1 - no edges - {} // vertex 2 - no edges + {}, // vertex 0 - no edge_pairs + {}, // vertex 1 - no edge_pairs + {} // vertex 2 - no edge_pairs }; SECTION("no value function") { @@ -76,7 +76,7 @@ TEST_CASE("edgelist - single edge", "[edgelist][single]") { using Graph = std::vector>; Graph g = { {1}, // vertex 0 -> edge to 1 - {} // vertex 1 - no edges + {} // vertex 1 - no edge_pairs }; SECTION("no value function") { @@ -94,8 +94,8 @@ TEST_CASE("edgelist - single edge", "[edgelist][single]") { } SECTION("with value function") { - auto elist = edgelist(g, [](const auto& g, auto e) { - return static_cast(source_id(g, e)) * 100 + static_cast(target_id(g, e)); + auto elist = edgelist(g, [](const auto& gr, auto e) { + return static_cast(source_id(gr, e)) * 100 + static_cast(target_id(gr, e)); }); auto ei = *elist.begin(); @@ -115,7 +115,7 @@ TEST_CASE("edgelist - single edge", "[edgelist][single]") { } SECTION("structured binding - with value function") { - auto elist = edgelist(g, [](const auto& g, auto e) { return target_id(g, e) * 10; }); + auto elist = edgelist(g, [](const auto& gr, auto e) { return target_id(gr, e) * 10; }); for (auto [sid, tid, e, val] : elist) { REQUIRE(tid == 1); @@ -128,9 +128,9 @@ TEST_CASE("edgelist - single edge", "[edgelist][single]") { // Test 4: Multiple Edges from Single Vertex // ============================================================================= -TEST_CASE("edgelist - multiple edges from single vertex", "[edgelist][multiple]") { +TEST_CASE("edgelist - multiple edge_pairs from single vertex", "[edgelist][multiple]") { using Graph = std::vector>; - Graph g = {{1, 2, 3}, // vertex 0 -> edges to 1, 2, 3 + Graph g = {{1, 2, 3}, // vertex 0 -> edge_pairs to 1, 2, 3 {}, {}, {}}; @@ -138,19 +138,19 @@ TEST_CASE("edgelist - multiple edges from single vertex", "[edgelist][multiple]" SECTION("iteration") { auto elist = edgelist(g); - std::vector> edges; + std::vector> edge_pairs; for (auto [sid, tid, e] : elist) { - edges.emplace_back(sid, tid); + edge_pairs.emplace_back(static_cast(sid), static_cast(tid)); } - REQUIRE(edges.size() == 3); - REQUIRE(edges[0] == std::pair{0, 1}); - REQUIRE(edges[1] == std::pair{0, 2}); - REQUIRE(edges[2] == std::pair{0, 3}); + REQUIRE(edge_pairs.size() == 3); + REQUIRE(edge_pairs[0] == std::pair{0, 1}); + REQUIRE(edge_pairs[1] == std::pair{0, 2}); + REQUIRE(edge_pairs[2] == std::pair{0, 3}); } SECTION("with value function") { - auto elist = edgelist(g, [](const auto& g, auto e) { return target_id(g, e); }); + auto elist = edgelist(g, [](const auto& gr, auto e) { return target_id(gr, e); }); std::vector values; for (auto [sid, tid, e, val] : elist) { @@ -168,33 +168,33 @@ TEST_CASE("edgelist - multiple edges from single vertex", "[edgelist][multiple]" TEST_CASE("edgelist - flattening multiple vertex edge lists", "[edgelist][flattening]") { using Graph = std::vector>; Graph g = { - {1, 2}, // vertex 0 -> edges to 1, 2 - {2, 3}, // vertex 1 -> edges to 2, 3 + {1, 2}, // vertex 0 -> edge_pairs to 1, 2 + {2, 3}, // vertex 1 -> edge_pairs to 2, 3 {3}, // vertex 2 -> edge to 3 - {} // vertex 3 - no edges + {} // vertex 3 - no edge_pairs }; - SECTION("all edges in order") { + SECTION("all edge_pairs in order") { auto elist = edgelist(g); - std::vector> edges; + std::vector> edge_pairs; for (auto [sid, tid, e] : elist) { - edges.emplace_back(sid, tid); + edge_pairs.emplace_back(static_cast(sid), static_cast(tid)); } // Edges should come in vertex order, then edge order within vertex - REQUIRE(edges.size() == 5); - REQUIRE(edges[0] == std::pair{0, 1}); - REQUIRE(edges[1] == std::pair{0, 2}); - REQUIRE(edges[2] == std::pair{1, 2}); - REQUIRE(edges[3] == std::pair{1, 3}); - REQUIRE(edges[4] == std::pair{2, 3}); + REQUIRE(edge_pairs.size() == 5); + REQUIRE(edge_pairs[0] == std::pair{0, 1}); + REQUIRE(edge_pairs[1] == std::pair{0, 2}); + REQUIRE(edge_pairs[2] == std::pair{1, 2}); + REQUIRE(edge_pairs[3] == std::pair{1, 3}); + REQUIRE(edge_pairs[4] == std::pair{2, 3}); } SECTION("with value function computing edge weight") { - auto elist = edgelist(g, [](const auto& g, auto e) { + auto elist = edgelist(g, [](const auto& gr, auto e) { // Compute edge "weight" as source + target - return static_cast(source_id(g, e)) + static_cast(target_id(g, e)); + return static_cast(source_id(gr, e)) + static_cast(target_id(gr, e)); }); std::vector weights; @@ -213,25 +213,25 @@ TEST_CASE("edgelist - flattening multiple vertex edge lists", "[edgelist][flatte TEST_CASE("edgelist - skipping empty vertices", "[edgelist][skip]") { using Graph = std::vector>; Graph g = { - {}, // vertex 0 - no edges + {}, // vertex 0 - no edge_pairs {2}, // vertex 1 -> edge to 2 - {}, // vertex 2 - no edges - {}, // vertex 3 - no edges + {}, // vertex 2 - no edge_pairs + {}, // vertex 3 - no edge_pairs {5}, // vertex 4 -> edge to 5 - {} // vertex 5 - no edges + {} // vertex 5 - no edge_pairs }; SECTION("correctly skips empty vertices") { auto elist = edgelist(g); - std::vector> edges; + std::vector> edge_pairs; for (auto [sid, tid, e] : elist) { - edges.emplace_back(sid, tid); + edge_pairs.emplace_back(static_cast(sid), static_cast(tid)); } - REQUIRE(edges.size() == 2); - REQUIRE(edges[0] == std::pair{1, 2}); - REQUIRE(edges[1] == std::pair{4, 5}); + REQUIRE(edge_pairs.size() == 2); + REQUIRE(edge_pairs[0] == std::pair{1, 2}); + REQUIRE(edge_pairs[1] == std::pair{4, 5}); } } @@ -244,8 +244,8 @@ TEST_CASE("edgelist - value function types", "[edgelist][evf]") { Graph g = {{1, 2}, {}, {}}; SECTION("returning string") { - auto elist = edgelist(g, [](const auto& g, auto e) { - return std::to_string(source_id(g, e)) + "->" + std::to_string(target_id(g, e)); + auto elist = edgelist(g, [](const auto& gr, auto e) { + return std::to_string(source_id(gr, e)) + "->" + std::to_string(target_id(gr, e)); }); std::vector labels; @@ -257,7 +257,7 @@ TEST_CASE("edgelist - value function types", "[edgelist][evf]") { } SECTION("returning double") { - auto elist = edgelist(g, [](const auto& g, auto e) { return static_cast(target_id(g, e)) * 1.5; }); + auto elist = edgelist(g, [](const auto& gr, auto e) { return static_cast(target_id(gr, e)) * 1.5; }); std::vector values; for (auto [sid, tid, e, val] : elist) { @@ -270,7 +270,7 @@ TEST_CASE("edgelist - value function types", "[edgelist][evf]") { SECTION("capturing lambda") { int multiplier = 100; - auto elist = edgelist(g, [multiplier](const auto& g, auto e) { return target_id(g, e) * multiplier; }); + auto elist = edgelist(g, [multiplier](const auto& gr, auto e) { return target_id(gr, e) * multiplier; }); std::vector values; for (auto [sid, tid, e, val] : elist) { @@ -329,19 +329,19 @@ TEST_CASE("edgelist - vector of deques", "[edgelist][container]") { SECTION("iteration") { auto elist = edgelist(g); - std::vector> edges; + std::vector> edge_pairs; for (auto [sid, tid, e] : elist) { - edges.emplace_back(sid, tid); + edge_pairs.emplace_back(static_cast(sid), static_cast(tid)); } - REQUIRE(edges.size() == 3); - REQUIRE(edges[0] == std::pair{0, 1}); - REQUIRE(edges[1] == std::pair{0, 2}); - REQUIRE(edges[2] == std::pair{1, 2}); + REQUIRE(edge_pairs.size() == 3); + REQUIRE(edge_pairs[0] == std::pair{0, 1}); + REQUIRE(edge_pairs[1] == std::pair{0, 2}); + REQUIRE(edge_pairs[2] == std::pair{1, 2}); } SECTION("with value function") { - auto elist = edgelist(g, [](const auto& g, auto e) { return target_id(g, e) * 10; }); + auto elist = edgelist(g, [](const auto& gr, auto e) { return target_id(gr, e) * 10; }); std::vector values; for (auto [sid, tid, e, val] : elist) { @@ -363,12 +363,12 @@ TEST_CASE("edgelist - deque of vectors", "[edgelist][container]") { SECTION("iteration") { auto elist = edgelist(g); - std::vector> edges; + std::vector> edge_pairs; for (auto [sid, tid, e] : elist) { - edges.emplace_back(sid, tid); + edge_pairs.emplace_back(static_cast(sid), static_cast(tid)); } - REQUIRE(edges.size() == 3); + REQUIRE(edge_pairs.size() == 3); } } @@ -403,7 +403,7 @@ TEST_CASE("edgelist - iterator operations", "[edgelist][iterator]") { auto elist = edgelist(g); auto it = elist.begin(); - // 3 edges total + // 3 edge_pairs total ++it; ++it; ++it; @@ -444,27 +444,27 @@ TEST_CASE("edgelist - map-based vertex container", "[edgelist][map]") { // Map vertices - non-contiguous vertex IDs using Graph = std::map>; Graph g = { - {100, {200, 300}}, // vertex 100 -> edges to 200, 300 + {100, {200, 300}}, // vertex 100 -> edge_pairs to 200, 300 {200, {300}}, // vertex 200 -> edge to 300 - {300, {}} // vertex 300 - no edges + {300, {}} // vertex 300 - no edge_pairs }; - SECTION("iteration over all edges") { + SECTION("iteration over all edge_pairs") { auto elist = edgelist(g); - std::vector> edges; + std::vector> edge_pairs; for (auto [sid, tid, e] : elist) { - edges.emplace_back(sid, tid); + edge_pairs.emplace_back(static_cast(sid), static_cast(tid)); } - REQUIRE(edges.size() == 3); - REQUIRE(edges[0] == std::pair{100, 200}); - REQUIRE(edges[1] == std::pair{100, 300}); - REQUIRE(edges[2] == std::pair{200, 300}); + REQUIRE(edge_pairs.size() == 3); + REQUIRE(edge_pairs[0] == std::pair{100, 200}); + REQUIRE(edge_pairs[1] == std::pair{100, 300}); + REQUIRE(edge_pairs[2] == std::pair{200, 300}); } SECTION("with value function") { - auto elist = edgelist(g, [](const auto& g, auto e) { return target_id(g, e) - source_id(g, e); }); + auto elist = edgelist(g, [](const auto& gr, auto e) { return target_id(gr, e) - source_id(gr, e); }); std::vector diffs; for (auto [sid, tid, e, diff] : elist) { @@ -486,31 +486,31 @@ TEST_CASE("edgelist - map-based vertex container", "[edgelist][map]") { // Test 14: Map-Based Edge Container (Sorted Edges) // ============================================================================= -TEST_CASE("edgelist - vector vertices map edges", "[edgelist][edge_map]") { +TEST_CASE("edgelist - vector vertices map edge_pairs", "[edgelist][edge_map]") { // Edges stored in map (sorted by target, with edge values) using Graph = std::vector>; Graph g = { {{1, 1.5}, {2, 2.5}}, // vertex 0 -> (1, 1.5), (2, 2.5) {{2, 3.5}}, // vertex 1 -> (2, 3.5) - {} // vertex 2 -> no edges + {} // vertex 2 -> no edge_pairs }; SECTION("iteration") { auto elist = edgelist(g); - std::vector> edges; + std::vector> edge_pairs; for (auto [sid, tid, e] : elist) { - edges.emplace_back(sid, tid); + edge_pairs.emplace_back(static_cast(sid), static_cast(tid)); } - REQUIRE(edges.size() == 3); - REQUIRE(edges[0] == std::pair{0, 1}); - REQUIRE(edges[1] == std::pair{0, 2}); - REQUIRE(edges[2] == std::pair{1, 2}); + REQUIRE(edge_pairs.size() == 3); + REQUIRE(edge_pairs[0] == std::pair{0, 1}); + REQUIRE(edge_pairs[1] == std::pair{0, 2}); + REQUIRE(edge_pairs[2] == std::pair{1, 2}); } SECTION("accessing edge weights via edge_value") { - auto elist = edgelist(g, [](const auto& g, auto e) { return edge_value(g, e); }); + auto elist = edgelist(g, [](const auto& gr, auto e) { return edge_value(gr, e); }); std::vector weights; for (auto [sid, tid, e, w] : elist) { @@ -525,31 +525,31 @@ TEST_CASE("edgelist - vector vertices map edges", "[edgelist][edge_map]") { // Test 15: Map Vertices + Map Edges (Fully Sparse Graph) // ============================================================================= -TEST_CASE("edgelist - map vertices map edges", "[edgelist][map][edge_map]") { - // Both vertices and edges in maps - fully sparse graph +TEST_CASE("edgelist - map vertices map edge_pairs", "[edgelist][map][edge_map]") { + // Both vertices and edge_pairs in maps - fully sparse graph using Graph = std::map>; Graph g = { {10, {{20, 1.0}, {30, 2.0}}}, // vertex 10 -> (20, 1.0), (30, 2.0) {20, {{30, 3.0}}}, // vertex 20 -> (30, 3.0) - {30, {}} // vertex 30 -> no edges + {30, {}} // vertex 30 -> no edge_pairs }; - SECTION("iteration over all edges") { + SECTION("iteration over all edge_pairs") { auto elist = edgelist(g); - std::vector> edges; + std::vector> edge_pairs; for (auto [sid, tid, e] : elist) { - edges.emplace_back(sid, tid); + edge_pairs.emplace_back(static_cast(sid), static_cast(tid)); } - REQUIRE(edges.size() == 3); - REQUIRE(edges[0] == std::pair{10, 20}); - REQUIRE(edges[1] == std::pair{10, 30}); - REQUIRE(edges[2] == std::pair{20, 30}); + REQUIRE(edge_pairs.size() == 3); + REQUIRE(edge_pairs[0] == std::pair{10, 20}); + REQUIRE(edge_pairs[1] == std::pair{10, 30}); + REQUIRE(edge_pairs[2] == std::pair{20, 30}); } SECTION("with edge value function") { - auto elist = edgelist(g, [](const auto& g, auto e) { return edge_value(g, e); }); + auto elist = edgelist(g, [](const auto& gr, auto e) { return edge_value(gr, e); }); std::vector weights; for (auto [sid, tid, e, w] : elist) { @@ -560,7 +560,7 @@ TEST_CASE("edgelist - map vertices map edges", "[edgelist][map][edge_map]") { } SECTION("combined source, target, weight extraction") { - auto elist = edgelist(g, [](const auto& g, auto e) { return edge_value(g, e); }); + auto elist = edgelist(g, [](const auto& gr, auto e) { return edge_value(gr, e); }); std::vector> all_edges; for (auto [sid, tid, e, w] : elist) { @@ -597,20 +597,20 @@ TEST_CASE("edgelist - edge_list with pairs", "[edgelist][edge_list]") { REQUIRE(elist.size() == 4); - std::vector> edges; + std::vector> edge_pairs; for (auto [sid, tid, e] : elist) { - edges.emplace_back(sid, tid); + edge_pairs.emplace_back(static_cast(sid), static_cast(tid)); } - REQUIRE(edges.size() == 4); - REQUIRE(edges[0] == std::pair{1, 2}); - REQUIRE(edges[1] == std::pair{2, 3}); - REQUIRE(edges[2] == std::pair{3, 4}); - REQUIRE(edges[3] == std::pair{4, 5}); + REQUIRE(edge_pairs.size() == 4); + REQUIRE(edge_pairs[0] == std::pair{1, 2}); + REQUIRE(edge_pairs[1] == std::pair{2, 3}); + REQUIRE(edge_pairs[2] == std::pair{3, 4}); + REQUIRE(edge_pairs[3] == std::pair{4, 5}); } SECTION("with value function") { - auto elist = edgelist(el, [](auto& el, auto e) { return source_id(el, e) + target_id(el, e); }); + auto elist = edgelist(el, [](auto& edge_list_ref, auto e) { return source_id(edge_list_ref, e) + target_id(edge_list_ref, e); }); std::vector sums; for (auto [sid, tid, e, sum] : elist) { @@ -634,19 +634,19 @@ TEST_CASE("edgelist - edge_list with 2-tuples", "[edgelist][edge_list]") { REQUIRE(elist.size() == 3); - std::vector> edges; + std::vector> edge_pairs; for (auto [sid, tid, e] : elist) { - edges.emplace_back(sid, tid); + edge_pairs.emplace_back(static_cast(sid), static_cast(tid)); } - REQUIRE(edges[0] == std::pair{0, 1}); - REQUIRE(edges[1] == std::pair{1, 2}); - REQUIRE(edges[2] == std::pair{2, 0}); + REQUIRE(edge_pairs[0] == std::pair{0, 1}); + REQUIRE(edge_pairs[1] == std::pair{1, 2}); + REQUIRE(edge_pairs[2] == std::pair{2, 0}); } } // ============================================================================= -// Test 18: edge_list with 3-tuples (weighted edges) +// Test 18: edge_list with 3-tuples (weighted edge_pairs) // ============================================================================= TEST_CASE("edgelist - edge_list with 3-tuples (weighted)", "[edgelist][edge_list]") { @@ -656,18 +656,18 @@ TEST_CASE("edgelist - edge_list with 3-tuples (weighted)", "[edgelist][edge_list SECTION("no value function") { auto elist = edgelist(el); - std::vector> edges; + std::vector> edge_pairs; for (auto [sid, tid, e] : elist) { - edges.emplace_back(sid, tid); + edge_pairs.emplace_back(static_cast(sid), static_cast(tid)); } - REQUIRE(edges.size() == 3); - REQUIRE(edges[0] == std::pair{0, 1}); - REQUIRE(edges[2] == std::pair{2, 3}); + REQUIRE(edge_pairs.size() == 3); + REQUIRE(edge_pairs[0] == std::pair{0, 1}); + REQUIRE(edge_pairs[2] == std::pair{2, 3}); } SECTION("value function accessing edge_value") { - auto elist = edgelist(el, [](auto& el, auto e) { return edge_value(el, e); }); + auto elist = edgelist(el, [](auto& edge_list_ref, auto e) { return edge_value(edge_list_ref, e); }); std::vector weights; for (auto [sid, tid, e, w] : elist) { @@ -678,7 +678,7 @@ TEST_CASE("edgelist - edge_list with 3-tuples (weighted)", "[edgelist][edge_list } SECTION("value function computing derived value") { - auto elist = edgelist(el, [](auto& el, auto e) { return edge_value(el, e) * 2.0; }); + auto elist = edgelist(el, [](auto& edge_list_ref, auto e) { return edge_value(edge_list_ref, e) * 2.0; }); std::vector doubled; for (auto [sid, tid, e, val] : elist) { @@ -704,18 +704,18 @@ TEST_CASE("edgelist - edge_list with edge_data", "[edgelist][edge_list]") { REQUIRE(elist.size() == 3); - std::vector> edges; + std::vector> edge_pairs; for (auto [sid, tid, e] : elist) { - edges.emplace_back(sid, tid); + edge_pairs.emplace_back(static_cast(sid), static_cast(tid)); } - REQUIRE(edges[0] == std::pair{10, 20}); - REQUIRE(edges[1] == std::pair{20, 30}); - REQUIRE(edges[2] == std::pair{30, 40}); + REQUIRE(edge_pairs[0] == std::pair{10, 20}); + REQUIRE(edge_pairs[1] == std::pair{20, 30}); + REQUIRE(edge_pairs[2] == std::pair{30, 40}); } SECTION("with value function") { - auto elist = edgelist(el, [](auto& el, auto e) { return target_id(el, e) - source_id(el, e); }); + auto elist = edgelist(el, [](auto& edge_list_ref, auto e) { return target_id(edge_list_ref, e) - source_id(edge_list_ref, e); }); std::vector diffs; for (auto [sid, tid, e, diff] : elist) { @@ -737,7 +737,7 @@ TEST_CASE("edgelist - edge_list with edge_data with value", "[edgelist][edge_lis EdgeList el = {EdgeType{1, 2, 0.5}, EdgeType{2, 3, 1.5}, EdgeType{3, 1, 2.5}}; SECTION("accessing edge_value") { - auto elist = edgelist(el, [](auto& el, auto e) { return edge_value(el, e); }); + auto elist = edgelist(el, [](auto& edge_list_ref, auto e) { return edge_value(edge_list_ref, e); }); std::vector weights; for (auto [sid, tid, e, w] : elist) { @@ -788,7 +788,7 @@ TEST_CASE("edgelist - edge_list satisfies range concepts", "[edgelist][edge_list } SECTION("view with value function") { - auto elist = edgelist(el, [](auto& el, auto e) { return source_id(el, e); }); + auto elist = edgelist(el, [](auto& edge_list_ref, auto e) { return source_id(edge_list_ref, e); }); STATIC_REQUIRE(std::ranges::range); STATIC_REQUIRE(std::ranges::forward_range); @@ -848,18 +848,18 @@ TEST_CASE("edgelist - edge_list with string vertex IDs", "[edgelist][edge_list][ REQUIRE(elist.size() == 3); - std::vector> edges; + std::vector> edge_pairs; for (auto [sid, tid, e] : elist) { - edges.emplace_back(sid, tid); + edge_pairs.emplace_back(sid, tid); } - REQUIRE(edges[0] == std::pair{"A", "B"}); - REQUIRE(edges[1] == std::pair{"B", "C"}); - REQUIRE(edges[2] == std::pair{"C", "A"}); + REQUIRE(edge_pairs[0] == std::pair{"A", "B"}); + REQUIRE(edge_pairs[1] == std::pair{"B", "C"}); + REQUIRE(edge_pairs[2] == std::pair{"C", "A"}); } SECTION("with value function creating labels") { - auto elist = edgelist(el, [](auto& el, auto e) { return source_id(el, e) + "->" + target_id(el, e); }); + auto elist = edgelist(el, [](auto& edge_list_ref, auto e) { return source_id(edge_list_ref, e) + "->" + target_id(edge_list_ref, e); }); std::vector labels; for (auto [sid, tid, e, label] : elist) { @@ -886,7 +886,7 @@ TEST_CASE("edgelist - edge_list with range algorithms", "[edgelist][edge_list][a SECTION("std::ranges::count_if") { auto elist = edgelist(el); auto count = std::ranges::count_if(elist, [&el](auto ei) { return target_id(el, ei.edge) > 3; }); - REQUIRE(count == 3); // edges to 4, 5, 6 + REQUIRE(count == 3); // edge_pairs to 4, 5, 6 } SECTION("std::ranges::for_each") { @@ -908,13 +908,13 @@ TEST_CASE("edgelist - deque-based edge_list", "[edgelist][edge_list][container]" SECTION("iteration") { auto elist = edgelist(el); - std::vector> edges; + std::vector> edge_pairs; for (auto [sid, tid, e] : elist) { - edges.emplace_back(sid, tid); + edge_pairs.emplace_back(static_cast(sid), static_cast(tid)); } - REQUIRE(edges.size() == 3); - REQUIRE(edges[0] == std::pair{1, 2}); + REQUIRE(edge_pairs.size() == 3); + REQUIRE(edge_pairs[0] == std::pair{1, 2}); } } @@ -929,7 +929,7 @@ struct counted_graph : std::vector> { using base = std::vector>; using base::base; - // Track total edges + // Track total edge_pairs [[nodiscard]] std::size_t num_edges() const noexcept { std::size_t n = 0; for (auto& row : *this) @@ -969,7 +969,7 @@ TEST_CASE("edgelist - adj list view IS sized_range when graph has O(1) num_edges TEST_CASE("edgelist - size() returns correct count from graph with num_edges()", "[edgelist][size]") { SECTION("non-empty graph") { - counted_graph g = {{1, 2}, {3}, {}, {0}}; // 4 edges total + counted_graph g = {{1, 2}, {3}, {}, {0}}; // 4 edge_pairs total auto elist = edgelist(g); REQUIRE(elist.size() == 4); } @@ -980,14 +980,14 @@ TEST_CASE("edgelist - size() returns correct count from graph with num_edges()", REQUIRE(elist.size() == 0); } - SECTION("graph with no edges") { + SECTION("graph with no edge_pairs") { counted_graph g = {{}, {}, {}}; auto elist = edgelist(g); REQUIRE(elist.size() == 0); } SECTION("with EVF") { - counted_graph g = {{1}, {2}, {}}; // 2 edges + counted_graph g = {{1}, {2}, {}}; // 2 edge_pairs auto elist = edgelist(g, [](const auto&, auto) { return 99; }); REQUIRE(elist.size() == 2); } @@ -1005,3 +1005,4 @@ TEST_CASE("edgelist - edge_list_edgelist_view size() still works (vector)", "[ed STATIC_REQUIRE(std::ranges::sized_range); REQUIRE(elist.size() == 3); } + diff --git a/tests/views/test_graph_hpp_includes_views.cpp b/tests/views/test_graph_hpp_includes_views.cpp index b9e448c..59aa6ea 100644 --- a/tests/views/test_graph_hpp_includes_views.cpp +++ b/tests/views/test_graph_hpp_includes_views.cpp @@ -109,11 +109,11 @@ TEST_CASE("graph.hpp - value functions work", "[graph_hpp][value_functions]") { auto g = make_test_graph(); // Test that value functions work through graph.hpp - auto vvf = [](const auto& g, auto v) { return vertex_id(g, v); }; + auto vvf = [](const auto& gr, auto v) { return vertex_id(gr, v); }; std::vector values; for (auto [id, v, val] : g | vertexlist(vvf)) { - values.push_back(val); + values.push_back(static_cast(val)); } REQUIRE(values.size() == 3); diff --git a/tests/views/test_in_incidence.cpp b/tests/views/test_in_incidence.cpp index 59151e2..f55a464 100644 --- a/tests/views/test_in_incidence.cpp +++ b/tests/views/test_in_incidence.cpp @@ -73,15 +73,15 @@ TEST_CASE("out_incidence matches incidence", "[in_incidence][out]") { std::vector ref_ids, test_ids; for (auto [tid, e] : ref) - ref_ids.push_back(tid); + ref_ids.push_back(static_cast(tid)); for (auto [tid, e] : test) - test_ids.push_back(tid); + test_ids.push_back(static_cast(tid)); REQUIRE(ref_ids == test_ids); } SECTION("with EVF") { - auto evf = [](const auto& g, auto e) { return adj::edge_value(g, e); }; + auto evf = [](const auto& gr, auto e) { return adj::edge_value(gr, e); }; auto ref = view::incidence(g, v0, evf); auto test = view::out_incidence(g, v0, evf); @@ -104,7 +104,7 @@ TEST_CASE("out_incidence matches incidence", "[in_incidence][out]") { } SECTION("with EVF from vertex id") { - auto evf = [](const auto& g, auto e) { return adj::edge_value(g, e); }; + auto evf = [](const auto& gr, auto e) { return adj::edge_value(gr, e); }; auto ref = view::incidence(g, 0u, evf); auto test = view::out_incidence(g, 0u, evf); @@ -127,15 +127,15 @@ TEST_CASE("basic_out_incidence matches basic_incidence", "[in_incidence][basic_o std::vector ref_ids, test_ids; for (auto ei : ref) - ref_ids.push_back(ei.target_id); + ref_ids.push_back(static_cast(ei.target_id)); for (auto ei : test) - test_ids.push_back(ei.target_id); + test_ids.push_back(static_cast(ei.target_id)); REQUIRE(ref_ids == test_ids); } SECTION("with EVF") { - auto evf = [](const auto& g, auto e) { return adj::edge_value(g, e); }; + auto evf = [](const auto& gr, auto e) { return adj::edge_value(gr, e); }; auto ref = view::basic_incidence(g, 0u, evf); auto test = view::basic_out_incidence(g, 0u, evf); @@ -177,7 +177,7 @@ TEST_CASE("in_incidence iterates in_edges", "[in_incidence][in]") { } SECTION("with EVF") { - auto evf = [](const auto& g, auto e) { return adj::edge_value(g, e); }; + auto evf = [](const auto& gr, auto e) { return adj::edge_value(gr, e); }; auto iview = view::in_incidence(g, v0, evf); REQUIRE(iview.size() == 2); @@ -195,7 +195,7 @@ TEST_CASE("in_incidence iterates in_edges", "[in_incidence][in]") { } SECTION("with EVF from vertex id") { - auto evf = [](const auto& g, auto e) { return adj::edge_value(g, e); }; + auto evf = [](const auto& gr, auto e) { return adj::edge_value(gr, e); }; auto iview = view::in_incidence(g, 1u, evf); REQUIRE(iview.size() == 2); // vertex 1: edges to 0 and 2 } @@ -214,7 +214,7 @@ TEST_CASE("basic_in_incidence", "[in_incidence][basic_in]") { } SECTION("with EVF — values accessible") { - auto evf = [](const auto& g, auto e) { return adj::edge_value(g, e); }; + auto evf = [](const auto& gr, auto e) { return adj::edge_value(gr, e); }; auto bview = view::basic_in_incidence(g, 0u, evf); REQUIRE(bview.size() == 2); diff --git a/tests/views/test_in_neighbors.cpp b/tests/views/test_in_neighbors.cpp index a513ae3..197f8ca 100644 --- a/tests/views/test_in_neighbors.cpp +++ b/tests/views/test_in_neighbors.cpp @@ -71,9 +71,9 @@ TEST_CASE("out_neighbors matches neighbors", "[in_neighbors][out]") { std::vector ref_ids, test_ids; for (auto [tid, v] : ref) - ref_ids.push_back(tid); + ref_ids.push_back(static_cast(tid)); for (auto [tid, v] : test) - test_ids.push_back(tid); + test_ids.push_back(static_cast(tid)); REQUIRE(ref_ids == test_ids); } @@ -87,9 +87,9 @@ TEST_CASE("out_neighbors matches neighbors", "[in_neighbors][out]") { std::vector ref_vals, test_vals; for (auto [tid, v, val] : ref) - ref_vals.push_back(val); + ref_vals.push_back(static_cast(val)); for (auto [tid, v, val] : test) - test_vals.push_back(val); + test_vals.push_back(static_cast(val)); REQUIRE(ref_vals == test_vals); } @@ -123,9 +123,9 @@ TEST_CASE("basic_out_neighbors matches basic_neighbors", "[in_neighbors][basic_o std::vector ref_ids, test_ids; for (auto ni : ref) - ref_ids.push_back(ni.target_id); + ref_ids.push_back(static_cast(ni.target_id)); for (auto ni : test) - test_ids.push_back(ni.target_id); + test_ids.push_back(static_cast(ni.target_id)); REQUIRE(ref_ids == test_ids); } @@ -251,3 +251,4 @@ TEST_CASE("in_neighbors - const graph", "[in_neighbors][const]") { REQUIRE(nview.size() == 2); } + diff --git a/tests/views/test_incidence.cpp b/tests/views/test_incidence.cpp index c7c8434..1771271 100644 --- a/tests/views/test_incidence.cpp +++ b/tests/views/test_incidence.cpp @@ -67,8 +67,8 @@ TEST_CASE("incidence - vertex with single edge", "[incidence][single]") { auto ei = *it; // edge_data, void> has just an 'edge' member // For vov graph, edge_t is an edge_descriptor - auto target = target_id(g, ei.edge); - REQUIRE(target == 1); + auto target_vid = target_id(g, ei.edge); + REQUIRE(target_vid == 1); ++it; REQUIRE(it == ilist.end()); @@ -76,7 +76,7 @@ TEST_CASE("incidence - vertex with single edge", "[incidence][single]") { SECTION("with value function") { auto v0 = vertex_t{0}; - auto ilist = incidence(g, v0, [](const auto& g, auto e) { return target_id(g, e) * 10; }); + auto ilist = incidence(g, v0, [](const auto& gr, auto e) { return target_id(gr, e) * 10; }); REQUIRE(ilist.size() == 1); @@ -114,7 +114,7 @@ TEST_CASE("incidence - vertex with multiple edges", "[incidence][multiple]") { SECTION("with value function") { auto v1 = vertex_t{1}; - auto ilist = incidence(g, v1, [](const auto& g, auto e) { return static_cast(target_id(g, e) * 100); }); + auto ilist = incidence(g, v1, [](const auto& gr, auto e) { return static_cast(target_id(gr, e) * 100); }); std::vector values; for (auto ei : ilist) { @@ -137,7 +137,7 @@ TEST_CASE("incidence - vertex with multiple edges", "[incidence][multiple]") { SECTION("structured binding - with value function") { auto v0 = vertex_t{0}; - auto ilist = incidence(g, v0, [](const auto& g, auto e) { return target_id(g, e) + 100; }); + auto ilist = incidence(g, v0, [](const auto& gr, auto e) { return target_id(gr, e) + 100; }); std::vector edge_targets; std::vector values; @@ -163,7 +163,7 @@ TEST_CASE("incidence - value function types", "[incidence][evf]") { auto v0 = vertex_t{0}; SECTION("returning string") { - auto ilist = incidence(g, v0, [](const auto& g, auto e) { return "edge_to_" + std::to_string(target_id(g, e)); }); + auto ilist = incidence(g, v0, [](const auto& gr, auto e) { return "edge_to_" + std::to_string(target_id(gr, e)); }); std::vector names; for (auto [tid, e, name] : ilist) { @@ -174,7 +174,7 @@ TEST_CASE("incidence - value function types", "[incidence][evf]") { } SECTION("returning double") { - auto ilist = incidence(g, v0, [](const auto& g, auto e) { return static_cast(target_id(g, e)) * 1.5; }); + auto ilist = incidence(g, v0, [](const auto& gr, auto e) { return static_cast(target_id(gr, e)) * 1.5; }); std::vector values; for (auto [tid, e, val] : ilist) { @@ -188,7 +188,7 @@ TEST_CASE("incidence - value function types", "[incidence][evf]") { SECTION("capturing lambda") { int multiplier = 7; auto ilist = incidence( - g, v0, [multiplier](const auto& g, auto e) { return static_cast(target_id(g, e) * multiplier); }); + g, v0, [multiplier](const auto& gr, auto e) { return static_cast(target_id(gr, e) * multiplier); }); std::vector values; for (auto [tid, e, val] : ilist) { @@ -259,8 +259,8 @@ TEST_CASE("incidence - weighted graph", "[incidence][weighted]") { SECTION("value function accessing edge weight") { auto v0 = vertex_t{0}; - auto ilist = incidence(g, v0, [](const auto& g, auto e) { - return edge_value(g, e); // Get the weight + auto ilist = incidence(g, v0, [](const auto& gr, auto e) { + return edge_value(gr, e); // Get the weight }); std::vector weights; @@ -292,7 +292,7 @@ TEST_CASE("incidence - range concepts", "[incidence][concepts]") { } SECTION("with value function") { - auto ilist = incidence(g, v0, [](const auto& g, auto e) { return target_id(g, e); }); + auto ilist = incidence(g, v0, [](const auto& gr, auto e) { return target_id(gr, e); }); STATIC_REQUIRE(std::ranges::input_range); STATIC_REQUIRE(std::ranges::forward_range); @@ -429,18 +429,18 @@ TEST_CASE("incidence - iterating all vertices", "[incidence][all]") { }; // Collect all edges from all vertices - std::vector> all_edges; + std::vector> all_edges; for (auto [id, v] : vertexlist(g)) { for (auto [tid, e] : incidence(g, v)) { - all_edges.emplace_back(source_id(g, e), tid); + all_edges.emplace_back(static_cast(source_id(g, e)), static_cast(tid)); } } REQUIRE(all_edges.size() == 3); - REQUIRE(all_edges[0] == std::pair{0, 1}); - REQUIRE(all_edges[1] == std::pair{0, 2}); - REQUIRE(all_edges[2] == std::pair{1, 2}); + REQUIRE(all_edges[0] == std::pair{0, 1}); + REQUIRE(all_edges[1] == std::pair{0, 2}); + REQUIRE(all_edges[2] == std::pair{1, 2}); } // ============================================================================= @@ -502,8 +502,8 @@ TEST_CASE("incidence - map vertices vector edges", "[incidence][map]") { auto verts = vertices(g); auto v100 = *verts.begin(); - auto ilist = incidence(g, v100, [](const auto& g, auto e) { - return target_id(g, e) - 100; // Offset from base + auto ilist = incidence(g, v100, [](const auto& gr, auto e) { + return target_id(gr, e) - 100; // Offset from base }); std::vector offsets; @@ -519,7 +519,7 @@ TEST_CASE("incidence - map vertices vector edges", "[incidence][map]") { for (auto [id, v] : vertexlist(g)) { for (auto [tid, e] : incidence(g, v)) { - all_edges.emplace_back(source_id(g, e), tid); + all_edges.emplace_back(static_cast(source_id(g, e)), static_cast(tid)); } } @@ -560,7 +560,7 @@ TEST_CASE("incidence - vector vertices map edges", "[incidence][edge_map]") { SECTION("accessing edge weights via edge_value") { auto v0 = vertex_t{0}; - auto ilist = incidence(g, v0, [](const auto& g, auto e) { return edge_value(g, e); }); + auto ilist = incidence(g, v0, [](const auto& gr, auto e) { return edge_value(gr, e); }); std::vector weights; for (auto [tid, e, w] : ilist) { @@ -616,7 +616,7 @@ TEST_CASE("incidence - map vertices map edges", "[incidence][map][edge_map]") { auto verts = vertices(g); auto v10 = *verts.begin(); - auto ilist = incidence(g, v10, [](const auto& g, auto e) { return edge_value(g, e); }); + auto ilist = incidence(g, v10, [](const auto& gr, auto e) { return edge_value(gr, e); }); std::vector weights; for (auto [tid, e, w] : ilist) { @@ -642,7 +642,7 @@ TEST_CASE("incidence - map vertices map edges", "[incidence][map][edge_map]") { std::vector> all_edges; for (auto [id, v] : vertexlist(g)) { - for (auto [tid, e, w] : incidence(g, v, [](const auto& g, auto e) { return edge_value(g, e); })) { + for (auto [tid, e, w] : incidence(g, v, [](const auto& gr, auto e) { return edge_value(gr, e); })) { all_edges.emplace_back(source_id(g, e), tid, w); } } @@ -740,7 +740,7 @@ TEST_CASE("incidence - undirected_adjacency_list basic", "[incidence][undirected auto v0_it = find_vertex(g, 0u); auto v0 = *v0_it; - auto inc = incidence(g, v0, [](const auto& g, auto e) { return edge_value(g, e); }); + auto inc = incidence(g, v0, [](const auto& gr, auto e) { return edge_value(gr, e); }); std::vector weights; std::vector targets; @@ -793,7 +793,7 @@ TEST_CASE("incidence - undirected_adjacency_list iteration order", "[incidence][ for (auto [id, v] : vertexlist(g)) { for (auto [tid, e] : incidence(g, v)) { - all_edges.emplace_back(source_id(g, e), tid); + all_edges.emplace_back(static_cast(source_id(g, e)), static_cast(tid)); } } @@ -835,7 +835,7 @@ TEST_CASE("incidence - undirected_adjacency_list range algorithms", "[incidence] } SECTION("std::ranges::count_if - count edges with weight > 20") { - auto inc = incidence(g, v0, [](const auto& g, auto e) { return edge_value(g, e); }); + auto inc = incidence(g, v0, [](const auto& gr, auto e) { return edge_value(gr, e); }); auto count = std::ranges::count_if(inc, [](auto ei) { return ei.value > 20; }); @@ -843,7 +843,7 @@ TEST_CASE("incidence - undirected_adjacency_list range algorithms", "[incidence] } SECTION("std::ranges::for_each - sum weights") { - auto inc = incidence(g, v0, [](const auto& g, auto e) { return edge_value(g, e); }); + auto inc = incidence(g, v0, [](const auto& gr, auto e) { return edge_value(gr, e); }); int total_weight = 0; std::ranges::for_each(inc, [&total_weight](auto ei) { total_weight += ei.value; }); @@ -852,7 +852,7 @@ TEST_CASE("incidence - undirected_adjacency_list range algorithms", "[incidence] } SECTION("range-based for with structured bindings") { - auto inc = incidence(g, v0, [](const auto& g, auto e) { return std::to_string(edge_value(g, e)); }); + auto inc = incidence(g, v0, [](const auto& gr, auto e) { return std::to_string(edge_value(gr, e)); }); std::vector weight_strs; for (auto [tid, e, w_str] : inc) { @@ -908,3 +908,4 @@ TEST_CASE("incidence - undirected_adjacency_list empty and single edge", "[incid REQUIRE(edge_value(g, e1) == 42); // Same edge, same weight } } + diff --git a/tests/views/test_neighbors.cpp b/tests/views/test_neighbors.cpp index becba1e..c896d7c 100644 --- a/tests/views/test_neighbors.cpp +++ b/tests/views/test_neighbors.cpp @@ -430,9 +430,9 @@ TEST_CASE("neighbors - iterating all vertices", "[neighbors][all]") { std::vector> all_neighbors; for (auto [id, v] : vertexlist(g)) { - auto source_id = id; + auto source_vid = id; for (auto [tid, neighbor] : neighbors(g, v)) { - all_neighbors.emplace_back(source_id, tid); + all_neighbors.emplace_back(source_vid, tid); } } @@ -505,9 +505,9 @@ TEST_CASE("neighbors - map vertices vector edges", "[neighbors][map]") { std::vector> all_neighbors; for (auto [id, v] : vertexlist(g)) { - auto source_id = id; + auto source_vid = id; for (auto [tid, neighbor] : neighbors(g, v)) { - all_neighbors.emplace_back(source_id, tid); + all_neighbors.emplace_back(source_vid, tid); } } @@ -617,9 +617,9 @@ TEST_CASE("neighbors - map vertices map edges", "[neighbors][map][edge_map]") { std::vector> all_neighbors; for (auto [id, v] : vertexlist(g)) { - auto source_id = id; + auto source_vid = id; for (auto [tid, neighbor] : neighbors(g, v)) { - all_neighbors.emplace_back(source_id, tid); + all_neighbors.emplace_back(source_vid, tid); } } diff --git a/tests/views/test_reverse_traversal.cpp b/tests/views/test_reverse_traversal.cpp index 1068730..d5d27cf 100644 --- a/tests/views/test_reverse_traversal.cpp +++ b/tests/views/test_reverse_traversal.cpp @@ -14,7 +14,6 @@ #include #include #include -#include #include #include #include @@ -78,7 +77,7 @@ TEST_CASE("vertices_bfs - default accessor on bidir graph", "[bfs][accessor][for std::vector visited; for (auto [v] : vertices_bfs(g, uint32_t{0})) { - visited.push_back(vertex_id(g, v)); + visited.push_back(static_cast(vertex_id(g, v))); } REQUIRE(visited.size() == 4); @@ -100,7 +99,7 @@ TEST_CASE("vertices_bfs - reverse accessor from sink", "[bfs][accessor][reverse] // BFS backwards from vertex 3 (the sink) using in_edge_accessor std::vector visited; for (auto [v] : vertices_bfs(g, uint32_t{3})) { - visited.push_back(vertex_id(g, v)); + visited.push_back(static_cast(vertex_id(g, v))); } // From 3 following incoming edges: 3 -> {1, 2} -> {0} @@ -116,7 +115,7 @@ TEST_CASE("edges_bfs - reverse accessor from sink", "[bfs][accessor][reverse]") std::vector source_ids; for (auto [uv] : edges_bfs(g, uint32_t{3})) { - source_ids.push_back(source_id(g, uv)); + source_ids.push_back(static_cast(source_id(g, uv))); } // From 3 following incoming edges: edges arriving at 3 are from 1 and 2 @@ -130,7 +129,7 @@ TEST_CASE("vertices_bfs - reverse on chain", "[bfs][accessor][reverse]") { // Reverse BFS from 3 should visit 3, 2, 1, 0 std::vector visited; for (auto [v] : vertices_bfs(g, uint32_t{3})) { - visited.push_back(vertex_id(g, v)); + visited.push_back(static_cast(vertex_id(g, v))); } REQUIRE(visited.size() == 4); @@ -148,8 +147,8 @@ TEST_CASE("vertices_bfs - reverse with value function", "[bfs][accessor][reverse std::vector ids; std::vector vals; for (auto [v, val] : vertices_bfs(g, uint32_t{3}, vvf)) { - ids.push_back(vertex_id(g, v)); - vals.push_back(val); + ids.push_back(static_cast(vertex_id(g, v))); + vals.push_back(static_cast(val)); } REQUIRE(ids == std::vector{3, 2, 1, 0}); @@ -165,7 +164,7 @@ TEST_CASE("vertices_dfs - default accessor on bidir graph", "[dfs][accessor][for std::vector visited; for (auto [v] : vertices_dfs(g, uint32_t{0})) { - visited.push_back(vertex_id(g, v)); + visited.push_back(static_cast(vertex_id(g, v))); } // DFS from 0 along the chain should visit all 4 @@ -185,7 +184,7 @@ TEST_CASE("vertices_dfs - reverse accessor from sink", "[dfs][accessor][reverse] // Reverse DFS from 3 should visit 3, 2, 1, 0 std::vector visited; for (auto [v] : vertices_dfs(g, uint32_t{3})) { - visited.push_back(vertex_id(g, v)); + visited.push_back(static_cast(vertex_id(g, v))); } REQUIRE(visited.size() == 4); @@ -197,7 +196,7 @@ TEST_CASE("edges_dfs - reverse accessor from sink", "[dfs][accessor][reverse]") std::vector neighbor_ids; for (auto [uv] : edges_dfs(g, uint32_t{3})) { - neighbor_ids.push_back(source_id(g, uv)); + neighbor_ids.push_back(static_cast(source_id(g, uv))); } // From 3 backwards: edges are 3<-2, 2<-1, 1<-0 @@ -211,8 +210,8 @@ TEST_CASE("vertices_dfs - reverse with value function", "[dfs][accessor][reverse std::vector ids; std::vector vals; for (auto [v, val] : vertices_dfs(g, uint32_t{3}, vvf)) { - ids.push_back(vertex_id(g, v)); - vals.push_back(val); + ids.push_back(static_cast(vertex_id(g, v))); + vals.push_back(static_cast(val)); } REQUIRE(ids == std::vector{3, 2, 1, 0}); @@ -228,7 +227,7 @@ TEST_CASE("vertices_dfs - reverse on diamond from sink", "[dfs][accessor][revers std::vector visited; for (auto [v] : vertices_dfs(g, uint32_t{3})) { - visited.push_back(vertex_id(g, v)); + visited.push_back(static_cast(vertex_id(g, v))); } // From 3, incoming edges lead to 1 and 2; from those, incoming edge leads to 0 @@ -248,7 +247,7 @@ TEST_CASE("vertices_topological_sort - default accessor", "[topo][accessor][forw std::vector order; for (auto [v] : vertices_topological_sort(g)) { - order.push_back(vertex_id(g, v)); + order.push_back(static_cast(vertex_id(g, v))); } REQUIRE(order.size() == 4); @@ -272,7 +271,7 @@ TEST_CASE("vertices_topological_sort - reverse accessor", "[topo][accessor][reve // Topological order of the reversed graph: 3 before {1,2}, {1,2} before 0 std::vector order; for (auto [v] : vertices_topological_sort(g)) { - order.push_back(vertex_id(g, v)); + order.push_back(static_cast(vertex_id(g, v))); } REQUIRE(order.size() == 4); @@ -289,7 +288,7 @@ TEST_CASE("edges_topological_sort - reverse accessor", "[topo][accessor][reverse std::set source_vertices; for (auto [uv] : edges_topological_sort(g)) { - source_vertices.insert(source_id(g, uv)); + source_vertices.insert(static_cast(source_id(g, uv))); } // All vertices with incoming edges (in the reversed direction = original out-edges) @@ -310,7 +309,7 @@ TEST_CASE("vertices_topological_sort_safe - reverse accessor", "[topo][accessor] std::vector order; for (auto [v] : *result) { - order.push_back(vertex_id(g, v)); + order.push_back(static_cast(vertex_id(g, v))); } REQUIRE(order.size() == 4); @@ -325,7 +324,7 @@ TEST_CASE("vertices_topological_sort_safe - reverse with VVF", "[topo][accessor] std::vector order; for (auto [v, val] : *result) { - order.push_back(val); + order.push_back(static_cast(val)); } REQUIRE(order.size() == 4); @@ -408,11 +407,11 @@ TEST_CASE("explicit out_edge_accessor matches default BFS", "[accessor][explicit std::vector default_order, explicit_order; for (auto [v] : vertices_bfs(g, uint32_t{0})) { - default_order.push_back(vertex_id(g, v)); + default_order.push_back(static_cast(vertex_id(g, v))); } for (auto [v] : vertices_bfs(g, uint32_t{0})) { - explicit_order.push_back(vertex_id(g, v)); + explicit_order.push_back(static_cast(vertex_id(g, v))); } REQUIRE(default_order == explicit_order); @@ -424,11 +423,11 @@ TEST_CASE("explicit out_edge_accessor matches default DFS", "[accessor][explicit std::vector default_order, explicit_order; for (auto [v] : vertices_dfs(g, uint32_t{0})) { - default_order.push_back(vertex_id(g, v)); + default_order.push_back(static_cast(vertex_id(g, v))); } for (auto [v] : vertices_dfs(g, uint32_t{0})) { - explicit_order.push_back(vertex_id(g, v)); + explicit_order.push_back(static_cast(vertex_id(g, v))); } REQUIRE(default_order == explicit_order); @@ -440,11 +439,11 @@ TEST_CASE("explicit out_edge_accessor matches default topo sort", "[accessor][ex std::vector default_order, explicit_order; for (auto [v] : vertices_topological_sort(g)) { - default_order.push_back(vertex_id(g, v)); + default_order.push_back(static_cast(vertex_id(g, v))); } for (auto [v] : vertices_topological_sort(g)) { - explicit_order.push_back(vertex_id(g, v)); + explicit_order.push_back(static_cast(vertex_id(g, v))); } REQUIRE(default_order == explicit_order); diff --git a/tests/views/test_topological_sort.cpp b/tests/views/test_topological_sort.cpp index e95c296..4d64aa0 100644 --- a/tests/views/test_topological_sort.cpp +++ b/tests/views/test_topological_sort.cpp @@ -1,6 +1,5 @@ #include #include -#include #include #include #include @@ -86,7 +85,7 @@ TEST_CASE("vertices_topological_sort - structured binding [v, val]", "[topo][ver Graph g = {{1, 2}, {}, {}}; auto topo = - vertices_topological_sort(g, [](const auto& g, auto v) { return static_cast(vertex_id(g, v)) * 10; }); + vertices_topological_sort(g, [](const auto& gr, auto v) { return static_cast(vertex_id(gr, v)) * 10; }); std::vector values; for (auto [v, val] : topo) { @@ -105,9 +104,9 @@ TEST_CASE("vertices_topological_sort - value function receives descriptor", "[to Graph g = {{1}, {2}, {}}; // Value function receives descriptor, not ID - auto topo = vertices_topological_sort(g, [](const auto& g, auto v) { + auto topo = vertices_topological_sort(g, [](const auto& gr, auto v) { // Can use vertex_id to convert descriptor to ID - return static_cast(vertex_id(g, v)) * 100; + return static_cast(vertex_id(gr, v)) * 100; }); std::vector values; @@ -151,7 +150,7 @@ TEST_CASE("vertices_topological_sort - complex DAG", "[topo][vertices]") { auto pos = [&](int vid) { return std::find(order.begin(), order.end(), vid) - order.begin(); }; - // Verify all edges point forward in the ordering + // Verify all edge_pairs point forward in the ordering REQUIRE(pos(0) < pos(1)); REQUIRE(pos(0) < pos(2)); REQUIRE(pos(0) < pos(3)); @@ -208,7 +207,7 @@ TEST_CASE("vertices_topological_sort - disconnected components", "[topo][vertice REQUIRE(pos(4) < pos(5)); } -TEST_CASE("vertices_topological_sort - all edges point forward", "[topo][vertices]") { +TEST_CASE("vertices_topological_sort - all edge_pairs point forward", "[topo][vertices]") { using Graph = std::vector>; // Random DAG structure Graph g = { @@ -233,7 +232,7 @@ TEST_CASE("vertices_topological_sort - all edges point forward", "[topo][vertice position[static_cast(order[i])] = i; } - // Verify ALL edges point forward + // Verify ALL edge_pairs point forward for (std::size_t u = 0; u < g.size(); ++u) { for (int v_id : g[u]) { REQUIRE(position[u] < position[static_cast(v_id)]); @@ -250,7 +249,7 @@ TEST_CASE("vertices_topological_sort - size accessor", "[topo][vertices]") { REQUIRE(topo.size() == 4); int count = 0; - for (auto [v] : topo) { + for ([[maybe_unused]] auto entry : topo) { ++count; } @@ -308,11 +307,11 @@ TEST_CASE("vertices_topological_sort VVF - num_visited tracks iteration progress REQUIRE(topo.size() == 4); } -TEST_CASE("edges_topological_sort - num_visited tracks source vertices step-by-step", "[topo][edges]") { +TEST_CASE("edges_topological_sort - num_visited tracks source vertices step-by-step", "[topo][edge_pairs]") { using Graph = std::vector>; // 0->1, 0->2, 1->2 Graph g = { - {1, 2}, // 0: 2 outgoing edges + {1, 2}, // 0: 2 outgoing edge_pairs {2}, // 1: 1 outgoing edge {} // 2: 0 outgoing edges (leaf) }; @@ -322,20 +321,20 @@ TEST_CASE("edges_topological_sort - num_visited tracks source vertices step-by-s // Before iteration: nothing consumed REQUIRE(topo_edges.num_visited() == 0); - // Iterate all edges + // Iterate all edge_pairs int edge_count = 0; - for (auto [e] : topo_edges) { + for ([[maybe_unused]] auto entry : topo_edges) { ++edge_count; } - // num_visited counts source vertices whose edges have been fully yielded. - // After exhausting all 3 edges, all source vertices are processed. - REQUIRE(edge_count == 3); // 3 edges total - // The graph has 3 vertices; all have been processed (some had edges, some didn't) + // num_visited counts source vertices whose edge_pairs have been fully yielded. + // After exhausting all 3 edge_pairs, all source vertices are processed. + REQUIRE(edge_count == 3); // 3 edge_pairs total + // The graph has 3 vertices; all have been processed (some had edge_pairs, some didn't) REQUIRE(topo_edges.num_visited() == 3); } -TEST_CASE("edges_topological_sort - num_visited zero before iteration", "[topo][edges]") { +TEST_CASE("edges_topological_sort - num_visited zero before iteration", "[topo][edge_pairs]") { using Graph = std::vector>; Graph g = {{1, 2}, {2}, {}}; @@ -347,9 +346,9 @@ TEST_CASE("edges_topological_sort - num_visited zero before iteration", "[topo][ (void)it; // suppress unused warning } -TEST_CASE("edges_topological_sort - num_visited on all-leaf graph (no edges)", "[topo][edges]") { +TEST_CASE("edges_topological_sort - num_visited on all-leaf graph (no edge_pairs)", "[topo][edge_pairs]") { using Graph = std::vector>; - // All isolated vertices, no edges at all + // All isolated vertices, no edge_pairs at all Graph g = { {}, // 0 {}, // 1 @@ -361,21 +360,21 @@ TEST_CASE("edges_topological_sort - num_visited on all-leaf graph (no edges)", " // Before iteration: must be 0 even though graph has vertices REQUIRE(topo_edges.num_visited() == 0); - // No edges to iterate + // No edge_pairs to iterate int edge_count = 0; - for (auto [e] : topo_edges) { + for ([[maybe_unused]] auto entry : topo_edges) { ++edge_count; } REQUIRE(edge_count == 0); - // No edges were yielded, so no source vertices were "processed" + // No edge_pairs were yielded, so no source vertices were "processed" REQUIRE(topo_edges.num_visited() == 0); } -TEST_CASE("edges_topological_sort - num_visited with leading edgeless vertices", "[topo][edges]") { +TEST_CASE("edges_topological_sort - num_visited with leading edgeless vertices", "[topo][edge_pairs]") { using Graph = std::vector>; // Topo order might put leaf vertices first (depending on DFS order). - // Graph: 0 has no edges, 1->2 + // Graph: 0 has no edge_pairs, 1->2 Graph g = { {}, // 0 (isolated) {2}, // 1->2 @@ -384,12 +383,12 @@ TEST_CASE("edges_topological_sort - num_visited with leading edgeless vertices", auto topo_edges = edges_topological_sort(g); - // Even if vertex 0 comes first in topo order (no edges), + // Even if vertex 0 comes first in topo order (no edge_pairs), // constructor must NOT inflate count_ REQUIRE(topo_edges.num_visited() == 0); int edge_count = 0; - for (auto [e] : topo_edges) { + for ([[maybe_unused]] auto entry : topo_edges) { ++edge_count; } @@ -397,21 +396,21 @@ TEST_CASE("edges_topological_sort - num_visited with leading edgeless vertices", REQUIRE(topo_edges.num_visited() > 0); } -TEST_CASE("edges_topological_sort - num_visited on empty graph", "[topo][edges]") { +TEST_CASE("edges_topological_sort - num_visited on empty graph", "[topo][edge_pairs]") { using Graph = std::vector>; Graph g; auto topo_edges = edges_topological_sort(g); REQUIRE(topo_edges.num_visited() == 0); - for (auto [e] : topo_edges) { + for ([[maybe_unused]] auto entry : topo_edges) { REQUIRE(false); // Should not execute } REQUIRE(topo_edges.num_visited() == 0); } -TEST_CASE("edges_topological_sort EVF - num_visited tracks source vertices", "[topo][edges]") { +TEST_CASE("edges_topological_sort EVF - num_visited tracks source vertices", "[topo][edge_pairs]") { using Graph = std::vector>; Graph g = {{1, 2}, {2}, {}}; auto evf = [](const auto& gr, auto e) { return static_cast(target_id(gr, e)); }; @@ -421,7 +420,7 @@ TEST_CASE("edges_topological_sort EVF - num_visited tracks source vertices", "[t REQUIRE(topo_edges.num_visited() == 0); int edge_count = 0; - for (auto [e, val] : topo_edges) { + for ([[maybe_unused]] auto entry : topo_edges) { ++edge_count; } @@ -429,7 +428,7 @@ TEST_CASE("edges_topological_sort EVF - num_visited tracks source vertices", "[t REQUIRE(topo_edges.num_visited() == 3); } -TEST_CASE("edges_topological_sort EVF - num_visited zero before iteration", "[topo][edges]") { +TEST_CASE("edges_topological_sort EVF - num_visited zero before iteration", "[topo][edge_pairs]") { using Graph = std::vector>; Graph g = {{1}, {2}, {}}; auto evf = [](const auto& gr, auto e) { return static_cast(target_id(gr, e)); }; @@ -440,7 +439,7 @@ TEST_CASE("edges_topological_sort EVF - num_visited zero before iteration", "[to (void)it; } -TEST_CASE("edges_topological_sort EVF - num_visited on all-leaf graph", "[topo][edges]") { +TEST_CASE("edges_topological_sort EVF - num_visited on all-leaf graph", "[topo][edge_pairs]") { using Graph = std::vector>; Graph g = {{}, {}, {}}; auto evf = [](const auto& gr, auto e) { return static_cast(target_id(gr, e)); }; @@ -449,7 +448,7 @@ TEST_CASE("edges_topological_sort EVF - num_visited on all-leaf graph", "[topo][ REQUIRE(topo_edges.num_visited() == 0); int edge_count = 0; - for (auto [e, val] : topo_edges) { + for ([[maybe_unused]] auto entry : topo_edges) { ++edge_count; } @@ -501,7 +500,7 @@ TEST_CASE("vertices_topological_sort - num_visited with post-increment", "[topo] TEST_CASE("vertices_topological_sort - num_visited on single vertex graph", "[topo][vertices]") { using Graph = std::vector>; - Graph g = {{}}; // Single vertex, no edges + Graph g = {{}}; // Single vertex, no edge_pairs auto topo = vertices_topological_sort(g); REQUIRE(topo.num_visited() == 0); @@ -522,7 +521,7 @@ TEST_CASE("vertices_topological_sort - num_visited on empty graph", "[topo][vert REQUIRE(topo.num_visited() == 0); REQUIRE(topo.size() == 0); - for (auto [v] : topo) { + for ([[maybe_unused]] auto entry : topo) { // Should not execute REQUIRE(false); } @@ -601,32 +600,34 @@ TEST_CASE("vertices_topological_sort - wide DAG", "[topo][vertices]") { // edges_topological_sort tests //=========================================================================== -TEST_CASE("edges_topological_sort - simple DAG", "[topo][edges]") { +TEST_CASE("edges_topological_sort - simple DAG", "[topo][edge_pairs]") { using Graph = std::vector>; // 0 -> 1 -> 2 Graph g = {{1}, {2}, {}}; - std::vector> edges; + std::vector> edge_pairs; for (auto [e] : edges_topological_sort(g)) { - edges.emplace_back(source_id(g, e), target_id(g, e)); + edge_pairs.emplace_back(static_cast(source_id(g, e)), static_cast(target_id(g, e))); } - REQUIRE(edges.size() == 2); - REQUIRE(edges[0] == std::make_pair(0, 1)); - REQUIRE(edges[1] == std::make_pair(1, 2)); + REQUIRE(edge_pairs.size() == 2); + REQUIRE(edge_pairs[0] == std::make_pair(0, 1)); + REQUIRE(edge_pairs[1] == std::make_pair(1, 2)); // Verify sources follow topological order - for (std::size_t i = 1; i < edges.size(); ++i) { - REQUIRE(edges[i - 1].first <= edges[i].first); + for (std::size_t i = 1; i < edge_pairs.size(); ++i) { + REQUIRE(edge_pairs[i - 1].first <= edge_pairs[i].first); } } -TEST_CASE("edges_topological_sort - diamond DAG", "[topo][edges]") { +TEST_CASE("edges_topological_sort - diamond DAG", "[topo][edge_pairs]") { using Graph = std::vector>; // 0 - // / \ - // 1 2 - // \ / + /* + * / \ + * 1 2 + * \ / + */ // 3 Graph g = {{1, 2}, {3}, {3}, {}}; @@ -634,7 +635,7 @@ TEST_CASE("edges_topological_sort - diamond DAG", "[topo][edges]") { for (auto [e] : edges_topological_sort(g)) { auto src = source_id(g, e); auto tgt = target_id(g, e); - edge_map[src].insert(tgt); + edge_map[static_cast(src)].insert(static_cast(tgt)); } REQUIRE(edge_map.size() == 3); @@ -647,14 +648,14 @@ TEST_CASE("edges_topological_sort - diamond DAG", "[topo][edges]") { REQUIRE(edge_map[2].count(3) == 1); } -TEST_CASE("edges_topological_sort - structured binding with value", "[topo][edges]") { +TEST_CASE("edges_topological_sort - structured binding with value", "[topo][edge_pairs]") { using Graph = std::vector>; // 0 -> 1 -> 2 Graph g = {{1}, {2}, {}}; std::vector> edges_with_values; - for (auto [e, val] : edges_topological_sort(g, [](const auto&, auto ed) { return 42; })) { - edges_with_values.emplace_back(source_id(g, e), target_id(g, e), val); + for (auto [e, val] : edges_topological_sort(g, [](const auto&, auto) { return 42; })) { + edges_with_values.emplace_back(static_cast(source_id(g, e)), static_cast(target_id(g, e)), val); } REQUIRE(edges_with_values.size() == 2); @@ -663,15 +664,15 @@ TEST_CASE("edges_topological_sort - structured binding with value", "[topo][edge } } -TEST_CASE("edges_topological_sort - value function receives descriptor", "[topo][edges]") { +TEST_CASE("edges_topological_sort - value function receives descriptor", "[topo][edge_pairs]") { using Graph = std::vector>; // 0 -> 1 -> 2 Graph g = {{1}, {2}, {}}; std::vector edge_ids; for (auto [e, id] : - edges_topological_sort(g, [](const auto& g, auto ed) { return source_id(g, ed) * 10 + target_id(g, ed); })) { - edge_ids.push_back(id); + edges_topological_sort(g, [](const auto& gr, auto ed) { return source_id(gr, ed) * 10 + target_id(gr, ed); })) { + edge_ids.push_back(static_cast(id)); } REQUIRE(edge_ids.size() == 2); @@ -679,16 +680,18 @@ TEST_CASE("edges_topological_sort - value function receives descriptor", "[topo] REQUIRE(edge_ids[1] == 12); // 1*10 + 2 } -TEST_CASE("edges_topological_sort - complex DAG", "[topo][edges]") { +TEST_CASE("edges_topological_sort - complex DAG", "[topo][edge_pairs]") { using Graph = std::vector>; // 0 - // / \ - // 1 2 - // |\ /| - // | X | - // |/ \| - // 3 4 - // \ / + /* + * / \ + * 1 2 + * |\ /| + * | X | + * |/ \| + * 3 4 + * \ / + */ // 5 Graph g = { {1, 2}, // 0 @@ -706,59 +709,59 @@ TEST_CASE("edges_topological_sort - complex DAG", "[topo][edges]") { // First, get vertex positions from vertices_topological_sort int pos = 0; for (auto [v] : vertices_topological_sort(g)) { - vertex_positions[vertex_id(g, v)] = pos++; + vertex_positions[static_cast(vertex_id(g, v))] = pos++; } - // Now verify edges follow topological order (sources before targets) + // Now verify edge_pairs follow topological order (sources before targets) for (auto [e] : edges_topological_sort(g)) { auto src = source_id(g, e); auto tgt = target_id(g, e); - seen_edges.emplace(src, tgt); + seen_edges.emplace(static_cast(src), static_cast(tgt)); ++edge_count; // Verify source comes before target in topological order - REQUIRE(vertex_positions[src] < vertex_positions[tgt]); + REQUIRE(vertex_positions[static_cast(src)] < vertex_positions[static_cast(tgt)]); } REQUIRE(edge_count == 8); REQUIRE(seen_edges.size() == 8); } -TEST_CASE("edges_topological_sort - disconnected components", "[topo][edges]") { +TEST_CASE("edges_topological_sort - disconnected components", "[topo][edge_pairs]") { using Graph = std::vector>; // 0 -> 1 2 -> 3 Graph g = {{1}, {}, {3}, {}}; - std::set> edges; + std::set> edge_pairs; for (auto [e] : edges_topological_sort(g)) { - edges.emplace(source_id(g, e), target_id(g, e)); + edge_pairs.emplace(static_cast(source_id(g, e)), static_cast(target_id(g, e))); } - REQUIRE(edges.size() == 2); - REQUIRE(edges.count({0, 1}) == 1); - REQUIRE(edges.count({2, 3}) == 1); + REQUIRE(edge_pairs.size() == 2); + REQUIRE(edge_pairs.count({0, 1}) == 1); + REQUIRE(edge_pairs.count({2, 3}) == 1); } -TEST_CASE("edges_topological_sort - empty graph", "[topo][edges]") { +TEST_CASE("edges_topological_sort - empty graph", "[topo][edge_pairs]") { using Graph = std::vector>; Graph g; int count = 0; - for (auto [e] : edges_topological_sort(g)) { + for ([[maybe_unused]] auto entry : edges_topological_sort(g)) { ++count; } REQUIRE(count == 0); } -TEST_CASE("edges_topological_sort - graph with no edges", "[topo][edges]") { +TEST_CASE("edges_topological_sort - graph with no edge_pairs", "[topo][edge_pairs]") { using Graph = std::vector>; // Three isolated vertices Graph g = {{}, {}, {}}; int count = 0; - for (auto [e] : edges_topological_sort(g)) { + for ([[maybe_unused]] auto entry : edges_topological_sort(g)) { ++count; } @@ -770,7 +773,7 @@ TEST_CASE("edges_topological_sort - graph with no edges", "[topo][edges]") { //=========================================================================== // NOTE: Current implementation does not explicitly detect or reject cycles. // On graphs with cycles, topological_sort produces an ordering, but it is -// NOT a valid topological ordering (some edges will point backward). +// NOT a valid topological ordering (some edge_pairs will point backward). // These tests document the current behavior. //=========================================================================== @@ -781,7 +784,7 @@ TEST_CASE("vertices_topological_sort - self-loop", "[topo][vertices][cycles]") { std::vector order; for (auto [v] : vertices_topological_sort(g)) { - order.push_back(vertex_id(g, v)); + order.push_back(static_cast(vertex_id(g, v))); } // Current behavior: produces ordering containing the vertex @@ -799,7 +802,7 @@ TEST_CASE("vertices_topological_sort - simple cycle", "[topo][vertices][cycles]" std::vector order; for (auto [v] : vertices_topological_sort(g)) { - order.push_back(vertex_id(g, v)); + order.push_back(static_cast(vertex_id(g, v))); } // Current behavior: produces an ordering with all vertices @@ -842,7 +845,7 @@ TEST_CASE("vertices_topological_sort - cycle with tail", "[topo][vertices][cycle std::vector order; for (auto [v] : vertices_topological_sort(g)) { - order.push_back(vertex_id(g, v)); + order.push_back(static_cast(vertex_id(g, v))); } REQUIRE(order.size() == 4); @@ -873,7 +876,7 @@ TEST_CASE("vertices_topological_sort - multiple cycles", "[topo][vertices][cycle std::vector order; for (auto [v] : vertices_topological_sort(g)) { - order.push_back(vertex_id(g, v)); + order.push_back(static_cast(vertex_id(g, v))); } // All vertices should be present @@ -883,40 +886,40 @@ TEST_CASE("vertices_topological_sort - multiple cycles", "[topo][vertices][cycle REQUIRE(vertices_seen.size() == 4); } -TEST_CASE("edges_topological_sort - simple cycle", "[topo][edges][cycles]") { +TEST_CASE("edges_topological_sort - simple cycle", "[topo][edge_pairs][cycles]") { using Graph = std::vector>; // Cycle: 0 -> 1 -> 2 -> 0 Graph g = {{1}, {2}, {0}}; - std::vector> edges; + std::vector> edge_pairs; for (auto [e] : edges_topological_sort(g)) { - edges.emplace_back(source_id(g, e), target_id(g, e)); + edge_pairs.emplace_back(static_cast(source_id(g, e)), static_cast(target_id(g, e))); } - // All 3 edges should be present - REQUIRE(edges.size() == 3); + // All 3 edge_pairs should be present + REQUIRE(edge_pairs.size() == 3); - // Verify all edges present - std::set> edge_set(edges.begin(), edges.end()); + // Verify all edge_pairs present + std::set> edge_set(edge_pairs.begin(), edge_pairs.end()); REQUIRE(edge_set.count({0, 1}) == 1); REQUIRE(edge_set.count({1, 2}) == 1); REQUIRE(edge_set.count({2, 0}) == 1); } -TEST_CASE("edges_topological_sort - self-loop", "[topo][edges][cycles]") { +TEST_CASE("edges_topological_sort - self-loop", "[topo][edge_pairs][cycles]") { using Graph = std::vector>; // Self-loop: 0 -> 0 Graph g = {{0}}; - std::vector> edges; + std::vector> edge_pairs; for (auto [e] : edges_topological_sort(g)) { - edges.emplace_back(source_id(g, e), target_id(g, e)); + edge_pairs.emplace_back(static_cast(source_id(g, e)), static_cast(target_id(g, e))); } // Self-loop edge should be present - REQUIRE(edges.size() == 1); - REQUIRE(edges[0].first == 0); - REQUIRE(edges[0].second == 0); + REQUIRE(edge_pairs.size() == 1); + REQUIRE(edge_pairs[0].first == 0); + REQUIRE(edge_pairs[0].second == 0); } TEST_CASE("topological_sort - cycle detection documentation", "[topo][cycles][.][documentation]") { @@ -926,7 +929,7 @@ TEST_CASE("topological_sort - cycle detection documentation", "[topo][cycles][.] // - topological_sort does NOT detect or reject cycles // - On cyclic graphs, it produces an ordering that includes all vertices // - The ordering is NOT a valid topological sort - // - Some edges will point "backward" (from later to earlier positions) + // - Some edge_pairs will point "backward" (from later to earlier positions) // // RATIONALE: // - DFS-based implementation visits all reachable vertices @@ -961,7 +964,7 @@ TEST_CASE("vertices_topological_sort_safe - valid DAG", "[topo][vertices][safe]" std::vector order; for (auto [v] : result.value()) { - order.push_back(vertex_id(g, v)); + order.push_back(static_cast(vertex_id(g, v))); } REQUIRE(order.size() == 3); @@ -1003,13 +1006,13 @@ TEST_CASE("vertices_topological_sort_safe - with value function on DAG", "[topo] // DAG: 0 -> 1 -> 2 Graph g = {{1}, {2}, {}}; - auto result = vertices_topological_sort_safe(g, [](const auto&, auto v) { return 42; }); + auto result = vertices_topological_sort_safe(g, [](const auto&, auto) { return 42; }); REQUIRE(result.has_value()); std::vector> results; for (auto [v, val] : result.value()) { - results.emplace_back(vertex_id(g, v), val); + results.emplace_back(static_cast(vertex_id(g, v)), val); } REQUIRE(results.size() == 3); @@ -1023,7 +1026,7 @@ TEST_CASE("vertices_topological_sort_safe - with value function on cycle", "[top // Cycle: 0 -> 1 -> 2 -> 0 Graph g = {{1}, {2}, {0}}; - auto result = vertices_topological_sort_safe(g, [](const auto&, auto v) { return 99; }); + auto result = vertices_topological_sort_safe(g, [](const auto&, auto) { return 99; }); REQUIRE(!result.has_value()); } @@ -1044,9 +1047,11 @@ TEST_CASE("vertices_topological_sort_safe - detects cycle with tail", "[topo][ve TEST_CASE("vertices_topological_sort_safe - diamond DAG", "[topo][vertices][safe]") { using Graph = std::vector>; // 0 - // / \ - // 1 2 - // \ / + /* + * / \ + * 1 2 + * \ / + */ // 3 Graph g = {{1, 2}, {3}, {3}, {}}; @@ -1056,7 +1061,7 @@ TEST_CASE("vertices_topological_sort_safe - diamond DAG", "[topo][vertices][safe std::vector order; for (auto [v] : *result) { - order.push_back(vertex_id(g, v)); + order.push_back(static_cast(vertex_id(g, v))); } REQUIRE(order.size() == 4); @@ -1064,7 +1069,7 @@ TEST_CASE("vertices_topological_sort_safe - diamond DAG", "[topo][vertices][safe REQUIRE(order[3] == 3); } -TEST_CASE("edges_topological_sort_safe - valid DAG", "[topo][edges][safe]") { +TEST_CASE("edges_topological_sort_safe - valid DAG", "[topo][edge_pairs][safe]") { using Graph = std::vector>; // Simple DAG: 0 -> 1 -> 2 Graph g = {{1}, {2}, {}}; @@ -1073,17 +1078,17 @@ TEST_CASE("edges_topological_sort_safe - valid DAG", "[topo][edges][safe]") { REQUIRE(result.has_value()); - std::vector> edges; + std::vector> edge_pairs; for (auto [e] : result.value()) { - edges.emplace_back(source_id(g, e), target_id(g, e)); + edge_pairs.emplace_back(static_cast(source_id(g, e)), static_cast(target_id(g, e))); } - REQUIRE(edges.size() == 2); - REQUIRE(edges[0] == std::make_pair(0, 1)); - REQUIRE(edges[1] == std::make_pair(1, 2)); + REQUIRE(edge_pairs.size() == 2); + REQUIRE(edge_pairs[0] == std::make_pair(0, 1)); + REQUIRE(edge_pairs[1] == std::make_pair(1, 2)); } -TEST_CASE("edges_topological_sort_safe - detects cycle", "[topo][edges][safe]") { +TEST_CASE("edges_topological_sort_safe - detects cycle", "[topo][edge_pairs][safe]") { using Graph = std::vector>; // Cycle: 0 -> 1 -> 2 -> 0 Graph g = {{1}, {2}, {0}}; @@ -1094,12 +1099,12 @@ TEST_CASE("edges_topological_sort_safe - detects cycle", "[topo][edges][safe]") REQUIRE(vertex_id(g, result.error()) == 0); } -TEST_CASE("edges_topological_sort_safe - with value function", "[topo][edges][safe]") { +TEST_CASE("edges_topological_sort_safe - with value function", "[topo][edge_pairs][safe]") { using Graph = std::vector>; // DAG: 0 -> 1 -> 2 Graph g = {{1}, {2}, {}}; - auto result = edges_topological_sort_safe(g, [](const auto&, auto e) { return 7; }); + auto result = edges_topological_sort_safe(g, [](const auto&, auto) { return 7; }); REQUIRE(result.has_value()); @@ -1258,7 +1263,7 @@ TEST_CASE("vertices_topological_sort_view - cancel_branch treated as can REQUIRE(count == 1); } -TEST_CASE("edges_topological_sort - cancel(cancel_all) stops iteration", "[topo][edges][cancel]") { +TEST_CASE("edges_topological_sort - cancel(cancel_all) stops iteration", "[topo][edge_pairs][cancel]") { using Graph = std::vector>; // 0 -> 1, 0 -> 2, 1 -> 3, 2 -> 3 Graph g = {{1, 2}, {3}, {3}, {}}; @@ -1278,7 +1283,7 @@ TEST_CASE("edges_topological_sort - cancel(cancel_all) stops iteration", "[topo] REQUIRE(view.cancel() == cancel_search::cancel_all); } -TEST_CASE("edges_topological_sort - cancel_branch treated as cancel_all", "[topo][edges][cancel]") { +TEST_CASE("edges_topological_sort - cancel_branch treated as cancel_all", "[topo][edge_pairs][cancel]") { using Graph = std::vector>; Graph g = {{1, 2}, {3}, {3}, {}}; @@ -1295,7 +1300,7 @@ TEST_CASE("edges_topological_sort - cancel_branch treated as cancel_all", "[topo REQUIRE(edge_count == 1); } -TEST_CASE("edges_topological_sort - cancel before iteration yields nothing", "[topo][edges][cancel]") { +TEST_CASE("edges_topological_sort - cancel before iteration yields nothing", "[topo][edge_pairs][cancel]") { using Graph = std::vector>; Graph g = {{1, 2}, {3}, {3}, {}}; @@ -1311,7 +1316,7 @@ TEST_CASE("edges_topological_sort - cancel before iteration yields nothing", "[t REQUIRE(view.num_visited() == 0); } -TEST_CASE("edges_topological_sort_view - cancel(cancel_all) stops iteration", "[topo][edges][cancel]") { +TEST_CASE("edges_topological_sort_view - cancel(cancel_all) stops iteration", "[topo][edge_pairs][cancel]") { using Graph = std::vector>; Graph g = {{1, 2}, {3}, {3}, {}}; @@ -1331,7 +1336,7 @@ TEST_CASE("edges_topological_sort_view - cancel(cancel_all) stops iterat REQUIRE(view.cancel() == cancel_search::cancel_all); } -TEST_CASE("edges_topological_sort_view - cancel_branch treated as cancel_all", "[topo][edges][cancel]") { +TEST_CASE("edges_topological_sort_view - cancel_branch treated as cancel_all", "[topo][edge_pairs][cancel]") { using Graph = std::vector>; Graph g = {{1, 2}, {3}, {3}, {}}; @@ -1363,7 +1368,7 @@ TEST_CASE("vertices_topological_sort - cancel on empty graph is safe", "[topo][v REQUIRE(count == 0); } -TEST_CASE("edges_topological_sort - cancel on empty graph is safe", "[topo][edges][cancel]") { +TEST_CASE("edges_topological_sort - cancel on empty graph is safe", "[topo][edge_pairs][cancel]") { using Graph = std::vector>; Graph g; @@ -1399,7 +1404,7 @@ TEST_CASE("vertices_topological_sort - cancel preserves num_visited accuracy", " REQUIRE(view.size() == 6); } -TEST_CASE("edges_topological_sort - cancel preserves num_visited accuracy", "[topo][edges][cancel]") { +TEST_CASE("edges_topological_sort - cancel preserves num_visited accuracy", "[topo][edge_pairs][cancel]") { using Graph = std::vector>; // 0 -> 1 -> 2 -> 3 (each vertex has exactly one edge) Graph g = {{1}, {2}, {3}, {}}; @@ -1415,8 +1420,8 @@ TEST_CASE("edges_topological_sort - cancel preserves num_visited accuracy", "[to } REQUIRE(edge_count == 2); - // num_visited counts source vertices whose edges were fully yielded - // After cancel, we got edges from first 2 source vertices but + // num_visited counts source vertices whose edge_pairs were fully yielded + // After cancel, we got edge_pairs from first 2 source vertices but // the second one's count happens when we'd advance past it // The exact count depends on when cancel fires relative to advance } @@ -1430,13 +1435,13 @@ using StrGraph = dynamic_adjacency_graph& vertex_names, - const std::vector>& edges) { + const std::vector>& edge_pairs) { using VD = copyable_vertex_t; using ED = copyable_edge_t; StrGraph g; g.load_vertices(vertex_names, [](const std::string& name) -> VD { return {name}; }); - g.load_edges(edges, [](const auto& e) -> ED { return {e.first, e.second}; }); + g.load_edges(edge_pairs, [](const auto& e) -> ED { return {e.first, e.second}; }); return g; } @@ -1516,11 +1521,11 @@ TEST_CASE("vertices_topological_sort - cycle detection with string ids", "[topo] REQUIRE((cycle_vid == "a" || cycle_vid == "b" || cycle_vid == "c")); } -TEST_CASE("edges_topological_sort - string vertex ids", "[topo][edges][non_integral]") { +TEST_CASE("edges_topological_sort - string vertex ids", "[topo][edge_pairs][non_integral]") { // DAG: a -> b -> c auto g = make_graph({"a", "b", "c"}, {{"a", "b"}, {"b", "c"}}); - SECTION("yields all edges in topological order") { + SECTION("yields all edge_pairs in topological order") { auto pairs = collect_edge_ids(g, edges_topological_sort(g)); REQUIRE(pairs.size() == 2); std::set> edge_set(pairs.begin(), pairs.end()); @@ -1532,3 +1537,4 @@ TEST_CASE("edges_topological_sort - string vertex ids", "[topo][edges][non_integ REQUIRE(it_ab < it_bc); } } + diff --git a/tests/views/test_transpose.cpp b/tests/views/test_transpose.cpp index 44cc442..4497151 100644 --- a/tests/views/test_transpose.cpp +++ b/tests/views/test_transpose.cpp @@ -15,7 +15,6 @@ #include #include #include -#include #include #include #include @@ -82,9 +81,9 @@ TEST_CASE("transpose_view - vertex CPOs forward unchanged", "[views][transpose]" // Verify vertices range produces same vertex ids std::vector g_ids, tv_ids; for (auto&& [uid, u] : view::vertexlist(g)) - g_ids.push_back(uid); + g_ids.push_back(static_cast(uid)); for (auto&& [uid, u] : view::vertexlist(tv)) - tv_ids.push_back(uid); + tv_ids.push_back(static_cast(uid)); REQUIRE(g_ids == tv_ids); } @@ -237,3 +236,4 @@ TEST_CASE("transpose_view - single vertex no edges", "[views][transpose]") { CHECK(adj_list::num_vertices(tv) == 1); } + \ No newline at end of file diff --git a/tests/views/test_unified_header.cpp b/tests/views/test_unified_header.cpp index 1da7068..d601b68 100644 --- a/tests/views/test_unified_header.cpp +++ b/tests/views/test_unified_header.cpp @@ -100,11 +100,11 @@ TEST_CASE("unified header - all search views accessible", "[unified][search_view TEST_CASE("unified header - value functions work", "[unified][value_functions]") { auto g = make_test_graph(); - auto vvf = [](const auto& g, auto v) { return vertex_id(g, v) * 10; }; + auto vvf = [](const auto& gr, auto v) { return vertex_id(gr, v) * 10; }; std::vector values; for (auto [id, v, val] : g | vertexlist(vvf)) { - values.push_back(val); + values.push_back(static_cast(val)); } REQUIRE(values.size() == 3); @@ -120,10 +120,10 @@ TEST_CASE("unified header - chaining with std::views works", "[unified][chaining std::vector results; for (auto id : g | vertexlist() | std::views::transform([](auto info) { auto [id, v] = info; - return id; + return static_cast(id); }) | std::views::filter([](int id) { return id > 0; }) | std::views::transform([](int id) { return id * 2; })) { - results.push_back(id); + results.push_back(static_cast(id)); } REQUIRE(results.size() == 2); diff --git a/tests/views/test_vertexlist.cpp b/tests/views/test_vertexlist.cpp index 5048c82..13815f5 100644 --- a/tests/views/test_vertexlist.cpp +++ b/tests/views/test_vertexlist.cpp @@ -128,8 +128,8 @@ TEST_CASE("vertexlist - multiple vertices", "[vertexlist][multiple]") { } SECTION("structured binding - with value function") { - auto vlist = vertexlist(g, [](const auto& g, auto v) { - return g[v.vertex_id()].size(); // number of edges + auto vlist = vertexlist(g, [](const auto& gr, auto v) { + return gr[v.vertex_id()].size(); // number of edges }); std::vector edge_counts; @@ -227,14 +227,14 @@ TEST_CASE("vertexlist - deque-based graph", "[vertexlist][deque]") { } SECTION("with value function") { - auto vlist = vertexlist(g, [](const auto& g, auto v) { - return g[v.vertex_id()].front(); // first edge target + auto vlist = vertexlist(g, [](const auto& gr, auto v) { + return gr[v.vertex_id()].front(); // first edge target }); std::vector targets; - for (auto [id, v, target] : vlist) { + for (auto [id, v, target_val] : vlist) { REQUIRE(id == v.vertex_id()); - targets.push_back(target); + targets.push_back(target_val); } REQUIRE(targets == std::vector{1, 2, 0}); @@ -416,10 +416,10 @@ TEST_CASE("vertexlist - weighted graph", "[vertexlist][weighted]") { } SECTION("value function can access edge data") { - auto vlist = vertexlist(g, [](const auto& g, auto v) { + auto vlist = vertexlist(g, [](const auto& gr, auto v) { // Sum of edge weights for this vertex double sum = 0.0; - for (auto [target, weight] : g[v.vertex_id()]) { + for (auto [target_vid, weight] : gr[v.vertex_id()]) { sum += weight; } return sum; @@ -452,7 +452,7 @@ TEST_CASE("vertexlist - std::ranges algorithms", "[vertexlist][algorithms]") { } SECTION("count_if") { - auto vlist = vertexlist(g, [](const auto& g, auto v) { return g[v.vertex_id()].size(); }); + auto vlist = vertexlist(g, [](const auto& gr, auto v) { return gr[v.vertex_id()].size(); }); auto count = std::ranges::count_if(vlist, [](auto vi) { return vi.value > 0; }); @@ -489,9 +489,9 @@ TEST_CASE("vertexlist - map vertices vector edges", "[vertexlist][map]") { } SECTION("with value function") { - auto vlist = vertexlist(g, [](const auto& g, auto v) { + auto vlist = vertexlist(g, [](const auto& gr, auto v) { // Return edge count for each vertex - return g.at(v.vertex_id()).size(); + return gr.at(v.vertex_id()).size(); }); std::vector edge_counts; @@ -551,10 +551,10 @@ TEST_CASE("vertexlist - vector vertices map edges", "[vertexlist][edge_map]") { } SECTION("with value function accessing edge weights") { - auto vlist = vertexlist(g, [](const auto& g, auto v) { + auto vlist = vertexlist(g, [](const auto& gr, auto v) { // Sum of edge weights for this vertex double sum = 0.0; - for (auto& [target, weight] : g[v.vertex_id()]) { + for (auto& [target_vid, weight] : gr[v.vertex_id()]) { sum += weight; } return sum; @@ -600,7 +600,7 @@ TEST_CASE("vertexlist - map vertices map edges", "[vertexlist][map][edge_map]") } SECTION("with value function") { - auto vlist = vertexlist(g, [](const auto& g, auto v) { return g.at(v.vertex_id()).size(); }); + auto vlist = vertexlist(g, [](const auto& gr, auto v) { return gr.at(v.vertex_id()).size(); }); std::vector counts; for (auto [id, v, count] : vlist) {