diff --git a/test/graph_input_tests.cpp b/test/graph_input_tests.cpp index a9d9dbb..4cec0a3 100644 --- a/test/graph_input_tests.cpp +++ b/test/graph_input_tests.cpp @@ -435,6 +435,40 @@ TEST_CASE("read_graph, floating point weights") } } +TEST_CASE("read_graph, loops") +{ + Edges32 edges; + auto emplace = [&](Vertex32 const u, Vertex32 const v) { edges.push_back({ u, v }); }; + + std::ifstream ia_southernwomen_input(graph_path + undirected_unweighted_loops_ia_southernwomen); + + // we start at 0 so we must have 18 + 1 vertices, the vertex count differs + // here since all vertices must be stored starting from 0 to highest vertex + // ID which in this case is 18 + unsigned int constexpr ia_southernwoman_vertex_count = 18 + 1; + unsigned int constexpr ia_southernwoman_loop_count = 14; + unsigned int constexpr ia_southernwoman_edge_count_loops = (89 - ia_southernwoman_loop_count) * 2 + ia_southernwoman_loop_count; + unsigned int constexpr ia_southernwoman_edge_count_no_loops = ia_southernwoman_edge_count_loops - 14; + + SECTION("reading with loops") + { + auto const [vertex_count, edge_count] = + gdsb::read_graph(ia_southernwomen_input, + std::move(emplace)); + CHECK(vertex_count == ia_southernwoman_vertex_count); + CHECK(edge_count == ia_southernwoman_edge_count_loops); + } + + SECTION("reading no loops") + { + auto const [vertex_count, edge_count] = + gdsb::read_graph(ia_southernwomen_input, + std::move(emplace)); + CHECK(vertex_count == ia_southernwoman_vertex_count); + CHECK(edge_count == ia_southernwoman_edge_count_no_loops); + } +} + TEST_CASE("read_graph, market_matrix") { Edges32 edges; diff --git a/test/graphs/README.md b/test/graphs/README.md index d4ea0b3..2658bc0 100644 --- a/test/graphs/README.md +++ b/test/graphs/README.md @@ -29,4 +29,9 @@ A synthetic graph made for testing purposes by the author. # aves-songbird-social.edges Source: https://networkrepository.com/aves-songbird-social.php Adelman, James S., et al. -"Real-world animal interaction network data sets. Animal interaction data from published studies of wild, captive, and domesticated animals." \ No newline at end of file +"Real-world animal interaction network data sets. Animal interaction data from published studies of wild, captive, and domesticated animals." + +# ia-southernwomen.edges +Source: https://networkrepository.com/ia-southernwomen.php +Davis and colleague in the 1930s +"Observed attendance at 14 social events by 18 Southern women." \ No newline at end of file diff --git a/test/graphs/ia-southernwomen.edges b/test/graphs/ia-southernwomen.edges new file mode 100644 index 0000000..7e44f5e --- /dev/null +++ b/test/graphs/ia-southernwomen.edges @@ -0,0 +1,91 @@ +% bip unweighted +% 89 18 14 +1 1 +1 2 +1 3 +1 4 +1 5 +1 6 +1 7 +1 8 +2 1 +2 2 +2 3 +2 5 +2 6 +2 9 +2 7 +3 2 +3 3 +3 4 +3 5 +3 6 +3 9 +3 7 +3 8 +4 1 +4 3 +4 4 +4 5 +4 6 +4 9 +4 7 +5 3 +5 4 +5 5 +5 9 +6 3 +6 5 +6 6 +6 7 +7 5 +7 6 +7 9 +7 7 +8 6 +8 7 +8 8 +9 5 +9 9 +9 7 +9 8 +10 9 +10 7 +10 8 +10 10 +11 7 +11 8 +11 11 +11 10 +12 7 +12 8 +12 11 +12 10 +12 12 +12 13 +13 9 +13 7 +13 8 +13 11 +13 10 +13 12 +13 13 +14 6 +14 9 +14 8 +14 11 +14 14 +14 10 +14 12 +14 13 +15 9 +15 7 +15 11 +15 14 +15 10 +16 7 +16 8 +17 8 +17 14 +18 8 +18 14 diff --git a/test/test_graph.h b/test/test_graph.h index 0d35f46..e615db1 100644 --- a/test/test_graph.h +++ b/test/test_graph.h @@ -16,6 +16,7 @@ static std::string unweighted_directed_graph_enzymes{ "ENZYMES_g1.edges" }; static std::string unweighted_directed_graph_enzymes_bin{ "ENZYMES_g1.bin" }; static std::string undirected_unweighted_soc_dolphins{ "soc-dolphins.mtx" }; static std::string undirected_weighted_aves_songbird_social{ "aves-songbird-social.edges" }; +static std::string undirected_unweighted_loops_ia_southernwomen{ "ia-southernwomen.edges" }; constexpr uint32_t enzymes_g1_vertex_count = 38; constexpr uint32_t enzymes_g1_edge_count = 168;