Skip to content

Commit 9aacfd9

Browse files
committed
aligned test_graph_incidence and test_graph_io
1 parent 706010b commit 9aacfd9

2 files changed

Lines changed: 415 additions & 429 deletions

File tree

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

0 commit comments

Comments
 (0)