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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
|
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/14 18:13:05 by charles #+# #+# */
/* Updated: 2020/12/12 12:32:41 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
#include <fstream>
#include <ctime>
#include <cstdlib>
#include "Bureaucrat.hpp"
#include "ShrubberyCreationForm.hpp"
#include "RobotomyRequestForm.hpp"
#include "PresidentialPardonForm.hpp"
#include "Intern.hpp"
int main()
{
int seed;
std::ifstream devRandom("/dev/random");
if (devRandom.is_open())
{
devRandom.read((char*)&seed, sizeof(int));
devRandom.close();
}
else
{
seed = time(NULL);
}
srand(seed);
{
std::cout << "=============== BUREAUCRAT ===============" << std::endl;
std::cout << "############### CREATION" << std::endl;
try { Bureaucrat bu("YO", 0); }
catch (std::exception& e) { std::cout << e.what() << std::endl; }
try { Bureaucrat bu("YO2", 151); }
catch (std::exception& e) { std::cout << e.what() << std::endl; }
Bureaucrat yep("YEP", 1);
Bureaucrat yep2(yep);
Bureaucrat yep3("SHOULD NOT BE PRINTED", 42);
yep3 = yep;
std::cout << yep;
std::cout << yep2;
std::cout << yep3;
std::cout << "############### DECREMENT" << std::endl;
Bureaucrat a("jean", 140);
while (true)
{
try
{
a.decrementGrade();
std::cout << a;
}
catch (std::exception& e)
{
std::cout << e.what() << std::endl;
break;
}
}
std::cout << "############### INCREMENT" << std::endl;
Bureaucrat b("didier", 10);
while (true)
{
try
{
b.incrementGrade();
std::cout << b;
}
catch (std::exception& e)
{
std::cout << e.what() << std::endl;
break;
}
}
{
std::cout << "############### SHRUBERRY SIGN FORM" << std::endl;
ShrubberyCreationForm sh("shi");
Bureaucrat c1("foo", 150); c1.signForm(sh);
Bureaucrat c2("foo", 146); c2.signForm(sh);
Bureaucrat c3("foo", 145); c3.signForm(sh);
Bureaucrat c4("foo", 1); c4.signForm(sh);
}
{
std::cout << "############### PRESIDENTIAL SIGN FORM" << std::endl;
PresidentialPardonForm pr("fu");
Bureaucrat c1("foo", 150); c1.signForm(pr);
Bureaucrat c2("foo", 26); c2.signForm(pr);
Bureaucrat c3("foo", 25); c3.signForm(pr);
Bureaucrat c4("foo", 1); c4.signForm(pr);
}
{
std::cout << "############### ROBOTOMY SIGN FORM" << std::endl;
RobotomyRequestForm ro("mi");
Bureaucrat c1("foo", 150); c1.signForm(ro);
Bureaucrat c2("foo", 73); c2.signForm(ro);
Bureaucrat c3("foo", 72); c3.signForm(ro);
Bureaucrat c4("foo", 1); c4.signForm(ro);
}
{
std::cout << "############### SHRUBERRY EXECUTE FORM" << std::endl;
ShrubberyCreationForm sh("shi");
sh.beSigned(Bureaucrat("foo", 1));
Bureaucrat c1("foo", 150); c1.executeForm(sh);
Bureaucrat c2("foo", 138); c2.executeForm(sh);
Bureaucrat c3("foo", 137); c3.executeForm(sh);
Bureaucrat c4("foo", 1); c4.executeForm(sh);
}
{
std::cout << "############### PRESIDENTIAL EXECUTE FORM" << std::endl;
PresidentialPardonForm pr("fu");
pr.beSigned(Bureaucrat("foo", 1));
Bureaucrat c1("foo", 150); c1.executeForm(pr);
Bureaucrat c2("foo", 6); c2.executeForm(pr);
Bureaucrat c3("foo", 5); c3.executeForm(pr);
Bureaucrat c4("foo", 1); c4.executeForm(pr);
}
{
std::cout << "############### ROBOTOMY EXECUTE FORM" << std::endl;
RobotomyRequestForm ro("mi");
ro.beSigned(Bureaucrat("foo", 1));
Bureaucrat c1("foo", 150); c1.executeForm(ro);
Bureaucrat c2("foo", 46); c2.executeForm(ro);
Bureaucrat c3("foo", 45); c3.executeForm(ro);
Bureaucrat c4("foo", 1); c4.executeForm(ro);
}
}
std::cout << std::endl;
{
std::cout << "================= SHRUBBERY CREATION =================" << std::endl;
ShrubberyCreationForm sh("home");
ShrubberyCreationForm sh2(sh);
ShrubberyCreationForm sh3("SHOULD NOT BE PRINTED");
sh3 = sh;
std::cout << sh;
std::cout << sh2;
std::cout << sh3;
try { sh.execute(Bureaucrat("", 1)); }
catch (std::exception& e) { std::cout << e.what() << std::endl; }
try { sh.beSigned(Bureaucrat("foo", 1)); }
catch (std::exception& e) { std::cout << e.what() << std::endl; }
try { sh.beSigned(Bureaucrat("foo", 145)); }
catch (std::exception& e) { std::cout << e.what() << std::endl; }
try { sh.beSigned(Bureaucrat("foo", 146)); }
catch (std::exception& e) { std::cout << e.what() << std::endl; }
try { sh.beSigned(Bureaucrat("foo", 150)); }
catch (std::exception& e) { std::cout << e.what() << std::endl; }
std::cout << sh;
try { sh.execute(Bureaucrat("bar", 1)); }
catch (std::exception& e) { std::cout << e.what() << std::endl; }
try { sh.execute(Bureaucrat("bar", 137)); }
catch (std::exception& e) { std::cout << e.what() << std::endl; }
try { sh.execute(Bureaucrat("bar", 138)); }
catch (std::exception& e) { std::cout << e.what() << std::endl; }
try { sh.execute(Bureaucrat("bar", 150)); }
catch (std::exception& e) { std::cout << e.what() << std::endl; }
}
std::cout << std::endl;
{
std::cout << "================= PRESIDENTIAL PARDON =================" << std::endl;
PresidentialPardonForm pr("Didier");
PresidentialPardonForm pr2(pr);
PresidentialPardonForm pr3("SHOULD NOT BE PRINTED");
pr3 = pr;
std::cout << pr;
std::cout << pr2;
std::cout << pr3;
try { pr.execute(Bureaucrat("", 1)); }
catch (std::exception& e) { std::cout << e.what() << std::endl; }
try { pr.beSigned(Bureaucrat("foo", 1)); }
catch (std::exception& e) { std::cout << e.what() << std::endl; }
try { pr.beSigned(Bureaucrat("foo", 25)); }
catch (std::exception& e) { std::cout << e.what() << std::endl; }
try { pr.beSigned(Bureaucrat("foo", 26)); }
catch (std::exception& e) { std::cout << e.what() << std::endl; }
try { pr.beSigned(Bureaucrat("foo", 150)); }
catch (std::exception& e) { std::cout << e.what() << std::endl; }
std::cout << pr;
try { pr.execute(Bureaucrat("bar", 1)); }
catch (std::exception& e) { std::cout << e.what() << std::endl; }
try { pr.execute(Bureaucrat("bar", 5)); }
catch (std::exception& e) { std::cout << e.what() << std::endl; }
try { pr.execute(Bureaucrat("bar", 6)); }
catch (std::exception& e) { std::cout << e.what() << std::endl; }
try { pr.execute(Bureaucrat("bar", 150)); }
catch (std::exception& e) { std::cout << e.what() << std::endl; }
}
std::cout << std::endl;
{
std::cout << "================= ROBOTOMY REQUEST =================" << std::endl;
RobotomyRequestForm ro("Jonathan");
RobotomyRequestForm ro2(ro);
RobotomyRequestForm ro3("SHOULD NOT BE PRINTED");
ro3 = ro;
std::cout << ro;
std::cout << ro2;
std::cout << ro3;
try { ro.execute(Bureaucrat("", 1)); }
catch (std::exception& e) { std::cout << e.what() << std::endl; }
try { ro.beSigned(Bureaucrat("foo", 1)); }
catch (std::exception& e) { std::cout << e.what() << std::endl; }
try { ro.beSigned(Bureaucrat("foo", 72)); }
catch (std::exception& e) { std::cout << e.what() << std::endl; }
try { ro.beSigned(Bureaucrat("foo", 73)); }
catch (std::exception& e) { std::cout << e.what() << std::endl; }
try { ro.beSigned(Bureaucrat("foo", 150)); }
catch (std::exception& e) { std::cout << e.what() << std::endl; }
std::cout << ro;
try { ro.execute(Bureaucrat("bar", 1)); }
catch (std::exception& e) { std::cout << e.what() << std::endl; }
try { ro.execute(Bureaucrat("bar", 45)); }
catch (std::exception& e) { std::cout << e.what() << std::endl; }
try { ro.execute(Bureaucrat("bar", 46)); }
catch (std::exception& e) { std::cout << e.what() << std::endl; }
try { ro.execute(Bureaucrat("bar", 150)); }
catch (std::exception& e) { std::cout << e.what() << std::endl; }
}
std::cout << std::endl;
{
std::cout << "================= INTERN =================" << std::endl;
Intern in;
Form *sh = in.makeForm("shrubbery creation", "yo");
Form *pr = in.makeForm("presidential pardon", "ya");
Form *ro = in.makeForm("robotomy request", "yu");
Form *nu = in.makeForm("foo", "yu");
std::cout << nu << std::endl;
std::cout << *sh;
std::cout << *pr;
std::cout << *ro;
delete sh;
delete pr;
delete ro;
}
return 0;
}
|