@@ -58,6 +58,13 @@ TEST_CASE_FIXTURE(
5858 CHECK_EQ (storage (sut).size (), constants::n_hyperedges - 1uz);
5959}
6060
61+ TEST_CASE_FIXTURE (test_undirected_hyperedge_list, " hyperedge_size should return 0 by default" ) {
62+ sut_type sut{constants::n_vertices, constants::n_hyperedges};
63+ CHECK (std::ranges::all_of (constants::hyperedge_ids_view, [&sut](const auto hyperedge_id) {
64+ return sut.hyperedge_size (hyperedge_id) == 0uz;
65+ }));
66+ }
67+
6168TEST_CASE_FIXTURE (
6269 test_undirected_hyperedge_list, " hyperedge_vertices should remove an empty view by default"
6370) {
@@ -67,6 +74,84 @@ TEST_CASE_FIXTURE(
6774 }));
6875}
6976
77+ TEST_CASE_FIXTURE (
78+ test_undirected_hyperedge_list,
79+ " bind(hyperedge, vertex) should add the vertex to the given hyperedge's storage only if the "
80+ " they are not bound"
81+ ) {
82+ sut_type sut{constants::n_vertices, constants::n_hyperedges};
83+ REQUIRE (std::ranges::empty (sut.hyperedge_vertices (constants::id1)));
84+
85+ sut.bind (constants::id1, constants::id1);
86+ const auto vertices1 = sut.hyperedge_vertices (constants::id1) | std::ranges::to<std::vector>();
87+ CHECK_EQ (sut.hyperedge_size (constants::id1), 1uz);
88+ CHECK_EQ (std::ranges::size (vertices1), 1uz);
89+ CHECK (std::ranges::contains (vertices1, constants::id1));
90+ CHECK (std::ranges::equal (vertices1, storage (sut)[constants::id1]));
91+
92+ sut.bind (constants::id1, constants::id1);
93+ const auto vertices2 = sut.hyperedge_vertices (constants::id1) | std::ranges::to<std::vector>();
94+ CHECK_EQ (std::ranges::size (vertices2), 1uz);
95+ CHECK (std::ranges::equal (vertices2, vertices1));
96+ }
97+
98+ TEST_CASE_FIXTURE (
99+ test_undirected_hyperedge_list,
100+ " unbind(hyperedge, vertex) should remove the vertex from the given hyperedge's storage only if "
101+ " the they are bound"
102+ ) {
103+ sut_type sut{constants::n_vertices, constants::n_hyperedges};
104+ REQUIRE (std::ranges::empty (sut.hyperedge_vertices (constants::id1)));
105+
106+ sut.bind (constants::id1, constants::id1);
107+ const auto vertices1 = sut.hyperedge_vertices (constants::id1) | std::ranges::to<std::vector>();
108+ REQUIRE_EQ (sut.hyperedge_size (constants::id1), 1uz);
109+ REQUIRE (std::ranges::contains (vertices1, constants::id1));
110+
111+ sut.unbind (constants::id1, constants::id2);
112+ const auto vertices2 = sut.hyperedge_vertices (constants::id1) | std::ranges::to<std::vector>();
113+ REQUIRE_EQ (std::ranges::size (vertices2), 1uz);
114+ REQUIRE (std::ranges::equal (vertices2, vertices1));
115+
116+ sut.unbind (constants::id1, constants::id1);
117+ CHECK (std::ranges::empty (sut.hyperedge_vertices (constants::id1)));
118+ }
119+
120+ TEST_CASE_FIXTURE (
121+ test_undirected_hyperedge_list,
122+ " are_bound(hyperedge, vertex) should return true only when the given vertex is present in the "
123+ " hyperedge's storage"
124+ ) {
125+ sut_type sut{constants::n_vertices, constants::n_hyperedges};
126+ REQUIRE (std::ranges::empty (sut.hyperedge_vertices (constants::id1)));
127+
128+ sut.bind (constants::id1, constants::id1);
129+ const auto vertices1 = sut.hyperedge_vertices (constants::id1) | std::ranges::to<std::vector>();
130+ REQUIRE_EQ (sut.hyperedge_size (constants::id1), 1uz);
131+ REQUIRE (std::ranges::contains (vertices1, constants::id1));
132+
133+ CHECK (sut.are_bound (constants::id1, constants::id1));
134+ CHECK_FALSE (sut.are_bound (constants::id1, constants::id2));
135+ CHECK_FALSE (sut.are_bound (constants::id2, constants::id1));
136+ }
137+
138+ TEST_CASE_FIXTURE (
139+ test_undirected_hyperedge_list,
140+ " remove_vertex should unbind the given vertex from all hyperedges"
141+ ) {
142+ sut_type sut{constants::n_vertices, constants::n_hyperedges};
143+ for (const auto hyperedge_id : constants::hyperedge_ids_view)
144+ sut.bind (hyperedge_id, constants::id1);
145+ REQUIRE (std::ranges::all_of (constants::hyperedge_ids_view, [&sut](const auto hyperedge_id) {
146+ return sut.are_bound (hyperedge_id, constants::id1);
147+ }));
148+
149+ sut.remove_vertex (constants::id1);
150+ CHECK (std::ranges::all_of (constants::hyperedge_ids_view, [&sut](const auto hyperedge_id) {
151+ return std::ranges::empty (sut.hyperedge_vertices (hyperedge_id));
152+ }));
153+ }
154+
70155TEST_SUITE_END (); // test_hyperedge_list
71156
72157} // namespace hgl_testing
0 commit comments