|
| 1 | +#pragma once |
| 2 | + |
| 3 | +#include "doctest.h" |
| 4 | + |
| 5 | +#include <hgl/hypergraph.hpp> |
| 6 | + |
| 7 | +#include <algorithm> |
| 8 | + |
| 9 | +namespace hgl_testing { |
| 10 | + |
| 11 | +template <hgl::traits::c_hypergraph HypergraphType> |
| 12 | +void verify_hypergraph_structure(const HypergraphType& actual, const HypergraphType& expected) { |
| 13 | + REQUIRE_EQ(actual.order(), expected.order()); |
| 14 | + REQUIRE_EQ(actual.size(), expected.size()); |
| 15 | + |
| 16 | + for (const auto& he_actual : actual.hyperedges()) { |
| 17 | + const auto id = he_actual.id(); |
| 18 | + REQUIRE(expected.has_hyperedge(id)); |
| 19 | + |
| 20 | + if constexpr (std::same_as<typename HypergraphType::directional_tag, hgl::undirected_t>) { |
| 21 | + auto actual_vs = actual.incident_vertex_ids(id) | std::ranges::to<std::vector>(); |
| 22 | + auto expected_vs = expected.incident_vertex_ids(id) | std::ranges::to<std::vector>(); |
| 23 | + CHECK(std::ranges::is_permutation(actual_vs, expected_vs)); |
| 24 | + } |
| 25 | + else if constexpr (std::same_as< |
| 26 | + typename HypergraphType::directional_tag, |
| 27 | + hgl::bf_directed_t>) { |
| 28 | + auto actual_tail = actual.tail_vertex_ids(id) | std::ranges::to<std::vector>(); |
| 29 | + auto expected_tail = expected.tail_vertex_ids(id) | std::ranges::to<std::vector>(); |
| 30 | + CHECK(std::ranges::is_permutation(actual_tail, expected_tail)); |
| 31 | + |
| 32 | + auto actual_head = actual.head_vertex_ids(id) | std::ranges::to<std::vector>(); |
| 33 | + auto expected_head = expected.head_vertex_ids(id) | std::ranges::to<std::vector>(); |
| 34 | + CHECK(std::ranges::is_permutation(actual_head, expected_head)); |
| 35 | + } |
| 36 | + } |
| 37 | +} |
| 38 | + |
| 39 | +template <hgl::traits::c_hypergraph HypergraphType> |
| 40 | +void verify_vertex_properties(const HypergraphType& actual, const HypergraphType& expected) { |
| 41 | + const auto properties_proj = [](const auto& item) { return item.properties(); }; |
| 42 | + |
| 43 | + CHECK(std::ranges::equal( |
| 44 | + actual.vertices(), |
| 45 | + expected.vertices(), |
| 46 | + std::ranges::equal_to{}, |
| 47 | + properties_proj, |
| 48 | + properties_proj |
| 49 | + )); |
| 50 | +} |
| 51 | + |
| 52 | +template <hgl::traits::c_hypergraph HypergraphType> |
| 53 | +void verify_hyperedge_properties(const HypergraphType& actual, const HypergraphType& expected) { |
| 54 | + const auto properties_proj = [](const auto& item) { return item.properties(); }; |
| 55 | + |
| 56 | + CHECK(std::ranges::equal( |
| 57 | + actual.hyperedges(), |
| 58 | + expected.hyperedges(), |
| 59 | + std::ranges::equal_to{}, |
| 60 | + properties_proj, |
| 61 | + properties_proj |
| 62 | + )); |
| 63 | +} |
| 64 | + |
| 65 | +} // namespace hgl_testing |
0 commit comments