Skip to content

Commit 192cd2a

Browse files
committed
wip: test_adjacency_list
1 parent bcc0a68 commit 192cd2a

5 files changed

Lines changed: 296 additions & 262 deletions

File tree

include/gl/edge_descriptor.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ class edge_descriptor final {
4949

5050
~edge_descriptor() = default;
5151

52+
// TODO: add tests
53+
[[nodiscard]] bool operator==(const edge_descriptor& other) const noexcept {
54+
return this->_id == other._id and this->_vertices == other._vertices;
55+
}
56+
5257
[[nodiscard]] constexpr bool is_directed() const noexcept {
5358
return type_traits::is_directed_v<type>;
5459
}

include/gl/impl/adjacency_list.hpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
#include "gl/types/types.hpp"
1111
#include "specialized/adjacency_list.hpp"
1212

13+
#ifdef GL_TESTING
14+
namespace gl_testing {
15+
struct test_adjacency_list;
16+
} // namespace gl_testing
17+
#endif
18+
1319
namespace gl::impl {
1420

1521
template <type_traits::c_list_graph_traits GraphTraits>
@@ -113,7 +119,7 @@ class adjacency_list final {
113119
});
114120
if (item_it == adjacent_edges.cend())
115121
return std::nullopt;
116-
return std::make_optional<edge_type>(source_id, target_id);
122+
return std::make_optional<edge_type>(item_it->id, source_id, target_id);
117123
}
118124

119125
[[nodiscard]] std::optional<edge_type> get_edge(
@@ -181,6 +187,10 @@ class adjacency_list final {
181187
});
182188
}
183189

190+
#ifdef GL_TESTING
191+
friend struct gl_testing::test_adjacency_list;
192+
#endif
193+
184194
private:
185195
using specialized_impl = typename specialized::list_impl_traits<adjacency_list>::type;
186196
friend specialized_impl;

include/gl/impl/specialized/adjacency_list.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,14 @@ struct directed_adjacency_list {
125125
if (id == vertex_id or adj_edges.empty())
126126
continue;
127127

128-
const auto rem_subrange = std::ranges::remove_if(
128+
const auto removed_subrng = std::ranges::remove_if(
129129
adj_edges, [vertex_id](const auto& item) { return item.target_id == vertex_id; }
130130
);
131131
std::ranges::copy(
132-
rem_subrange | std::views::transform(&edge_list_item::id),
132+
removed_subrng | std::views::transform(&edge_list_item::id),
133133
std::back_inserter(removed_edges)
134134
);
135-
adj_edges.erase(rem_subrange.begin(), rem_subrange.end());
135+
adj_edges.erase(removed_subrng.begin(), removed_subrng.end());
136136
}
137137

138138
// remove the list of edges incident from the vertex entirely
@@ -151,10 +151,10 @@ struct directed_adjacency_list {
151151
if (id == vertex_id or adj_edges.empty())
152152
continue;
153153

154-
const auto rem_subrange = std::ranges::remove_if(
154+
const auto removed_subrng = std::ranges::remove_if(
155155
adj_edges, [vertex_id](const auto& item) { return item.target_id == vertex_id; }
156156
);
157-
adj_edges.erase(rem_subrange.begin(), rem_subrange.end());
157+
adj_edges.erase(removed_subrng.begin(), removed_subrng.end());
158158
}
159159

160160
// remove the list of edges incident from the vertex entirely
@@ -246,11 +246,11 @@ struct undirected_adjacency_list {
246246
continue; // will be removed with the vertex's list
247247

248248
auto& adj_edges = self._list[item.target_id];
249-
const auto rem_subrange =
249+
const auto removed_subrng =
250250
std::ranges::remove_if(adj_edges, [vertex_id](const auto& edge) {
251251
return edge->is_incident_with(vertex_id);
252252
});
253-
adj_edges.erase(rem_subrange.begin(), rem_subrange.end());
253+
adj_edges.erase(removed_subrng.begin(), removed_subrng.end());
254254
}
255255

256256
// remove the list of edges incident from the vertex entirely

tests/include/testing/gl/transforms.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66

77
namespace gl_testing::transforms {
88

9+
// TODO: replace with generic get_id
910
template <
1011
gl::type_traits::c_instantiation_of<gl::vertex_descriptor> VertexType = gl::vertex_descriptor<>>
1112
inline gl::types::id_type extract_vertex_id(const VertexType& vertex) {
1213
return vertex.id();
1314
}
1415

16+
// TODO: remove
1517
template <typename T>
1618
struct address_projection {
1719
auto operator()(const T& ref) const {

0 commit comments

Comments
 (0)