Skip to content

Commit 1365e2d

Browse files
committed
wip: undirected hyperedge list tests
1 parent 4bb9017 commit 1365e2d

3 files changed

Lines changed: 82 additions & 16 deletions

File tree

include/hgl/impl/undirected_hyperedge_list.hpp renamed to include/hgl/impl/hyperedge_list.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
#include <algorithm>
1010
#include <vector>
1111

12+
#ifdef HGL_TESTING
13+
namespace hgl_testing {
14+
struct test_hyperedge_list;
15+
} // namespace hgl_testing
16+
#endif
17+
1218
namespace hgl::impl {
1319

1420
// *** BENCHMARKS ***
@@ -91,6 +97,10 @@ class undirected_hyperedge_list final {
9197
return vertex_it != hyperedge_vertices.end() and *vertex_it == vertex_id;
9298
}
9399

100+
#ifdef HGL_TESTING
101+
friend struct hgl_testing::test_hyperedge_list;
102+
#endif
103+
94104
private:
95105
void _unbind_impl(
96106
hyperedge_storage_type& hyperedge_vertices, const types::id_type vertex_id
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#include "testing/hgl/constants.hpp"
2+
3+
#include <doctest.h>
4+
#include <hgl/impl/hyperedge_list.hpp>
5+
6+
#include <algorithm>
7+
8+
namespace hgl_testing {
9+
10+
TEST_SUITE_BEGIN("test_hyperedge_list");
11+
12+
struct test_hyperedge_list {
13+
template <typename HyperedgeList>
14+
typename HyperedgeList::hypergraph_storage_type& storage(HyperedgeList& sut) const noexcept {
15+
return sut._storage;
16+
}
17+
};
18+
19+
struct test_undirected_hyperedge_list : public test_hyperedge_list {
20+
using sut_type = hgl::impl::undirected_hyperedge_list;
21+
};
22+
23+
TEST_CASE_FIXTURE(test_undirected_hyperedge_list, "should initialize empty storage by default") {
24+
sut_type sut{};
25+
CHECK(storage(sut).empty());
26+
}
27+
28+
TEST_CASE_FIXTURE(
29+
test_undirected_hyperedge_list,
30+
"initialization with size parameters should properly initialize storage"
31+
) {
32+
sut_type sut(constants::n_vertices, constants::n_hyperedges);
33+
CHECK_EQ(storage(sut).size(), constants::n_hyperedges);
34+
CHECK(std::ranges::all_of(storage(sut), [](const auto& hyperedge_storage) {
35+
return hyperedge_storage.empty();
36+
}));
37+
}
38+
39+
TEST_CASE_FIXTURE(
40+
test_undirected_hyperedge_list, "add_hyperedges should properly extend the hypergraph storage"
41+
) {
42+
sut_type sut{};
43+
sut.add_hyperedges(constants::n_hyperedges);
44+
CHECK_EQ(storage(sut).size(), constants::n_hyperedges);
45+
CHECK(std::ranges::all_of(storage(sut), [](const auto& hyperedge_storage) {
46+
return hyperedge_storage.empty();
47+
}));
48+
}
49+
50+
TEST_CASE_FIXTURE(
51+
test_undirected_hyperedge_list,
52+
"remove_hyperedge should properly erase the proper hyperedge storage from the hypergraph"
53+
) {
54+
sut_type sut{constants::n_vertices, constants::n_hyperedges};
55+
REQUIRE_EQ(storage(sut).size(), constants::n_hyperedges);
56+
57+
sut.remove_hyperedge(constants::id1);
58+
CHECK_EQ(storage(sut).size(), constants::n_hyperedges - 1uz);
59+
}
60+
61+
TEST_CASE_FIXTURE(
62+
test_undirected_hyperedge_list, "hyperedge_vertices should remove an empty view by default"
63+
) {
64+
sut_type sut{constants::n_vertices, constants::n_hyperedges};
65+
CHECK(std::ranges::all_of(constants::hyperedge_ids_view, [&sut](const auto hyperedge_id) {
66+
return std::ranges::empty(sut.hyperedge_vertices(hyperedge_id));
67+
}));
68+
}
69+
70+
TEST_SUITE_END(); // test_hyperedge_list
71+
72+
} // namespace hgl_testing

tests/source/hgl/test_undirected_hyperedge_list.cpp

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)