Skip to content

Commit 22ab082

Browse files
committed
fixed errors
1 parent fc53d23 commit 22ab082

5 files changed

Lines changed: 46 additions & 34 deletions

File tree

include/hgl/directional_tags.hpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
#pragma once
66

7-
#include <type_traits>
7+
#include "types/type_traits.hpp"
88

99
namespace hgl {
1010

@@ -16,4 +16,11 @@ struct bf_directed_t {
1616
using type = std::type_identity_t<bf_directed_t>;
1717
};
1818

19+
namespace type_traits {
20+
21+
template <typename T>
22+
concept c_hypergraph_directional_tag = c_one_of<T, undirected_t, bf_directed_t>;
23+
24+
} // namespace type_traits
25+
1926
} // namespace hgl

include/hgl/hypergraph_elements.hpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
#include "constants.hpp"
88
#include "gl/vertex_descriptor.hpp"
9-
#include "hyperedge_tags.hpp"
109
#include "types/type_traits.hpp"
1110
#include "types/types.hpp"
1211

@@ -29,8 +28,6 @@ class hyperedge_descriptor final {
2928
types::empty_properties,
3029
properties_type&>;
3130

32-
friend directional_tag;
33-
3431
hyperedge_descriptor() {
3532
*this = hyperedge_descriptor::invalid();
3633
}
@@ -95,9 +92,7 @@ class hyperedge_descriptor final {
9592
std::reference_wrapper<properties_type>> _properties;
9693
};
9794

98-
template <
99-
type_traits::c_hypergraph_directional_tag DirectionalTag = undirected_t,
100-
type_traits::c_properties Properties = types::empty_properties>
101-
using hyperedge = hyperedge_descriptor<DirectionalTag, Properties>;
95+
template <type_traits::c_properties Properties = types::empty_properties>
96+
using hyperedge = hyperedge_descriptor<Properties>;
10297

10398
} // namespace hgl

include/hgl/hypergraph_traits.hpp

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,56 +4,48 @@
44

55
#pragma once
66

7+
#include "directional_tags.hpp"
78
#include "hypergraph_elements.hpp"
89
#include "impl/impl_tags.hpp"
910

