Skip to content

Commit d1634d1

Browse files
committed
remaining tests
1 parent 296cb4c commit d1634d1

2 files changed

Lines changed: 74 additions & 0 deletions

File tree

include/hgl/hypergraph.hpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,20 @@ class hypergraph final {
351351
this->unbind(vertex.id(), hyperedge.id());
352352
}
353353

354+
[[nodiscard]] bool are_incident(
355+
const types::id_type vertex_id, const types::id_type hyperedge_id
356+
) const {
357+
this->_verify_vertex_id(vertex_id);
358+
this->_verify_hyperedge_id(hyperedge_id);
359+
return this->_impl.are_bound(vertex_id, hyperedge_id);
360+
}
361+
362+
[[nodiscard]] gl_attr_force_inline bool are_incident(
363+
const vertex_type& vertex, const hyperedge_type& hyperedge
364+
) const {
365+
return this->are_incident(vertex.id(), hyperedge.id());
366+
}
367+
354368
[[nodiscard]] auto incident_hyperedges(const types::id_type vertex_id) {
355369
this->_verify_vertex_id(vertex_id);
356370
return this->_impl.incident_hyperedges(vertex_id)

tests/source/hgl/test_hypergraph.cpp

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,66 @@ TEST_CASE_TEMPLATE_DEFINE(
376376

377377
// --- incidence method tests ---
378378

379+
SUBCASE("bind, unbind and are_incident should throw if either of the fiven elements is invalid"
380+
) {
381+
sut_type sut{constants::n_vertices, constants::n_hyperedges};
382+
383+
CHECK_THROWS_AS(
384+
sut.bind(constants::out_of_rng_vid, constants::out_of_rng_eid), std::out_of_range
385+
);
386+
CHECK_THROWS_AS(sut.bind(constants::id1, constants::out_of_rng_eid), std::out_of_range);
387+
CHECK_THROWS_AS(sut.bind(constants::out_of_rng_vid, constants::id1), std::out_of_range);
388+
389+
CHECK_THROWS_AS(
390+
sut.unbind(constants::out_of_rng_vid, constants::out_of_rng_eid), std::out_of_range
391+
);
392+
CHECK_THROWS_AS(sut.unbind(constants::id1, constants::out_of_rng_eid), std::out_of_range);
393+
CHECK_THROWS_AS(sut.unbind(constants::out_of_rng_vid, constants::id1), std::out_of_range);
394+
395+
CHECK_THROWS_AS(
396+
static_cast<void>(sut.are_incident(constants::out_of_rng_vid, constants::out_of_rng_eid)
397+
),
398+
std::out_of_range
399+
);
400+
CHECK_THROWS_AS(
401+
static_cast<void>(sut.are_incident(constants::id1, constants::out_of_rng_eid)),
402+
std::out_of_range
403+
);
404+
CHECK_THROWS_AS(
405+
static_cast<void>(sut.are_incident(constants::out_of_rng_vid, constants::id1)),
406+
std::out_of_range
407+
);
408+
}
409+
410+
SUBCASE("are_incident should return false by default") {
411+
sut_type sut{constants::n_vertices, constants::n_hyperedges};
412+
for (const auto vertex : sut.vertices())
413+
for (const auto hyperedge : sut.hyperedges())
414+
CHECK_FALSE(sut.are_incident(vertex, hyperedge));
415+
}
416+
417+
SUBCASE("bind should properly mark the given vertex and hyperedge as incident and unbind "
418+
"should mark them as not incident") {
419+
constexpr auto vertex_id = constants::id1;
420+
constexpr auto hyperedge_id = constants::id2;
421+
constexpr auto unbound_id = constants::id3;
422+
423+
sut_type sut{constants::n_vertices, constants::n_hyperedges};
424+
REQUIRE_FALSE(sut.are_incident(vertex_id, hyperedge_id));
425+
REQUIRE_FALSE(sut.are_incident(vertex_id, unbound_id));
426+
REQUIRE_FALSE(sut.are_incident(unbound_id, hyperedge_id));
427+
428+
sut.bind(vertex_id, hyperedge_id);
429+
CHECK(sut.are_incident(vertex_id, hyperedge_id));
430+
CHECK_FALSE(sut.are_incident(vertex_id, unbound_id));
431+
CHECK_FALSE(sut.are_incident(unbound_id, hyperedge_id));
432+
433+
sut.unbind(vertex_id, hyperedge_id);
434+
CHECK_FALSE(sut.are_incident(vertex_id, hyperedge_id));
435+
CHECK_FALSE(sut.are_incident(vertex_id, unbound_id));
436+
CHECK_FALSE(sut.are_incident(unbound_id, hyperedge_id));
437+
}
438+
379439
SUBCASE("incident_hyperedges and degree should throw if the given vertex (id) is invalid") {
380440
sut_type sut{constants::n_vertices, constants::n_hyperedges};
381441
CHECK_THROWS_AS(

0 commit comments

Comments
 (0)