forked from Evgueni-Petrov-aka-espetrov/TestDriver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
testlab3-0.c
302 lines (288 loc) · 7.91 KB
/
testlab3-0.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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
#include "testLab.h"
#include <stdio.h>
#include <string.h>
static int testN = 0;
static const struct {const char *const in; int n, out[32];} testInOut[] = {
{"3\n4 -1 2\n", 3, {-1, 2, 4}},
{"3\n0 0 -1\n", 3, {-1, 0, 0}},
{"3\n-1 2 4\n", 3, {-1, 2, 4}},
{"3\n-1 4 2\n", 3, {-1, 2, 4}},
{"3\n2 -1 4\n", 3, {-1, 2, 4}},
{"3\n2 4 -1\n", 3, {-1, 2, 4}},
{"3\n4 2 -1\n", 3, {-1, 2, 4}},
{"3\n-1 -1 2\n", 3, {-1, -1, 2}},
{"3\n-1 2 -1\n", 3, {-1, -1, 2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 4}},
};
static int FeedFromArray(void)
{
FILE *const in = fopen("in.txt", "w+");
if (!in) {
printf("can't create in.txt. No space on disk?\n");
return -1;
}
fprintf(in, "%s", testInOut[testN].in);
fclose(in);
return 0;
}
static int CheckFromArray(void)
{
FILE *const out = fopen("out.txt", "r");
int i, passed = 1;
if (!out) {
printf("can't open out.txt\n");
testN++;
return -1;
}
for (i = 0; i < testInOut[testN].n; i++) {
int n;
if (ScanInt(out, &n) != Pass) {
passed = 0;
} else if (testInOut[testN].out[i] != n) {
passed = 0;
printf("wrong output -- ");
break;
}
}
if (passed) {
passed = !HaveGarbageAtTheEnd(out);
}
fclose(out);
if (passed) {
printf("PASSED\n");
testN++;
return 0;
} else {
printf("FAILED\n");
testN++;
return 1;
}
}
static int LabTimeout;
static size_t LabMemoryLimit;
static int feederBig(void)
{
FILE *const in = fopen("in.txt", "w+");
int i;
DWORD t;
if (!in) {
printf("can't create in.txt. No space on disk?\n");
return -1;
}
printf("Creating large array... ");
fflush(stdout);
t = GetTickCount();
fprintf(in, "%d\n", 2000000);
for (i = 0; i < 2000000; i++) {
if (fprintf(in, "%d ", i^0x1234567) == EOF) {
printf("can't create in.txt. No space on disk?\n");
fclose(in);
return -1;
}
}
fprintf(in, "\n");
fclose(in);
t = RoundUptoThousand(GetTickCount() - t);
printf("done in T=%u seconds. Starting exe with timeout 2*T+3... ", (unsigned)t/1000);
LabTimeout = (int)t*2+3000;
fflush(stdout);
LabMemoryLimit = MIN_PROCESS_RSS_BYTES+4*2000000;
return 0;
}
static int checkerBig(void)
{
FILE *const out = fopen("out.txt", "r");
int i, passed = 1, last = 0;
if (!out) {
printf("can't open out.txt\n");
testN++;
return -1;
}
for (i = 0; i < 2000000; i++) {
int n;
if (ScanInt(out, &n) != Pass) {
passed = 0;
break;
} else if ((n^0x1234567) < 0 || 2000000 <= (n^0x1234567)) {
passed = 0;
printf("wrong output -- ");
break;
} else if (i == 0) {
last = n;
continue;
} else if (n <= last ) {
passed = 0;
printf("wrong output -- ");
break;
}
}
if (passed) {
passed = !HaveGarbageAtTheEnd(out);
}
fclose(out);
if (passed) {
printf("PASSED\n");
testN++;
return 0;
} else {
printf("FAILED\n");
testN++;
return 1;
}
}
static int feederBig2(void)
{
FILE *const in = fopen("in.txt", "w+");
int i;
DWORD t;
if (!in) {
printf("can't create in.txt. No space on disk?\n");
return -1;
}
printf("Creating large array... ");
fflush(stdout);
t = GetTickCount();
fprintf(in, "%d\n", 2000000);
for (i = 0; i < 200000; i++) {
if (fprintf(in, "0 0 0 0 0 0 0 0 0 0 ") == EOF) {
printf("can't create in.txt. No space on disk?\n");
fclose(in);
return -1;
}
}
fprintf(in, "\n");
fclose(in);
t = RoundUptoThousand(GetTickCount() - t);
printf("done in T=%u seconds. Starting exe with timeout 2*T+3... ", (unsigned)t/1000);
LabTimeout = (int)t*2+3000;
fflush(stdout);
LabMemoryLimit = MIN_PROCESS_RSS_BYTES+4*2000000;
return 0;
}
static int checkerBig2(void)
{
FILE *const out = fopen("out.txt", "r");
int i, passed = 1;
if (!out) {
printf("can't open out.txt\n");
testN++;
return -1;
}
for (i = 0; i < 2000000; i++) {
int n;
if (ScanInt(out, &n) != Pass) {
passed = 0;
break;
} else if (n != 0) {
passed = 0;
printf("wrong output -- ");
break;
}
}
if (passed) {
passed = !HaveGarbageAtTheEnd(out);
}
fclose(out);
if (passed) {
printf("PASSED\n");
testN++;
return 0;
} else {
printf("FAILED\n");
testN++;
return 1;
}
}
const TLabTest LabTests[] = {
{FeedFromArray, CheckFromArray},
{FeedFromArray, CheckFromArray},
{FeedFromArray, CheckFromArray},
{FeedFromArray, CheckFromArray},
{FeedFromArray, CheckFromArray},
{FeedFromArray, CheckFromArray},
{FeedFromArray, CheckFromArray},
{FeedFromArray, CheckFromArray},
{FeedFromArray, CheckFromArray},
{FeedFromArray, CheckFromArray},
{FeedFromArray, CheckFromArray},
{FeedFromArray, CheckFromArray},
{FeedFromArray, CheckFromArray},
{FeedFromArray, CheckFromArray},
{FeedFromArray, CheckFromArray},
{FeedFromArray, CheckFromArray},
{FeedFromArray, CheckFromArray},
{FeedFromArray, CheckFromArray},
{FeedFromArray, CheckFromArray},
{FeedFromArray, CheckFromArray},
{FeedFromArray, CheckFromArray},
{FeedFromArray, CheckFromArray},
{FeedFromArray, CheckFromArray},
{FeedFromArray, CheckFromArray},
{FeedFromArray, CheckFromArray},
{FeedFromArray, CheckFromArray},
{FeedFromArray, CheckFromArray},
{FeedFromArray, CheckFromArray},
{FeedFromArray, CheckFromArray},
{FeedFromArray, CheckFromArray},
{FeedFromArray, CheckFromArray},
{FeedFromArray, CheckFromArray},
{FeedFromArray, CheckFromArray},
{FeedFromArray, CheckFromArray},
{FeedFromArray, CheckFromArray},
{FeedFromArray, CheckFromArray},
{FeedFromArray, CheckFromArray},
{FeedFromArray, CheckFromArray},
{FeedFromArray, CheckFromArray},
{FeedFromArray, CheckFromArray},
{feederBig, checkerBig},
{feederBig2, checkerBig2}
};
TLabTest GetLabTest(int testIdx) {
return LabTests[testIdx];
}
int GetTestCount(void) {
return sizeof(LabTests)/sizeof(LabTests[0]);
}
const char* GetTesterName(void) {
return "Lab 3-x Quick Sort or Heap Sort";
}
static int LabTimeout = 3000;
int GetTestTimeout() {
return LabTimeout;
}
static size_t LabMemoryLimit = MIN_PROCESS_RSS_BYTES;
size_t GetTestMemoryLimit() {
return LabMemoryLimit;
}