Skip to content

Commit 2210e53

Browse files
committed
more test alignments
1 parent 0542d44 commit 2210e53

4 files changed

Lines changed: 405 additions & 406 deletions

File tree

include/gl/edge_descriptor.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ class edge_descriptor final {
157157
return this->_vertices.first == this->_vertices.second;
158158
}
159159

160-
[[nodiscard]] gl_attr_force_inline properties_type& properties() const noexcept {
160+
[[nodiscard]] gl_attr_force_inline properties_ref_type properties() const {
161+
// TODO: throw if edge is invalid
161162
return this->_properties;
162163
}
163164

include/gl/vertex_descriptor.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ class vertex_descriptor final {
3535
requires(type_traits::c_non_empty_properties<properties_type>)
3636
: _id(id), _properties(properties) {}
3737

38-
// TODO: invalid vertex builders, is_valid function, default ctor -> invalid
39-
4038
vertex_descriptor(const vertex_descriptor&) = default;
4139
vertex_descriptor& operator=(const vertex_descriptor&) = default;
4240

Lines changed: 166 additions & 166 deletions
Original file line numberDiff line numberDiff line change
@@ -1,166 +1,166 @@
1-
// #include "testing/gl/constants.hpp"
2-
// #include "testing/gl/functional.hpp"
3-
4-
// #include <gl/graph.hpp>
5-
6-
// #include <doctest.h>
7-
8-
// namespace gl_testing {
9-
10-
// TEST_SUITE_BEGIN("test_graph_incidence");
11-
12-
// TEST_CASE_TEMPLATE_DEFINE("incidence functions tests", SutType, graph_type_template) {
13-
// using vertex_type = gl::vertex_descriptor<>;
14-
15-
// SutType sut{constants::n_elements};
16-
17-
// const auto& vd_1 = sut.get_vertex(constants::vertex_id_1);
18-
// const auto& vd_2 = sut.get_vertex(constants::vertex_id_2);
19-
// const auto& vd_3 = sut.get_vertex(constants::vertex_id_3);
20-
// vertex_type out_of_range_vertex{constants::out_of_range_element_idx};
21-
22-
// SUBCASE("are_incident(vertex_id, vertex_id) should throw for out of range vertex ids") {
23-
// CHECK_THROWS_AS(
24-
// func::discard_result(
25-
// sut.are_incident(constants::out_of_range_element_idx, constants::vertex_id_2)
26-
// ),
27-
// std::out_of_range
28-
// );
29-
// CHECK_THROWS_AS(
30-
// func::discard_result(
31-
// sut.are_incident(constants::vertex_id_1, constants::out_of_range_element_idx)
32-
// ),
33-
// std::out_of_range
34-
// );
35-
// }
36-
37-
// SUBCASE("are_incident(vertex_id, vertex_id) should return true the ids are the same and valid"
38-
// ) {
39-
// CHECK(std::ranges::all_of(constants::vertex_id_view, [&sut](const auto vertex_id) {
40-
// return sut.are_incident(vertex_id, vertex_id);
41-
// }));
42-
// }
43-
44-
// SUBCASE("are_incident(vertex_id, vertex_id) should return true if there is an edge connecting "
45-
// "the given vertices") {
46-
// sut.add_edge(vd_1, vd_2);
47-
48-
// CHECK(sut.are_incident(constants::vertex_id_1, constants::vertex_id_2));
49-
// CHECK(sut.are_incident(constants::vertex_id_2, constants::vertex_id_1));
50-
51-
// CHECK_FALSE(sut.are_incident(constants::vertex_id_1, constants::vertex_id_3));
52-
// CHECK_FALSE(sut.are_incident(constants::vertex_id_2, constants::vertex_id_3));
53-
// }
54-
55-
// SUBCASE("are_incident(vertex, vertex) should throw if at least one of the vertices is invalid"
56-
// ) {
57-
// CHECK_THROWS_AS(
58-
// func::discard_result(sut.are_incident(out_of_range_vertex, out_of_range_vertex)),
59-
// std::out_of_range
60-
// );
61-
// CHECK_THROWS_AS(
62-
// func::discard_result(sut.are_incident(out_of_range_vertex, vd_2)), std::out_of_range
63-
// );
64-
// CHECK_THROWS_AS(
65-
// func::discard_result(sut.are_incident(vd_1, out_of_range_vertex)), std::out_of_range
66-
// );
67-
// }
68-
69-
// SUBCASE("are_incident(vertex, vertex) should return true if there is an edge connecting the "
70-
// "given vertices") {
71-
// sut.add_edge(vd_1, vd_2);
72-
73-
// CHECK(sut.are_incident(vd_1, vd_2));
74-
// CHECK(sut.are_incident(vd_2, vd_1));
75-
76-
// CHECK_FALSE(sut.are_incident(vd_1, vd_3));
77-
// CHECK_FALSE(sut.are_incident(vd_2, vd_3));
78-
// }
79-
80-
// SUBCASE("are_incident(vertex, vertex) should return true the vertices are the same and valid") {
81-
// CHECK(std::ranges::all_of(sut.vertices(), [&sut](const auto& vertex) {
82-
// return sut.are_incident(vertex, vertex);
83-
// }));
84-
// }
85-
86-
// SUBCASE("are_incident(vertex and edge pair) should throw if the vertex is invalid") {
87-
// const auto& edge = sut.add_edge(vd_1, vd_2);
88-
89-
// CHECK_THROWS_AS(
90-
// func::discard_result(sut.are_incident(out_of_range_vertex, edge)), std::out_of_range
91-
// );
92-
// CHECK_THROWS_AS(
93-
// func::discard_result(sut.are_incident(out_of_range_vertex, edge)), std::out_of_range
94-
// );
95-
96-
// CHECK_THROWS_AS(
97-
// func::discard_result(sut.are_incident(edge, out_of_range_vertex)), std::out_of_range
98-
// );
99-
// CHECK_THROWS_AS(
100-
// func::discard_result(sut.are_incident(edge, out_of_range_vertex)), std::out_of_range
101-
// );
102-
// }
103-
104-
// SUBCASE("are_incident(vertex and edge pair) should throw if the edge is invalid") {
105-
// const typename SutType::edge_type invalid_edge{vd_1.id(), vd_2.id()};
106-
107-
// CHECK_THROWS_AS(
108-
// func::discard_result(sut.are_incident(vd_1, invalid_edge)), std::invalid_argument
109-
// );
110-
// CHECK_THROWS_AS(
111-
// func::discard_result(sut.are_incident(vd_1, invalid_edge)), std::invalid_argument
112-
// );
113-
114-
// CHECK_THROWS_AS(
115-
// func::discard_result(sut.are_incident(invalid_edge, vd_2)), std::invalid_argument
116-
// );
117-
// CHECK_THROWS_AS(
118-
// func::discard_result(sut.are_incident(invalid_edge, vd_2)), std::invalid_argument
119-
// );
120-
// }
121-
122-
// SUBCASE("are_incident(vertex and edge pair) should return true only when the edge and the "
123-
// "vertex are incident with each other") {
124-
// const auto& edge = sut.add_edge(vd_1, vd_2);
125-
126-
// CHECK(sut.are_incident(vd_1, edge));
127-
// CHECK(sut.are_incident(vd_2, edge));
128-
129-
// CHECK(sut.are_incident(edge, vd_1));
130-
// CHECK(sut.are_incident(edge, vd_2));
131-
// }
132-
133-
// SUBCASE("are_incident(edge, edge) should throw if either edge is invalid") {
134-
// const auto& edge = sut.add_edge(vd_1, vd_2);
135-
// const typename SutType::edge_type invalid_edge{vd_1.id(), vd_2.id()};
136-
137-
// CHECK_THROWS_AS(
138-
// func::discard_result(sut.are_incident(edge, invalid_edge)), std::invalid_argument
139-
// );
140-
// CHECK_THROWS_AS(
141-
// func::discard_result(sut.are_incident(invalid_edge, edge)), std::invalid_argument
142-
// );
143-
// }
144-
145-
// SUBCASE("are_incident(edge, edge) should return true only when the edges share a common vertex"
146-
// ) {
147-
// const auto& edge_1 = sut.add_edge(vd_1, vd_2);
148-
// const auto& edge_2 = sut.add_edge(vd_2, vd_3);
149-
// const auto& loop_3 = sut.add_edge(vd_3, vd_3);
150-
151-
// CHECK(sut.are_incident(edge_1, edge_2));
152-
// CHECK(sut.are_incident(edge_2, edge_1));
153-
// CHECK_FALSE(sut.are_incident(edge_1, loop_3));
154-
// CHECK_FALSE(sut.are_incident(loop_3, edge_1));
155-
// }
156-
// }
157-
158-
// TEST_CASE_TEMPLATE_INSTANTIATE(
159-
// graph_type_template,
160-
// gl::graph<gl::graph_traits<gl::directed_t>>, // directed graph
161-
// gl::graph<gl::graph_traits<gl::undirected_t>> // undirected graph
162-
// );
163-
164-
// TEST_SUITE_END(); // test_graph_incidence
165-
166-
// } // namespace gl_testing
1+
#include "testing/gl/constants.hpp"
2+
#include "testing/gl/functional.hpp"
3+
4+
#include <gl/graph.hpp>
5+
6+
#include <doctest.h>
7+
8+
namespace gl_testing {
9+
10+
TEST_SUITE_BEGIN("test_graph_incidence");
11+
12+
TEST_CASE_TEMPLATE_DEFINE("incidence functions tests", SutType, graph_type_template) {
13+
using vertex_type = gl::vertex_descriptor<>;
14+
15+
SutType sut{constants::n_elements};
16+
17+
const auto vd_1 = sut.get_vertex(constants::vertex_id_1);
18+
const auto vd_2 = sut.get_vertex(constants::vertex_id_2);
19+
const auto vd_3 = sut.get_vertex(constants::vertex_id_3);
20+
vertex_type out_of_range_vertex{constants::out_of_range_element_idx};
21+
22+
SUBCASE("are_incident(vertex_id, vertex_id) should throw for out of range vertex ids") {
23+
CHECK_THROWS_AS(
24+
func::discard_result(
25+
sut.are_incident(constants::out_of_range_element_idx, constants::vertex_id_2)
26+
),
27+
std::out_of_range
28+
);
29+
CHECK_THROWS_AS(
30+
func::discard_result(
31+
sut.are_incident(constants::vertex_id_1, constants::out_of_range_element_idx)
32+
),
33+
std::out_of_range
34+
);
35+
}
36+
37+
SUBCASE("are_incident(vertex_id, vertex_id) should return true the ids are the same and valid"
38+
) {
39+
CHECK(std::ranges::all_of(constants::vertex_id_view, [&sut](const auto vertex_id) {
40+
return sut.are_incident(vertex_id, vertex_id);
41+
}));
42+
}
43+
44+
SUBCASE("are_incident(vertex_id, vertex_id) should return true if there is an edge connecting "
45+
"the given vertices") {
46+
sut.add_edge(vd_1, vd_2);
47+
48+
CHECK(sut.are_incident(constants::vertex_id_1, constants::vertex_id_2));
49+
CHECK(sut.are_incident(constants::vertex_id_2, constants::vertex_id_1));
50+
51+
CHECK_FALSE(sut.are_incident(constants::vertex_id_1, constants::vertex_id_3));
52+
CHECK_FALSE(sut.are_incident(constants::vertex_id_2, constants::vertex_id_3));
53+
}
54+
55+
SUBCASE("are_incident(vertex, vertex) should throw if at least one of the vertices is invalid"
56+
) {
57+
CHECK_THROWS_AS(
58+
func::discard_result(sut.are_incident(out_of_range_vertex, out_of_range_vertex)),
59+
std::out_of_range
60+
);
61+
CHECK_THROWS_AS(
62+
func::discard_result(sut.are_incident(out_of_range_vertex, vd_2)), std::out_of_range
63+
);
64+
CHECK_THROWS_AS(
65+
func::discard_result(sut.are_incident(vd_1, out_of_range_vertex)), std::out_of_range
66+
);
67+
}
68+
69+
SUBCASE("are_incident(vertex, vertex) should return true if there is an edge connecting the "
70+
"given vertices") {
71+
sut.add_edge(vd_1, vd_2);
72+
73+
CHECK(sut.are_incident(vd_1, vd_2));
74+
CHECK(sut.are_incident(vd_2, vd_1));
75+
76+
CHECK_FALSE(sut.are_incident(vd_1, vd_3));
77+
CHECK_FALSE(sut.are_incident(vd_2, vd_3));
78+
}
79+
80+
SUBCASE("are_incident(vertex, vertex) should return true the vertices are the same and valid") {
81+
CHECK(std::ranges::all_of(sut.vertices(), [&sut](const auto& vertex) {
82+
return sut.are_incident(vertex, vertex);
83+
}));
84+
}
85+
86+
SUBCASE("are_incident(vertex and edge pair) should throw if the vertex is invalid") {
87+
const auto edge = sut.add_edge(vd_1, vd_2);
88+
89+
CHECK_THROWS_AS(
90+
func::discard_result(sut.are_incident(out_of_range_vertex, edge)), std::out_of_range
91+
);
92+
CHECK_THROWS_AS(
93+
func::discard_result(sut.are_incident(out_of_range_vertex, edge)), std::out_of_range
94+
);
95+
96+
CHECK_THROWS_AS(
97+
func::discard_result(sut.are_incident(edge, out_of_range_vertex)), std::out_of_range
98+
);
99+
CHECK_THROWS_AS(
100+
func::discard_result(sut.are_incident(edge, out_of_range_vertex)), std::out_of_range
101+
);
102+
}
103+
104+
SUBCASE("are_incident(vertex and edge pair) should throw if the edge is invalid") {
105+
const typename SutType::edge_type invalid_edge{constants::invalid_id, vd_1.id(), vd_2.id()};
106+
107+
CHECK_THROWS_AS(
108+
func::discard_result(sut.are_incident(vd_1, invalid_edge)), std::invalid_argument
109+
);
110+
CHECK_THROWS_AS(
111+
func::discard_result(sut.are_incident(vd_1, invalid_edge)), std::invalid_argument
112+
);
113+
114+
CHECK_THROWS_AS(
115+
func::discard_result(sut.are_incident(invalid_edge, vd_2)), std::invalid_argument
116+
);
117+
CHECK_THROWS_AS(
118+
func::discard_result(sut.are_incident(invalid_edge, vd_2)), std::invalid_argument
119+
);
120+
}
121+
122+
SUBCASE("are_incident(vertex and edge pair) should return true only when the edge and the "
123+
"vertex are incident with each other") {
124+
const auto edge = sut.add_edge(vd_1, vd_2);
125+
126+
CHECK(sut.are_incident(vd_1, edge));
127+
CHECK(sut.are_incident(vd_2, edge));
128+
129+
CHECK(sut.are_incident(edge, vd_1));
130+
CHECK(sut.are_incident(edge, vd_2));
131+
}
132+
133+
SUBCASE("are_incident(edge, edge) should throw if either edge is invalid") {
134+
const auto edge = sut.add_edge(vd_1, vd_2);
135+
const typename SutType::edge_type invalid_edge{constants::invalid_id, vd_1.id(), vd_2.id()};
136+
137+
CHECK_THROWS_AS(
138+
func::discard_result(sut.are_incident(edge, invalid_edge)), std::invalid_argument
139+
);
140+
CHECK_THROWS_AS(
141+
func::discard_result(sut.are_incident(invalid_edge, edge)), std::invalid_argument
142+
);
143+
}
144+
145+
SUBCASE("are_incident(edge, edge) should return true only when the edges share a common vertex"
146+
) {
147+
const auto edge_1 = sut.add_edge(vd_1, vd_2);
148+
const auto edge_2 = sut.add_edge(vd_2, vd_3);
149+
const auto loop_3 = sut.add_edge(vd_3, vd_3);
150+
151+
CHECK(sut.are_incident(edge_1, edge_2));
152+
CHECK(sut.are_incident(edge_2, edge_1));
153+
CHECK_FALSE(sut.are_incident(edge_1, loop_3));
154+
CHECK_FALSE(sut.are_incident(loop_3, edge_1));
155+
}
156+
}
157+
158+
TEST_CASE_TEMPLATE_INSTANTIATE(
159+
graph_type_template,
160+
gl::graph<gl::graph_traits<gl::directed_t>>, // directed graph
161+
gl::graph<gl::graph_traits<gl::undirected_t>> // undirected graph
162+
);
163+
164+
TEST_SUITE_END(); // test_graph_incidence
165+
166+
} // namespace gl_testing

0 commit comments

Comments
 (0)