Skip to content

Commit 59d480d

Browse files
committed
are_incident -> are_adjacent for (v,v) and (e,e)
1 parent ee36c8a commit 59d480d

2 files changed

Lines changed: 33 additions & 37 deletions

File tree

include/gl/graph.hpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -524,8 +524,7 @@ class graph final {
524524

525525
// --- adjacency and incidence methods ---
526526

527-
// TODO: rename to are_adjacent
528-
[[nodiscard]] bool are_incident(const id_type source_id, const id_type target_id) const {
527+
[[nodiscard]] bool are_adjacent(const id_type source_id, const id_type target_id) const {
529528
this->_verify_vertex_id(source_id);
530529
if (source_id == target_id)
531530
return true;
@@ -538,15 +537,13 @@ class graph final {
538537
return this->has_edge(source_id, target_id);
539538
}
540539

541-
// TODO: rename to are_adjacent
542-
[[nodiscard]] gl_attr_force_inline bool are_incident(
540+
[[nodiscard]] gl_attr_force_inline bool are_adjacent(
543541
const vertex_type& source, const vertex_type& target
544542
) const {
545-
return this->are_incident(source.id(), target.id());
543+
return this->are_adjacent(source.id(), target.id());
546544
}
547545

548-
// TODO: rename to are_adjacent
549-
[[nodiscard]] bool are_incident(const edge_type& edge_1, const edge_type& edge_2) const {
546+
[[nodiscard]] bool are_adjacent(const edge_type& edge_1, const edge_type& edge_2) const {
550547
this->_verify_edge(edge_1);
551548
this->_verify_edge(edge_2);
552549
return edge_1.is_incident_with(edge_2.source()) or edge_1.is_incident_with(edge_2.target());

tests/source/gl/test_graph.cpp

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -850,91 +850,90 @@ TEST_CASE_TEMPLATE_DEFINE("common graph structure tests", TraitsType, common_gra
850850
const auto v2 = sut.get_vertex(constants::v2_id);
851851
const auto v3 = sut.get_vertex(constants::v3_id);
852852

853-
SUBCASE("are_incident(vertex_id, vertex_id) should throw for out of range vertex ids") {
853+
SUBCASE("are_adjacent(vertex_id, vertex_id) should throw for out of range vertex ids") {
854854
CHECK_THROWS_AS(
855-
discard_result(sut.are_incident(constants::out_of_rng_idx, constants::v2_id)),
855+
discard_result(sut.are_adjacent(constants::out_of_rng_idx, constants::v2_id)),
856856
std::out_of_range
857857
);
858858
CHECK_THROWS_AS(
859-
discard_result(sut.are_incident(constants::v1_id, constants::out_of_rng_idx)),
859+
discard_result(sut.are_adjacent(constants::v1_id, constants::out_of_rng_idx)),
860860
std::out_of_range
861861
);
862862
}
863863

864-
SUBCASE("are_incident(vertex_id, vertex_id) should return true the ids are the same and "
864+
SUBCASE("are_adjacent(vertex_id, vertex_id) should return true the ids are the same and "
865865
"valid") {
866866
CHECK(std::ranges::all_of(constants::vertex_id_view, [&sut](const auto vertex_id) {
867-
return sut.are_incident(vertex_id, vertex_id);
867+
return sut.are_adjacent(vertex_id, vertex_id);
868868
}));
869869
}
870870

871-
SUBCASE("are_incident(vertex_id, vertex_id) should return true if there is an edge "
871+
SUBCASE("are_adjacent(vertex_id, vertex_id) should return true if there is an edge "
872872
"connecting the given vertices") {
873873
sut.add_edge(v1, v2);
874874

875-
CHECK(sut.are_incident(constants::v1_id, constants::v2_id));
876-
CHECK(sut.are_incident(constants::v2_id, constants::v1_id));
875+
CHECK(sut.are_adjacent(constants::v1_id, constants::v2_id));
876+
CHECK(sut.are_adjacent(constants::v2_id, constants::v1_id));
877877

878-
CHECK_FALSE(sut.are_incident(constants::v1_id, constants::v3_id));
879-
CHECK_FALSE(sut.are_incident(constants::v2_id, constants::v3_id));
878+
CHECK_FALSE(sut.are_adjacent(constants::v1_id, constants::v3_id));
879+
CHECK_FALSE(sut.are_adjacent(constants::v2_id, constants::v3_id));
880880
}
881881

882-
SUBCASE("are_incident(vertex, vertex) should throw if at least one of the vertices is "
882+
SUBCASE("are_adjacent(vertex, vertex) should throw if at least one of the vertices is "
883883
"invalid") {
884884
CHECK_THROWS_AS(
885885
discard_result(
886-
sut.are_incident(fixture.out_of_range_vertex, fixture.out_of_range_vertex)
886+
sut.are_adjacent(fixture.out_of_range_vertex, fixture.out_of_range_vertex)
887887
),
888888
std::out_of_range
889889
);
890890
CHECK_THROWS_AS(
891-
discard_result(sut.are_incident(fixture.out_of_range_vertex, v2)), std::out_of_range
891+
discard_result(sut.are_adjacent(fixture.out_of_range_vertex, v2)), std::out_of_range
892892
);
893893
CHECK_THROWS_AS(
894-
discard_result(sut.are_incident(v1, fixture.out_of_range_vertex)), std::out_of_range
894+
discard_result(sut.are_adjacent(v1, fixture.out_of_range_vertex)), std::out_of_range
895895
);
896896
}
897897

898-
SUBCASE("are_incident(vertex, vertex) should return true if there is an edge connecting "
898+
SUBCASE("are_adjacent(vertex, vertex) should return true if there is an edge connecting "
899899
"the given vertices") {
900900
sut.add_edge(v1, v2);
901901

902-
CHECK(sut.are_incident(v1, v2));
903-
CHECK(sut.are_incident(v2, v1));
902+
CHECK(sut.are_adjacent(v1, v2));
903+
CHECK(sut.are_adjacent(v2, v1));
904904

905-
CHECK_FALSE(sut.are_incident(v1, v3));
906-
CHECK_FALSE(sut.are_incident(v2, v3));
905+
CHECK_FALSE(sut.are_adjacent(v1, v3));
906+
CHECK_FALSE(sut.are_adjacent(v2, v3));
907907
}
908908

909-
SUBCASE("are_incident(vertex, vertex) should return true the vertices are the same and "
909+
SUBCASE("are_adjacent(vertex, vertex) should return true the vertices are the same and "
910910
"valid") {
911911
CHECK(std::ranges::all_of(sut.vertices(), [&sut](const auto& vertex) {
912-
return sut.are_incident(vertex, vertex);
912+
return sut.are_adjacent(vertex, vertex);
913913
}));
914914
}
915915

916-
SUBCASE("are_incident(edge, edge) should throw if either edge is invalid") {
916+
SUBCASE("are_adjacent(edge, edge) should throw if either edge is invalid") {
917917
const auto edge = sut.add_edge(v1, v2);
918918
const edge_type invalid_edge{gl::invalid_id, v1.id(), v2.id()};
919919

920920
CHECK_THROWS_AS(
921-
discard_result(sut.are_incident(edge, invalid_edge)), std::invalid_argument
921+
discard_result(sut.are_adjacent(edge, invalid_edge)), std::invalid_argument
922922
);
923923
CHECK_THROWS_AS(
924-
discard_result(sut.are_incident(invalid_edge, edge)), std::invalid_argument
924+
discard_result(sut.are_adjacent(invalid_edge, edge)), std::invalid_argument
925925
);
926926
}
927927

928-
SUBCASE("are_incident(edge, edge) should return true only when the edges share a common "
929-
"vertex") {
928+
SUBCASE("are_adjacent(edge, edge) should return true only when the edges share a vertex") {
930929
const auto edge_1 = sut.add_edge(v1, v2);
931930
const auto edge_2 = sut.add_edge(v2, v3);
932931
const auto loop_3 = sut.add_edge(v3, v3);
933932

934-
CHECK(sut.are_incident(edge_1, edge_2));
935-
CHECK(sut.are_incident(edge_2, edge_1));
936-
CHECK_FALSE(sut.are_incident(edge_1, loop_3));
937-
CHECK_FALSE(sut.are_incident(loop_3, edge_1));
933+
CHECK(sut.are_adjacent(edge_1, edge_2));
934+
CHECK(sut.are_adjacent(edge_2, edge_1));
935+
CHECK_FALSE(sut.are_adjacent(edge_1, loop_3));
936+
CHECK_FALSE(sut.are_adjacent(loop_3, edge_1));
938937
}
939938

940939
SUBCASE("are_incident(vertex and edge pair) should throw if the vertex is invalid") {

0 commit comments

Comments
 (0)