Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TEST] Scenarios for fully connected and disconnected graphs #120

Merged
merged 2 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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