Skip to content

Commit

Permalink
Test reading graph with loops.
Browse files Browse the repository at this point in the history
  • Loading branch information
c-bebop committed Oct 21, 2024
1 parent a524156 commit 1a41caf
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 1 deletion.
34 changes: 34 additions & 0 deletions test/graph_input_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vertex32, decltype(emplace), EdgeListUndirectedUnweightedLoopStatic>(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<Vertex32, decltype(emplace), EdgeListUndirectedUnweightedNoLoopStatic>(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;
Expand Down
7 changes: 6 additions & 1 deletion test/graphs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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."
"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."
91 changes: 91 additions & 0 deletions test/graphs/ia-southernwomen.edges
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions test/test_graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 1a41caf

Please sign in to comment.