-
Notifications
You must be signed in to change notification settings - Fork 118
Expand file tree
/
Copy patheulerian_paths_tests.cpp
More file actions
149 lines (139 loc) · 3.59 KB
/
Copy patheulerian_paths_tests.cpp
File metadata and controls
149 lines (139 loc) · 3.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#define BOOST_TEST_MODULE eulerian paths tests
#include <boost/test/included/unit_test.hpp>
#include "eulerian_paths.hpp"
using std::vector;
using namespace eulerian_paths;
BOOST_AUTO_TEST_SUITE(eulerian_paths_tests);
struct PointLessThan {
bool operator()(const point_type& a, const point_type& b) const {
return std::tie(a.x(), a.y()) < std::tie(b.x(), b.y());
}
};
BOOST_AUTO_TEST_CASE(do_nothing_points) {
linestring_type ls;
ls.push_back(point_type(1,1));
ls.push_back(point_type(2,2));
ls.push_back(point_type(3,4));
multi_linestring_type mls;
mls.push_back(ls);
multi_linestring_type result =
get_eulerian_paths<point_type, linestring_type, multi_linestring_type, PointLessThan>(mls);
BOOST_CHECK_EQUAL(result.size(), 1UL);
}
// 3x3 grid connected like a window pane:
// 1---2---3
// | | |
// 4---5---6
// | | |
// 7---8---9
BOOST_AUTO_TEST_CASE(window_pane) {
vector<vector<int>> euler_paths = get_eulerian_paths<int, vector<int>, vector<vector<int>>>({
{1,2},
{2,3},
{4,5},
{5,6},
{7,8},
{8,9},
{1,4},
{4,7},
{2,5},
{5,8},
{3,6},
{6,9},
});
int edges_visited = 0;
for (size_t i = 0; i < euler_paths.size(); i++) {
edges_visited += euler_paths[i].size()-1;
for (size_t j = 0; j < euler_paths[i].size(); j++) {
printf("%d ", euler_paths[i][j]);
}
printf("\n");
}
BOOST_CHECK_EQUAL(edges_visited, 12);
BOOST_CHECK_EQUAL(euler_paths.size(), 2UL);
}
// 3x3 grid connected like a window pane, but corners are longer paths:
// 1---2---3
// | | |
// 4---5---6
// | | |
// 7---8---9
BOOST_AUTO_TEST_CASE(window_pane_with_longer_corners) {
vector<vector<int>> euler_paths = get_eulerian_paths<int, vector<int>, vector<vector<int>>>({
{4,5},
{5,6},
{4,7,8},
{2,5},
{5,8},
{6,9,8},
{4,1,2},
{2,3,6},
});
int edges_visited = 0;
for (size_t i = 0; i < euler_paths.size(); i++) {
edges_visited += euler_paths[i].size()-1;
for (size_t j = 0; j < euler_paths[i].size(); j++) {
printf("%d ", euler_paths[i][j]);
}
printf("\n");
}
BOOST_CHECK_EQUAL(edges_visited, 12);
BOOST_CHECK_EQUAL(euler_paths.size(), 2UL);
}
// Bridge
// 5---2---1---6
// | | | |
// 3---4 7---8
BOOST_AUTO_TEST_CASE(bridge) {
vector<vector<int>> euler_paths = get_eulerian_paths<int, vector<int>, vector<vector<int>>>({
{5,2},
{2,1},
{1,6},
{3,4},
{7,8},
{5,3},
{2,4},
{1,7},
{6,8},
});
int edges_visited = 0;
for (size_t i = 0; i < euler_paths.size(); i++) {
edges_visited += euler_paths[i].size()-1;
for (size_t j = 0; j < euler_paths[i].size(); j++) {
printf("%d ", euler_paths[i][j]);
}
printf("\n");
}
BOOST_CHECK_EQUAL(edges_visited, 9);
BOOST_CHECK_EQUAL(euler_paths.size(), 1UL);
}
// Disjoint Loops and two degenerate paths
// 5---2 1---6 0---9
// | | | |
// 3---4 7---8
BOOST_AUTO_TEST_CASE(disjoint_loops) {
vector<vector<int>> euler_paths = get_eulerian_paths<int, vector<int>, vector<vector<int>>>({
{5,2},
{1,6},
{3,4},
{7,8},
{5,3},
{2,4},
{1,7},
{6,8},
{0,9},
{},
{12}
});
int edges_visited = 0;
for (size_t i = 0; i < euler_paths.size(); i++) {
edges_visited += euler_paths[i].size()-1;
for (size_t j = 0; j < euler_paths[i].size(); j++) {
printf("%d ", euler_paths[i][j]);
}
printf("\n");
}
BOOST_CHECK_EQUAL(edges_visited, 9);
BOOST_CHECK_EQUAL(euler_paths.size(), 3UL);
}
BOOST_AUTO_TEST_SUITE_END()