-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtest-array.cbl
More file actions
496 lines (421 loc) · 17.5 KB
/
test-array.cbl
File metadata and controls
496 lines (421 loc) · 17.5 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
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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
identification division.
program-id. test-array.
author. Studiofarma nome autore.
date-written. Data.
environment division.
configuration section.
special-names.
input-output section.
file-control.
data division.
file section.
working-storage section.
copy "definitions.cpy".
78 STR-EL-SZ value 10.
78 NUM-EL-SZ value 9.
77 w-str-element pic x(STR-EL-SZ).
77 w-num-element pic 9(NUM-EL-SZ) value 0.
77 w-num-element2 pic 9(NUM-EL-SZ) value 0.
77 w-bigger-num-element pic 9(10) value 0.
77 w-max-elements pic 9(NUM-EL-SZ) value 0.
77 j pic 9(NUM-EL-SZ) value 0.
77 i pic 9(NUM-EL-SZ) value 0.
77 i-d redefines i pic 9v99999999.
77 w-actual pic x(2048).
77 w-actual-num pic 9(NUM-EL-SZ).
77 w-expected pic x(2048).
77 w-expected-num pic 9(NUM-EL-SZ).
copy "array.cpy" replacing ==!PREFIX!== by ==w-==.
copy "array.cpy" replacing ==!PREFIX!== by ==w-expected-==.
01 w-expected-array-str-tbl value spaces.
05 w-expected-array-str-arr pic x(STR-EL-SZ) occurs 100.
01 w-expected-array-num-tbl value zeros.
05 w-expected-array-num-arr pic 9(NUM-EL-SZ) occurs 100.
01 w-expected-array-stt-tbl.
03 w-expected-array-stt-arr occurs 100.
05 w-expected-array-stt-arr-x pic x(25).
05 w-expected-array-stt-arr-9 pic 9(08).
01 w-stt.
05 w-stt-x pic x(25) value spaces.
05 w-stt-9 pic 9(08) value zeros.
78 STT-SZ value length of w-stt.
linkage section.
01 d-array-str-tbl value spaces.
05 d-array-str-arr
pic x(STR-EL-SZ)
occurs 200000000
depending on w-array-length.
01 d-array-num-tbl value spaces.
05 d-array-num-arr
pic x(NUM-EL-SZ)
occurs 200000000
depending on w-array-length.
procedure division using
d-array-str-tbl
.
call "array".
perform test-allocation
thru test-allocation-ex.
perform test-append1
thru test-append1-ex.
call "array:free" using w-array.
perform test-append-many
thru test-append-many-ex.
perform test-element-overflow
thru test-element-overflow-ex.
perform test-get-of-an-element
thru test-get-of-an-element-ex.
perform test-get-of-an-element-numeric
thru test-get-of-an-element-numeric-ex.
perform test-insert
thru test-insert-ex.
perform test-append-and-get-of-a-numeric-value
thru test-append-and-get-of-a-numeric-value-ex.
perform test-sorting-alphanumerics
thru test-sorting-alphanumerics-ex.
perform test-sorting-numbers
thru test-sorting-numbers-ex.
perform test-sorting
thru test-sorting-ex.
perform test-sorting-parts-of-data-structures
thru test-sorting-parts-of-data-structures-ex.
perform test-sorting-comparators
thru test-sorting-comparators-ex.
call "assert" using VERIFY.
cancel "array".
cancel "assert".
goback.
test-allocation.
move STR-EL-SZ to w-expected-array-element-sz.
move 0 to w-expected-array-length.
move 2 to w-expected-array-capacity.
move "x" to w-expected-array-type.
call "array:new" using w-array length of w-str-element.
call "assert"
using EQ
w-expected-array-data
w-array-data
"array should be allocated as expected".
test-allocation-ex.
exit.
test-append1.
initialize w-expected-array-str-tbl.
move "bla" to w-expected-array-str-arr(1).
move "bla2" to w-expected-array-str-arr(2).
call "array:append" using w-array "bla".
call "array:append" using w-array "bla2".
call "assert"
using ARRAY-EQ
w-expected-array-str-tbl
w-array
"after appending, array should contain a new element
- "".
move 2 to w-expected-array-length.
call "assert" using EQ w-expected-array-length w-array-length
"after appending, array length should increment".
test-append1-ex.
exit.
test-append-many.
call "array:new" using w-array length of w-str-element.
initialize w-expected-array-str-tbl.
move "xx" to w-expected-array-str-arr(1).
move "yyyy" to w-expected-array-str-arr(2).
move "zzzzzz" to w-expected-array-str-arr(3).
call "array:append" using w-array "xx".
call "array:append" using w-array "yyyy".
call "array:append" using w-array "zzzzzz".
call "assert"
using ARRAY-EQ
w-expected-array-str-tbl
w-array
"it should continue to append also when it excedees
- "the initial capacity".
move 3 to w-expected-array-length.
call "assert" using EQ w-expected-array-length w-array-length
"after appending, array length should increment".
call "array:free" using w-array.
test-append-many-ex.
exit.
test-element-overflow.
call "array:new" using w-array length of w-str-element.
initialize w-expected-array-str-tbl.
move "0123456789" to w-expected-array-str-tbl.
call "array:append" using w-array "01234567891".
call "assert"
using ARRAY-EQ
w-expected-array-str-tbl
w-array
"when you append an element that exceeds the element
- "size, it should be truncated".
call "array:free" using w-array.
test-element-overflow-ex.
exit.
test-get-of-an-element.
call "array:new" using w-array length of w-str-element.
move "test" to w-expected.
initialize w-actual.
call "array:append" using w-array w-expected.
call "array:get" using w-array w-actual 0.
call "assert"
using EQ
w-expected
w-actual
"it should be possible to read an element with 0 bas
- "ed indexing system".
move "test2" to w-expected.
initialize w-actual.
call "array:append" using w-array w-expected.
call "array:get" using w-array w-actual 1.
call "assert"
using EQ
w-expected
w-actual
"it should be possible to read elements with 0 based
- "indexing system".
move "test3" to w-expected.
initialize w-actual.
call "array:append" using w-array w-expected.
call "array:get" using w-array w-actual 2.
call "assert"
using EQ
w-expected
w-actual
"it should be possible to read elements with 0 based
- "indexing system".
set address of d-array-str-tbl to w-array-ptr.
call "assert"
using EQ
w-expected
d-array-str-arr(3)
"it should be possible to read elements dereferencin
- "g the array with a linkage table".
call "array:free" using w-array.
test-get-of-an-element-ex.
exit.
test-get-of-an-element-numeric.
call "array:new"
using w-array length of w-num-element TNUMERIC.
move 12 to w-expected-num.
initialize w-actual.
call "array:append" using w-array 12.
call "array:get" using w-array w-actual-num 0.
call "assert"
using EQ
w-expected-num
w-actual-num
"it should be possible to read a numeric element".
move 15 to w-bigger-num-element.
call "array:append" using w-array w-bigger-num-element.
call "array:get" using w-array w-actual-num 1.
move w-bigger-num-element to w-expected-num.
call "assert"
using EQ
w-expected-num
w-actual-num
"it should be possible to read a numeric element app
- "ended from a bigger picture".
test-get-of-an-element-numeric-ex.
exit.
test-insert.
call "array:new" using w-array length of w-str-element.
initialize w-expected-array-str-tbl.
move "bla" to w-expected-array-str-arr(1).
move "bla3" to w-expected-array-str-arr(2).
move "bla2" to w-expected-array-str-arr(3).
call "array:append" using w-array "bla".
call "array:append" using w-array "bla2".
call "array:insert" using w-array "bla3" 1.
call "assert"
using ARRAY-EQ
w-expected-array-str-tbl
w-array
"after insert, array should contain a new element in
- " the right position".
move 3 to w-expected-array-length.
call "assert" using EQ w-expected-array-length w-array-length
"after inserting, array length should increment".
call "array:insert" using w-array "bla4" 3.
call "assert"
using ARRAY-EQ
w-expected-array-str-tbl
w-array
"after inserting in a position that is greater than
- "current maximum index, it should stay invariate"
move 3 to w-expected-array-length.
call "assert" using EQ w-expected-array-length w-array-length
"after inserting in a position that is greater than curren
- "t maximum index, it should stay invariate also in length"
.
call "array:free" using w-array.
test-insert-ex.
exit.
test-append-and-get-of-a-numeric-value.
call "array:new" using w-array length of w-num-element.
move 42 to w-num-element
call "array:append" using w-array w-num-element.
move 43 to w-expected-num
call "array:append" using w-array w-expected-num.
move 44 to w-num-element
call "array:append" using w-array w-num-element.
call "array:get" using w-array w-actual-num 1
call "assert"
using EQ
w-expected-num
w-actual-num
"array works also with numbers".
call "array:free" using w-array.
test-append-and-get-of-a-numeric-value-ex.
exit.
test-sorting.
call "array:new" using w-array length of i.
move 10000 to w-max-elements.
perform fill-the-array-with-random-numbers
thru fill-the-array-with-random-numbers-ex.
call "array:sort" using w-array
initialize i.
perform check-that-array-is-sorted
thru check-that-array-is-sorted-ex
call "assert"
using EQ
w-max-elements
i
"big array is sorted".
call "array:free" using w-array.
test-sorting-ex.
exit.
test-sorting-alphanumerics.
call "array:new" using w-array length of w-str-element.
move "aaaaaaaaaa" to w-expected-array-str-arr(1).
move "bbbbbbbbbb" to w-expected-array-str-arr(2).
move "cccccccccc" to w-expected-array-str-arr(3).
move "dddddddddd" to w-expected-array-str-arr(4).
move "eeeeeeeeee" to w-expected-array-str-arr(5).
call "array:append" using w-array "bbbbbbbbbb".
call "array:append" using w-array "aaaaaaaaaa".
call "array:append" using w-array "eeeeeeeeee".
call "array:append" using w-array "dddddddddd".
call "array:append" using w-array "cccccccccc".
call "array:sort" using w-array.
call "assert"
using ARRAY-EQ
w-expected-array-str-tbl
w-array
"array of strings is sorted".
call "array:free" using w-array.
test-sorting-alphanumerics-ex.
exit.
test-sorting-numbers.
call "array:new"
using w-array length of w-num-element TNUMERIC.
move 1 to w-expected-array-num-arr(1).
move 1 to w-expected-array-num-arr(2).
move 2 to w-expected-array-num-arr(3).
move 3 to w-expected-array-num-arr(4).
move 4 to w-expected-array-num-arr(5).
move 5 to w-expected-array-num-arr(6).
move 11 to w-expected-array-num-arr(7).
call "array:append" using w-array 3.
call "array:append" using w-array 2.
call "array:append" using w-array 1.
call "array:append" using w-array 4.
call "array:append" using w-array 1.
call "array:append" using w-array 11.
call "array:append" using w-array 5.
call "array:sort" using w-array.
call "assert"
using ARRAY-EQ
w-expected-array-num-tbl
w-array
"array of numbers is sorted".
call "array:free" using w-array.
test-sorting-numbers-ex.
exit.
test-sorting-parts-of-data-structures.
call "array:new" using w-array length of w-stt.
move 1 to w-expected-array-stt-arr-9(1).
move "z" to w-expected-array-stt-arr-x(1).
move 2 to w-expected-array-stt-arr-9(2).
move "v" to w-expected-array-stt-arr-x(2).
move 3 to w-expected-array-stt-arr-9(3).
move "u" to w-expected-array-stt-arr-x(3).
move 4 to w-expected-array-stt-arr-9(4).
move "t" to w-expected-array-stt-arr-x(4).
move 5 to w-expected-array-stt-arr-9(5).
move "s" to w-expected-array-stt-arr-x(5).
move 11 to w-expected-array-stt-arr-9(6).
move "r" to w-expected-array-stt-arr-x(6).
call "array:append"
using w-array w-expected-array-stt-arr(5).
call "array:append"
using w-array w-expected-array-stt-arr(3).
call "array:append"
using w-array w-expected-array-stt-arr(2).
call "array:append"
using w-array w-expected-array-stt-arr(4).
call "array:append"
using w-array w-expected-array-stt-arr(6).
call "array:append"
using w-array w-expected-array-stt-arr(1).
call "array:sort"
using w-array
record-position of w-stt-9
length of w-stt-9
.
call "assert"
using ARRAY-EQ
w-expected-array-stt-tbl
w-array
"array of data structure is sorted with rules on par
- "t of the structure".
call "array:free" using w-array.
test-sorting-parts-of-data-structures-ex.
exit.
test-sorting-comparators.
call "array:new" using w-array length of w-str-element.
move "first" to w-expected-array-str-arr(1).
move "second" to w-expected-array-str-arr(2).
move "third" to w-expected-array-str-arr(3).
move "apple" to w-expected-array-str-arr(4).
move "banana" to w-expected-array-str-arr(5).
call "array:append"
using w-array w-expected-array-str-arr(2).
call "array:append"
using w-array w-expected-array-str-arr(5).
call "array:append"
using w-array w-expected-array-str-arr(3).
call "array:append"
using w-array w-expected-array-str-arr(1).
call "array:append"
using w-array w-expected-array-str-arr(4).
call "array:sort"
using w-array
0
length of w-str-element
"testcomparator"
.
call "assert"
using ARRAY-EQ
w-expected-array-str-tbl
w-array
"array is sorted with test comparator".
call "array:free" using w-array.
test-sorting-comparators-ex.
exit.
fill-the-array-with-random-numbers.
perform w-max-elements times
move function random() to i-d
call "array:append" using w-array i
end-perform.
fill-the-array-with-random-numbers-ex.
exit.
check-that-array-is-sorted.
perform varying i from 1 by 1 until i >= w-max-elements
subtract 1 from i giving j
call "array:get" using w-array w-num-element j
call "array:get" using w-array w-num-element2 i
if w-num-element > w-num-element2
exit perform
end-if
end-perform.
check-that-array-is-sorted-ex.
exit.