-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_hyperedge_list.cpp
More file actions
157 lines (130 loc) · 5.87 KB
/
test_hyperedge_list.cpp
File metadata and controls
157 lines (130 loc) · 5.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#include "testing/hgl/constants.hpp"
#include <doctest.h>
#include <hgl/impl/hyperedge_list.hpp>
#include <algorithm>
namespace hgl_testing {
TEST_SUITE_BEGIN("test_hyperedge_list");
struct test_hyperedge_list {
template <typename HyperedgeList>
typename HyperedgeList::hypergraph_storage_type& storage(HyperedgeList& sut) const noexcept {
return sut._storage;
}
};
struct test_undirected_hyperedge_list : public test_hyperedge_list {
using sut_type = hgl::impl::undirected_hyperedge_list;
};
TEST_CASE_FIXTURE(test_undirected_hyperedge_list, "should initialize empty storage by default") {
sut_type sut{};
CHECK(storage(sut).empty());
}
TEST_CASE_FIXTURE(
test_undirected_hyperedge_list,
"initialization with size parameters should properly initialize storage"
) {
sut_type sut(constants::n_vertices, constants::n_hyperedges);
CHECK_EQ(storage(sut).size(), constants::n_hyperedges);
CHECK(std::ranges::all_of(storage(sut), [](const auto& hyperedge_storage) {
return hyperedge_storage.empty();
}));
}
TEST_CASE_FIXTURE(
test_undirected_hyperedge_list, "add_hyperedges should properly extend the hypergraph storage"
) {
sut_type sut{};
sut.add_hyperedges(constants::n_hyperedges);
CHECK_EQ(storage(sut).size(), constants::n_hyperedges);
CHECK(std::ranges::all_of(storage(sut), [](const auto& hyperedge_storage) {
return hyperedge_storage.empty();
}));
}
TEST_CASE_FIXTURE(
test_undirected_hyperedge_list,
"remove_hyperedge should properly erase the proper hyperedge storage from the hypergraph"
) {
sut_type sut{constants::n_vertices, constants::n_hyperedges};
REQUIRE_EQ(storage(sut).size(), constants::n_hyperedges);
sut.remove_hyperedge(constants::id1);
CHECK_EQ(storage(sut).size(), constants::n_hyperedges - 1uz);
}
TEST_CASE_FIXTURE(test_undirected_hyperedge_list, "hyperedge_size should return 0 by default") {
sut_type sut{constants::n_vertices, constants::n_hyperedges};
CHECK(std::ranges::all_of(constants::hyperedge_ids_view, [&sut](const auto hyperedge_id) {
return sut.hyperedge_size(hyperedge_id) == 0uz;
}));
}
TEST_CASE_FIXTURE(
test_undirected_hyperedge_list, "hyperedge_vertices should remove an empty view by default"
) {
sut_type sut{constants::n_vertices, constants::n_hyperedges};
CHECK(std::ranges::all_of(constants::hyperedge_ids_view, [&sut](const auto hyperedge_id) {
return std::ranges::empty(sut.hyperedge_vertices(hyperedge_id));
}));
}
TEST_CASE_FIXTURE(
test_undirected_hyperedge_list,
"bind(hyperedge, vertex) should add the vertex to the given hyperedge's storage only if the "
"they are not bound"
) {
sut_type sut{constants::n_vertices, constants::n_hyperedges};
REQUIRE(std::ranges::empty(sut.hyperedge_vertices(constants::id1)));
sut.bind(constants::id1, constants::id1);
const auto vertices1 = sut.hyperedge_vertices(constants::id1) | std::ranges::to<std::vector>();
CHECK_EQ(sut.hyperedge_size(constants::id1), 1uz);
CHECK_EQ(std::ranges::size(vertices1), 1uz);
CHECK(std::ranges::contains(vertices1, constants::id1));
CHECK(std::ranges::equal(vertices1, storage(sut)[constants::id1]));
sut.bind(constants::id1, constants::id1);
const auto vertices2 = sut.hyperedge_vertices(constants::id1) | std::ranges::to<std::vector>();
CHECK_EQ(std::ranges::size(vertices2), 1uz);
CHECK(std::ranges::equal(vertices2, vertices1));
}
TEST_CASE_FIXTURE(
test_undirected_hyperedge_list,
"unbind(hyperedge, vertex) should remove the vertex from the given hyperedge's storage only if "
"the they are bound"
) {
sut_type sut{constants::n_vertices, constants::n_hyperedges};
REQUIRE(std::ranges::empty(sut.hyperedge_vertices(constants::id1)));
sut.bind(constants::id1, constants::id1);
const auto vertices1 = sut.hyperedge_vertices(constants::id1) | std::ranges::to<std::vector>();
REQUIRE_EQ(sut.hyperedge_size(constants::id1), 1uz);
REQUIRE(std::ranges::contains(vertices1, constants::id1));
sut.unbind(constants::id1, constants::id2);
const auto vertices2 = sut.hyperedge_vertices(constants::id1) | std::ranges::to<std::vector>();
REQUIRE_EQ(std::ranges::size(vertices2), 1uz);
REQUIRE(std::ranges::equal(vertices2, vertices1));
sut.unbind(constants::id1, constants::id1);
CHECK(std::ranges::empty(sut.hyperedge_vertices(constants::id1)));
}
TEST_CASE_FIXTURE(
test_undirected_hyperedge_list,
"are_bound(hyperedge, vertex) should return true only when the given vertex is present in the "
"hyperedge's storage"
) {
sut_type sut{constants::n_vertices, constants::n_hyperedges};
REQUIRE(std::ranges::empty(sut.hyperedge_vertices(constants::id1)));
sut.bind(constants::id1, constants::id1);
const auto vertices1 = sut.hyperedge_vertices(constants::id1) | std::ranges::to<std::vector>();
REQUIRE_EQ(sut.hyperedge_size(constants::id1), 1uz);
REQUIRE(std::ranges::contains(vertices1, constants::id1));
CHECK(sut.are_bound(constants::id1, constants::id1));
CHECK_FALSE(sut.are_bound(constants::id1, constants::id2));
CHECK_FALSE(sut.are_bound(constants::id2, constants::id1));
}
TEST_CASE_FIXTURE(
test_undirected_hyperedge_list,
"remove_vertex should unbind the given vertex from all hyperedges"
) {
sut_type sut{constants::n_vertices, constants::n_hyperedges};
for (const auto hyperedge_id : constants::hyperedge_ids_view)
sut.bind(hyperedge_id, constants::id1);
REQUIRE(std::ranges::all_of(constants::hyperedge_ids_view, [&sut](const auto hyperedge_id) {
return sut.are_bound(hyperedge_id, constants::id1);
}));
sut.remove_vertex(constants::id1);
CHECK(std::ranges::all_of(constants::hyperedge_ids_view, [&sut](const auto hyperedge_id) {
return std::ranges::empty(sut.hyperedge_vertices(hyperedge_id));
}));
}
TEST_SUITE_END(); // test_hyperedge_list
} // namespace hgl_testing