-
Notifications
You must be signed in to change notification settings - Fork 1
/
testdepcomputations.C
244 lines (193 loc) · 5.1 KB
/
testdepcomputations.C
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
/*
** Copyright 2022 Double Precision, Inc.
** See COPYING for distribution information.
*/
#include "config.h"
#include "unit_test.H"
#include "proc_container.C"
#include <iostream>
#include <algorithm>
#include <vector>
struct sort_test_dependencies {
bool operator()(const auto &tuple1, const auto &tuple2)
{
const auto &[tuple1_f, tuple1_s] = tuple1;
const auto &[tuple2_f, tuple2_s] = tuple2;
return tuple1_f->name < tuple2_f->name;
}
};
typedef current_containers_infoObj::dependency_info dependency_info;
typedef current_containers_infoObj::new_all_dependency_info_t
new_all_dependency_info_t;
void test_deps()
{
std::shared_ptr<proc_containerObj> tests[5]={
std::make_shared<proc_containerObj>("a"),
std::make_shared<proc_containerObj>("b"),
std::make_shared<proc_containerObj>("c"),
std::make_shared<proc_containerObj>("d"),
std::make_shared<proc_containerObj>("e")
};
std::vector<proc_container> containers{std::begin(tests),
std::end(tests)};
std::vector dependencies{
std::tuple{containers[0], containers[1]},
std::tuple{containers[1], containers[2]},
std::tuple{containers[2], containers[3]},
std::tuple{containers[3], containers[4]},
};
std::sort(dependencies.begin(), dependencies.end(),
sort_test_dependencies{});
do
{
std::cout << "test 1:";
new_all_dependency_info_t all_dependency_info;
for (auto &[a, b] : dependencies)
{
std::cout << " " << a->name << "->"
<< b->name;
current_containers_infoObj::define_dependency(
all_dependency_info,
&dependency_info::all_requires,
&dependency_info::all_required_by,
a, b
);
}
std::cout << "\n";
auto me=containers.begin();
for (auto &c:containers)
{
std::cout << " " << c->name << ":\n"
<< " requires: ";
std::vector<proc_container> req{
all_dependency_info[c].all_requires.begin(),
all_dependency_info[c].all_requires.end()
};
std::sort(req.begin(), req.end(),
proc_container_less_than{});
for (const auto &c:req)
{
std::cout << " " << c->name;
}
std::cout << "\n";
std::vector<proc_container>
expected{me+1, containers.end()};
if (expected.size() != req.size() ||
!std::equal(req.begin(),
req.end(),
expected.begin(),
proc_container_equal{}))
exit(1);
std::cout << " required_by: ";
std::vector<proc_container> reqby{
all_dependency_info[c].all_required_by.begin(),
all_dependency_info[c].all_required_by.end()
};
std::sort(reqby.begin(), reqby.end(),
proc_container_less_than{});
for (const auto &c:reqby)
{
std::cout << " " << c->name;
}
std::cout << "\n";
expected=std::vector<proc_container>{
containers.begin(), me
};
if (expected.size() != reqby.size() ||
!std::equal(reqby.begin(),
reqby.end(),
expected.begin(),
proc_container_equal{}))
exit(1);
++me;
}
} while (std::next_permutation(dependencies.begin(),
dependencies.end(),
sort_test_dependencies{}));
}
void test_deps2()
{
auto runlevel=std::make_shared<proc_containerObj>("0");
auto a=std::make_shared<proc_containerObj>("a");
auto b=std::make_shared<proc_containerObj>("b");
auto c=std::make_shared<proc_containerObj>("c");
runlevel->type=proc_container_type::runlevel;
std::vector dependencies{
std::tuple{c, runlevel},
std::tuple{runlevel, a},
std::tuple{a, b},
};
std::sort(dependencies.begin(), dependencies.end(),
sort_test_dependencies{});
std::vector<proc_container> containers{{runlevel, a, b, c}};
do
{
std::cout << "test 2:";
new_all_dependency_info_t all_dependency_info;
for (auto &[a, b] : dependencies)
{
std::cout << " " << a->name << "->"
<< b->name;
current_containers_infoObj::define_dependency(
all_dependency_info,
&dependency_info::all_requires,
&dependency_info::all_required_by,
a, b
);
}
std::cout << "\n";
for (auto &c:containers)
{
std::cout << " " << c->name << ":\n"
<< " requires: ";
std::vector<proc_container> req{
all_dependency_info[c].all_requires.begin(),
all_dependency_info[c].all_requires.end()
};
std::sort(req.begin(), req.end(),
proc_container_less_than{});
int cnt=0;
for (const auto &c2:req)
{
std::cout << " " << c2->name;
if (c2->name == "c" ||
c2->name <= c->name)
{
std::cout << "\n";
exit(1);
}
++cnt;
}
std::cout << "\n";
std::cout << " required_by: ";
std::vector<proc_container> reqby{
all_dependency_info[c].all_required_by.begin(),
all_dependency_info[c].all_required_by.end()
};
std::sort(reqby.begin(), reqby.end(),
proc_container_less_than{});
for (const auto &c2:reqby)
{
std::cout << " " << c2->name;
if (c2->name == "c" ||
c2-> name >= c->name)
{
std::cout << "\n";
exit(1);
}
++cnt;
}
std::cout << "\n";
if (cnt != (c->name == "c" ? 0:2))
exit(1);
}
} while (std::next_permutation(dependencies.begin(),
dependencies.end(),
sort_test_dependencies{}));
}
int main()
{
test_deps();
test_deps2();
return 0;
}