Skip to content

Commit

Permalink
[TEST] Scenarios for fully connected and disconnected graphs (#120)
Browse files Browse the repository at this point in the history
* Fully connected graph scenario
* Disconnected graph scenario
  • Loading branch information
joweich authored Oct 3, 2023
1 parent 2554ea3 commit 6439083
Show file tree
Hide file tree
Showing 2 changed files with 140 additions and 0 deletions.
88 changes: 88 additions & 0 deletions test/utils/scenarios/scenarios.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,94 @@ template <typename GRAPH_T>
template <typename GRAPH_T>
[[nodiscard]] scenario<GRAPH_T> create_simple_graph_scenario();

/**
* Creates a scenario containing a fully connected graph structure. In the
* visualization below, vertices and edge values are shown. Vertex IDs are given
* between parentheses.
*
* The direction of the edges is visualized. However, undirected edges are
* supported as well if an undirected graph is passed as a template parameter.
*
*
* ┌─────────────────┐
* │ │
* ┌────────┐ │
* ┌──── │ 10 (0) │ ─┐ │
* │ └────────┘ │ │
* │ │ │ │
* │ │ 100 │ │
* │ ▼ │ │
* │ ┌────────┐ │ │
* ┌────┼──── │ 20 (1) │ ─┼───────┼────────────┐
* │ │ └────────┘ │ │ │
* │ │ │ │ │ │
* │ │ │ 500 │ 200 │ │
* │ │ ▼ │ │ │
* │ │ ┌────────┐ │ │ │
* ┌────┼────┼──── │ 30 (2) │ ◀┘ │ │
* │ │ │ └────────┘ │ │
* │ │ │ │ │ │
* │ │ │ 300 │ 800 │ │ 700
* │ │ │ ▼ │ │
* │ │ │ ┌────────┐ 600 │ │
* │ │ └───▶ │ 40 (3) │ ◀────────┼───────┐ │
* │ │ └────────┘ │ │ │
* │ │ │ │ │ │
* │ │ │ 1000 │ 400 │ │
* │ │ ▼ ▼ │ │
* │ │ 900 ┌────────────────────────┐ │ │
* └────┼────────▶ │ 50 (4) │ ◀┼────┘
* │ └────────────────────────┘ │
* │ │
* └──────────────────────────────────────┘
*
* @tparam GRAPH_T Can be either a directed or undirected graph with numeric
* vertices and edges.
* @return The scenario containing the graph structure.
*/
template <typename GRAPH_T>
[[nodiscard]] scenario<GRAPH_T> create_fully_connected_graph_scenario();

/**
* Creates a scenario containing a disconnected graph consisting of two
* conntected subgraphs. In the visualization below, vertices and edge values
* are shown. Vertex IDs are given between parentheses.
*
* The direction of the edges is visualized. However, undirected edges are
* supported as well if an undirected graph is passed as a template parameter.
*
*
*┌────────┐ 200 ┌────────┐
*│ 30 (2) │ ◀───── │ 10 (0) │
*└────────┘ └────────┘
* │
* │ 100
* ▼
* ┌────────┐
* │ 20 (1) │
* └────────┘
* ┌────────┐
* │ 40 (3) │ ◀┐
* └────────┘ │
* │ │
* │ 300 │
* ▼ │
* ┌────────┐ │
* │ 50 (4) │ │ 500
* └────────┘ │
* │ │
* │ 400 │
* ▼ │
* ┌────────┐ │
* │ 60 (5) │ ─┘
* └────────┘
*
* @tparam GRAPH_T Can be either a directed or undirected graph with numeric
* vertices and edges.
* @return The scenario containing the graph structure.
*/
template <typename GRAPH_T>
[[nodiscard]] scenario<GRAPH_T> create_disconnected_graph_scenario();
} // namespace graaf::utils::scenarios

#include "scenarios.tpp"
52 changes: 52 additions & 0 deletions test/utils/scenarios/scenarios.tpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,56 @@ scenario<GRAPH_T> create_simple_graph_scenario() {
return {std::move(graph), std::move(vertex_ids)};
}

template <typename GRAPH_T>
scenario<GRAPH_T> create_fully_connected_graph_scenario() {
std::vector<vertex_id_t> vertex_ids{};
vertex_ids.reserve(5);

GRAPH_T graph{};

vertex_ids.push_back(graph.add_vertex(10));
vertex_ids.push_back(graph.add_vertex(20));
vertex_ids.push_back(graph.add_vertex(30));
vertex_ids.push_back(graph.add_vertex(40));
vertex_ids.push_back(graph.add_vertex(50));

graph.add_edge(vertex_ids[0], vertex_ids[1], 100);
graph.add_edge(vertex_ids[0], vertex_ids[2], 200);
graph.add_edge(vertex_ids[0], vertex_ids[3], 300);
graph.add_edge(vertex_ids[0], vertex_ids[4], 400);
graph.add_edge(vertex_ids[1], vertex_ids[2], 500);
graph.add_edge(vertex_ids[1], vertex_ids[3], 600);
graph.add_edge(vertex_ids[1], vertex_ids[4], 700);
graph.add_edge(vertex_ids[2], vertex_ids[3], 800);
graph.add_edge(vertex_ids[2], vertex_ids[4], 900);
graph.add_edge(vertex_ids[3], vertex_ids[4], 1000);

return {std::move(graph), std::move(vertex_ids)};
}

template <typename GRAPH_T>
scenario<GRAPH_T> create_disconnected_graph_scenario() {
std::vector<vertex_id_t> vertex_ids{};
vertex_ids.reserve(6);

GRAPH_T graph{};

vertex_ids.push_back(graph.add_vertex(10));
vertex_ids.push_back(graph.add_vertex(20));
vertex_ids.push_back(graph.add_vertex(30));

vertex_ids.push_back(graph.add_vertex(40));
vertex_ids.push_back(graph.add_vertex(50));
vertex_ids.push_back(graph.add_vertex(60));

graph.add_edge(vertex_ids[0], vertex_ids[1], 100);
graph.add_edge(vertex_ids[0], vertex_ids[2], 200);

graph.add_edge(vertex_ids[3], vertex_ids[4], 300);
graph.add_edge(vertex_ids[4], vertex_ids[5], 400);
graph.add_edge(vertex_ids[5], vertex_ids[3], 500);

return {std::move(graph), std::move(vertex_ids)};
}

} // namespace graaf::utils::scenarios

0 comments on commit 6439083

Please sign in to comment.