1011
namespace hgl {
1112

1213
template <
13-
type_traits::c_hypergraph_directional_tag HyperedgeDirectionalTag = undirected_t,
14+
type_traits::c_hypergraph_directional_tag DirectionalTag = undirected_t,
1415
type_traits::c_properties VertexProperties = types::empty_properties,
1516
type_traits::c_properties HyperedgeProperties = types::empty_properties,
1617
type_traits::c_hypergraph_impl_tag ImplTag = impl::hyperedge_list_t>
1718
struct hypergraph_traits {
1819
using vertex_type = vertex_descriptor<VertexProperties>;
1920
using vertex_properties_type = typename vertex_type::properties_type;
2021

21-
using hyperedge_type = hyperedge_descriptor<HyperedgeDirectionalTag, HyperedgeProperties>;
22-
using hyperedge_directional_tag = typename hyperedge_type::directional_tag;
22+
using hyperedge_type = hyperedge_descriptor<HyperedgeProperties>;
2323
using hyperedge_properties_type = typename hyperedge_type::properties_type;
2424

25+
using directional_tag = DirectionalTag;
2526
using implementation_tag = ImplTag;
2627
};
2728

2829
template <
29-
type_traits::c_hypergraph_directional_tag HyperedgeDirectionalTag = undirected_t,
30+
type_traits::c_hypergraph_directional_tag DirectionalTag = undirected_t,
3031
type_traits::c_properties VertexProperties = types::empty_properties,
3132
type_traits::c_properties HyperedgeProperties = types::empty_properties>
32-
using hyperedge_list_hg_traits = hypergraph_traits<
33-
HyperedgeDirectionalTag,
34-
VertexProperties,
35-
HyperedgeProperties,
36-
impl::hyperedge_list_t>;
33+
using hyperedge_list_hg_traits =
34+
hypergraph_traits<DirectionalTag, VertexProperties, HyperedgeProperties, impl::hyperedge_list_t>;
3735

3836
template <
39-
type_traits::c_hypergraph_directional_tag HyperedgeDirectionalTag = undirected_t,
37+
type_traits::c_hypergraph_directional_tag DirectionalTag = undirected_t,
4038
type_traits::c_properties VertexProperties = types::empty_properties,
4139
type_traits::c_properties HyperedgeProperties = types::empty_properties>
42-
using adjacency_list_hg_traits = hypergraph_traits<
43-
HyperedgeDirectionalTag,
44-
VertexProperties,
45-
HyperedgeProperties,
46-
impl::adjacency_list_t>;
40+
using adjacency_list_hg_traits =
41+
hypergraph_traits<DirectionalTag, VertexProperties, HyperedgeProperties, impl::adjacency_list_t>;
4742

4843
template <
49-
type_traits::c_hypergraph_directional_tag HyperedgeDirectionalTag = undirected_t,
44+
type_traits::c_hypergraph_directional_tag DirectionalTag = undirected_t,
5045
type_traits::c_properties VertexProperties = types::empty_properties,
5146
type_traits::c_properties HyperedgeProperties = types::empty_properties>
52-
using incidence_matrix_hg_traits = hypergraph_traits<
53-
HyperedgeDirectionalTag,
54-
VertexProperties,
55-
HyperedgeProperties,
56-
impl::incidence_matrix_t>;
47+
using incidence_matrix_hg_traits =
48+
hypergraph_traits<DirectionalTag, VertexProperties, HyperedgeProperties, impl::incidence_matrix_t>;
5749

5850
template <
5951
type_traits::c_properties VertexProperties = types::empty_properties,

tests/source/hgl/test_hypergraph.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ template <
1717
gl::type_traits::c_instantiation_of<hgl::hypergraph_traits> HypergraphTraits,
1818
gl::type_traits::c_properties VertexProperties>
1919
using add_vertex_property = hgl::hypergraph_traits<
20-
typename HypergraphTraits::hyperedge_directional_tag,
20+
typename HypergraphTraits::directional_tag,
2121
VertexProperties,
2222
typename HypergraphTraits::hyperedge_properties_type,
2323
typename HypergraphTraits::implementation_tag>;
@@ -26,7 +26,7 @@ template <
2626
gl::type_traits::c_instantiation_of<gl::graph_traits> HypergraphTraits,
2727
gl::type_traits::c_properties HyperedgeProperties>
2828
using add_edge_property = hgl::hypergraph_traits<
29-
typename HypergraphTraits::edge_directional_tag,
29+
typename HypergraphTraits::directional_tag,
3030
typename HypergraphTraits::vertex_properties_type,
3131
HyperedgeProperties,
3232
typename HypergraphTraits::implementation_tag>;

tests/source/hgl/test_hypergraph_elements.cpp

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
#include "hgl/hypergraph_elements.hpp"
1+
#include "testing/hgl/constants.hpp"
2+
#include "testing/hgl/types.hpp"
23

34
#include <doctest.h>
5+
#include <hgl/hypergraph_elements.hpp>
46

57
namespace hgl_testing {
68

@@ -28,7 +30,7 @@ TEST_CASE_FIXTURE(
2830
TEST_CASE_FIXTURE(test_hyperedge_descriptor, "hyperedge should be valid only if it has a valid id") {
2931
CHECK(he1);
3032
CHECK(he2.is_valid());
31-
CHECK_FALSE(HyperedgeType::invalid());
33+
CHECK_FALSE(sut_type::invalid());
3234
}
3335

3436
TEST_CASE_FIXTURE(test_hyperedge_descriptor, "id() should return the id of the hyperedge") {
@@ -41,7 +43,23 @@ TEST_CASE_FIXTURE(test_hyperedge_descriptor, "hyperedge descriptors should be in
4143
CHECK_EQ(sut_type{}.id(), hgl::constants::invalid_id);
4244
}
4345

44-
// TODO: properties tests
46+
TEST_CASE_FIXTURE(test_hyperedge_descriptor, "properties should be properly initialized") {
47+
types::boolean_property property{constants::p_true};
48+
49+
const hgl::hyperedge<types::boolean_property> sut{id1, property};
50+
CHECK_EQ(&sut.properties(), &property);
51+
}
52+
53+
TEST_CASE("accessing properties should throw for an invalid hyperedge") {
54+
using sut_type = hgl::hyperedge<types::boolean_property>;
55+
types::boolean_property property{constants::p_true};
56+
57+
CHECK_THROWS_AS(static_cast<void>(sut_type::invalid().properties()), std::logic_error);
58+
CHECK_THROWS_AS(
59+
static_cast<void>(sut_type{hgl::constants::invalid_id, property}.properties()),
60+
std::logic_error
61+
);
62+
}
4563

4664
TEST_SUITE_END(); // test_hypergraph_elements
4765

0 commit comments

Comments
 (0)