File: stack.testsuite

package info (click to toggle)
tcllib 1.20%2Bdfsg-1
  • links: PTS
  • area: main
  • in suites: bullseye
  • size: 68,064 kB
  • sloc: tcl: 216,842; ansic: 14,250; sh: 2,846; xml: 1,766; yacc: 1,145; pascal: 881; makefile: 107; perl: 84; f90: 84; python: 33; ruby: 13; php: 11
file content (641 lines) | stat: -rw-r--r-- 16,129 bytes parent folder | download | duplicates (6)
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
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
# -*- tcl -*-
# stack.test:  tests for the stack package.
#
# This file contains a collection of tests for one or more of the Tcl
# built-in commands.  Sourcing this file into Tcl runs the tests and
# generates output for errors.  No output means no errors were found.
#
# Copyright (c) 1998-2000 by Ajuba Solutions.
# All rights reserved.
#
# RCS: @(#) $Id: stack.testsuite,v 1.5 2010/03/24 06:13:00 andreas_kupries Exp $

# -------------------------------------------------------------------------

::tcltest::testConstraint stack_critcl [string equal $impl critcl]
::tcltest::testConstraint stack_oo     [expr {![catch {package present TclOO}] && [string equal $impl tcl]}]

#----------------------------------------------------------------------

test stack-${impl}-0.1.0 {stack errors} !stack_oo {
    stack mystack
    catch {stack mystack} msg
    mystack destroy
    set msg
} {command "::mystack" already exists, unable to create stack}

test stack-${impl}-0.1.1 {stack errors} stack_oo {
    stack mystack
    catch {stack mystack} msg
    mystack destroy
    set msg
} {can't create object "mystack": command already exists with that name}

test stack-${impl}-0.2 {stack errors} badTest {
    stack mystack
    catch {mystack} msg
    mystack destroy
    set msg
} {wrong # args: should be "::mystack option ?arg arg ...?"}

test stack-${impl}-0.3.0 {stack errors} tcl8.4minus {
    stack mystack
    catch {mystack foo} msg
    mystack destroy
    set msg
} {bad option "foo": must be clear, destroy, get, getr, peek, peekr, pop, push, rotate, size, trim, or trim*}

test stack-${impl}-0.3.1.0 {stack errors} {tcl8.5plus !stack_oo} {
    stack mystack
    catch {mystack foo} msg
    mystack destroy
    set msg
} [tmTake \
       {unknown or ambiguous subcommand "foo": must be clear, destroy, get, getr, peek, peekr, pop, push, rotate, size, trim, or trim*} \
       {bad option "foo": must be clear, destroy, get, getr, peek, peekr, pop, push, rotate, size, trim, or trim*} \
      ]

test stack-${impl}-0.3.1.1 {stack errors} {tcl8.5plus stack_oo} {
    stack mystack
    catch {mystack foo} msg
    mystack destroy
    set msg
} [tmTake \
       {unknown method "foo": must be clear, destroy, get, getr, peek, peekr, pop, push, rotate, size, trim or trim*} \
       {bad option "foo": must be clear, destroy, get, getr, peek, peekr, pop, push, rotate, size, trim, or trim*} \
      ]

test stack-${impl}-0.4.0 {stack errors} !stack_oo {
    catch {stack set} msg
    set msg
} {command "::set" already exists, unable to create stack}

test stack-${impl}-0.4.1 {stack errors} stack_oo {
    catch {stack set} msg
    set msg
} {can't create object "set": command already exists with that name}

#----------------------------------------------------------------------

test stack-${impl}-1.1 {stack creation} {
    set foo [stack mystack]
    set cmd [info commands ::mystack]
    set size [mystack size]
    mystack destroy
    list $foo $cmd $size
} {::mystack ::mystack 0}

test stack-${impl}-1.2.0 {stack creation} !stack_oo {
    set foo [stack]
    set cmd [info commands ::$foo]
    set size [$foo size]
    $foo destroy
    list $foo $cmd $size
} {::stack1 ::stack1 0}

test stack-${impl}-1.2.1 {stack creation} stack_oo {
    set foo [stack]
    set cmd [info commands ::$foo]
    set size [$foo size]
    $foo destroy
    string match [list ::oo::Obj* ::oo::Obj* 0] [list $foo $cmd $size]
} 1

#----------------------------------------------------------------------

test stack-${impl}-2.1 {stack destroy} {
    stack mystack
    mystack destroy
    info commands ::mystack
} {}

#----------------------------------------------------------------------

test stack-${impl}-3.2 {size operation} {
    stack mystack
    mystack push a b c d e f g
    set size [mystack size]
    mystack destroy
    set size
} 7

test stack-${impl}-3.3 {size operation} {
    stack mystack
    mystack push a b c d e f g
    mystack pop 3
    set size [mystack size]
    mystack destroy
    set size
} 4

test stack-${impl}-3.4 {size operation} {
    stack mystack
    mystack push a b c d e f g
    mystack pop 3
    mystack peek 3
    set size [mystack size]
    mystack destroy
    set size
} 4

#----------------------------------------------------------------------
    
test stack-${impl}-4.1 {push operation} {
    stack mystack
    catch {mystack push} msg
    mystack destroy
    set msg
} "wrong # args: should be \"$MY push item ?item ...?\""

test stack-${impl}-4.2 {push operation, singleton items} {
    stack mystack
    mystack push a
    mystack push b
    mystack push c
    set result [list [mystack pop] [mystack pop] [mystack pop]]
    mystack destroy
    set result
} {c b a}

test stack-${impl}-4.3 {push operation, multiple items} {
    stack mystack
    mystack push a b c
    set result [list [mystack pop] [mystack pop] [mystack pop]]
    mystack destroy
    set result
} {c b a}

test stack-${impl}-4.4 {push operation, spaces in items} {
    stack mystack
    mystack push a b "foo bar"
    set result [list [mystack pop] [mystack pop] [mystack pop]]
    mystack destroy
    set result
} {{foo bar} b a}

test stack-${impl}-4.5 {push operation, bad chars in items} {
    stack mystack
    mystack push a b \{
    set result [list [mystack pop] [mystack pop] [mystack pop]]
    mystack destroy
    set result
} [list \{ b a]

#----------------------------------------------------------------------

test stack-${impl}-5.1 {pop operation} {
    stack mystack
    mystack push a
    mystack push b
    mystack push c
    set result [list [mystack pop] [mystack pop] [mystack pop]]
    mystack destroy
    set result
} {c b a}

test stack-${impl}-5.2 {pop operation, multiple items} {
    stack mystack
    mystack push a
    mystack push b
    mystack push c
    set result [mystack pop 3]
    mystack destroy
    set result
} {c b a}

#----------------------------------------------------------------------

test stack-${impl}-6.1 {peek operation} {
    stack mystack
    mystack push a
    mystack push b
    mystack push c
    set result [list [mystack peek] [mystack peek] [mystack peek]]
    mystack destroy
    set result
} {c c c}

test stack-${impl}-6.2 {peek operation} {
    stack mystack
    catch {mystack peek 0} msg
    mystack destroy
    set msg
} {invalid item count 0}

test stack-${impl}-6.3 {peek operation} {
    stack mystack
    catch {mystack peek -1} msg
    mystack destroy
    set msg
} {invalid item count -1}

test stack-${impl}-6.4 {peek operation} {
    stack mystack
    catch {mystack peek} msg
    mystack destroy
    set msg
} {insufficient items on stack to fill request}

test stack-${impl}-6.5 {peek operation} {
    stack mystack
    mystack push a
    catch {mystack peek 2} msg
    mystack destroy
    set msg
} {insufficient items on stack to fill request}

test stack-${impl}-6.11 {peek operation} {
    stack mystack
    mystack push a
    mystack push b
    mystack push c
    mystack push d
    set result [mystack peek 3]
    mystack destroy
    set result
} {d c b}

#----------------------------------------------------------------------

test stack-${impl}-6.6 {pop operation, multiple items} {
    stack mystack
    mystack push a
    mystack push b
    mystack push c
    set result [list [mystack peek 3] [mystack pop 3]]
    mystack destroy
    set result
} {{c b a} {c b a}}

test stack-${impl}-6.7 {pop operation} {
    stack mystack
    catch {mystack pop 0} msg
    mystack destroy
    set msg
} {invalid item count 0}

test stack-${impl}-6.8 {pop operation} {
    stack mystack
    catch {mystack pop -1} msg
    mystack destroy
    set msg
} {invalid item count -1}

test stack-${impl}-6.9 {pop operation} {
    stack mystack
    catch {mystack pop} msg
    mystack destroy
    set msg
} {insufficient items on stack to fill request}

test stack-${impl}-6.10 {pop operation} {
    stack mystack
    mystack push a
    catch {mystack pop 2} msg
    mystack destroy
    set msg
} {insufficient items on stack to fill request}

#----------------------------------------------------------------------

test stack-${impl}-7.1 {clear operation} {
    stack mystack
    mystack push a
    mystack push b
    mystack push c
    set result [list [mystack peek 3]]
    mystack clear
    lappend result [mystack size]
    mystack destroy
    set result
} {{c b a} 0}

#----------------------------------------------------------------------

test stack-${impl}-8.1 {rotate operation} {
    stack mystack
    mystack push a b c d e f g h
    mystack rotate 3 1
    set result [mystack get]
    mystack destroy
    set result
} {g f h e d c b a}

test stack-${impl}-8.2 {rotate operation} {
    stack mystack
    mystack push a b c d e f g h
    mystack rotate 3 2
    set result [mystack get]
    mystack destroy
    set result
} {f h g e d c b a}

test stack-${impl}-8.3 {rotate operation} {
    stack mystack
    mystack push a b c d e f g h
    mystack rotate 3 5
    set result [mystack get]
    mystack destroy
    set result
} {f h g e d c b a}

test stack-${impl}-8.4 {rotate operation} {
    stack mystack
    mystack push a b c d e f g h
    mystack rotate 8 1
    set result [mystack get]
    mystack destroy
    set result
} {g f e d c b a h}

test stack-${impl}-8.5 {rotate operation} {
    stack mystack
    mystack push a b c d e f g h
    mystack rotate 8 -1
    set result [mystack get]
    mystack destroy
    set result
} {a h g f e d c b}

test stack-${impl}-8.6 {rotate operation} {
    stack mystack
    catch {mystack rotate 8 -1} msg
    mystack destroy
    set msg
} {insufficient items on stack to fill request}

test stack-${impl}-8.7 {rotate operation} {
    stack mystack
    mystack push a b c d
    catch {mystack rotate 8 -1} msg
    mystack destroy
    set msg
} {insufficient items on stack to fill request}

#----------------------------------------------------------------------

test stack-${impl}-9.0 {get operation, wrong args, too many} {
    stack mystack
    catch {mystack get X} msg
    mystack destroy
    set msg
} [tmTooMany get {}]

test stack-${impl}-9.1 {get operation, empty stack} {
    stack mystack
    set result [mystack get]
    mystack destroy
    set result
} {}

test stack-${impl}-9.2 {get operation} {
    stack mystack
    mystack push a b c d
    set result [mystack get]
    mystack destroy
    set result
} {d c b a}

test stack-${impl}-9.3 {get operation} {
    stack mystack
    mystack push a
    mystack push b
    mystack push c
    mystack push d
    set result [mystack get]
    mystack destroy
    set result
} {d c b a}

#----------------------------------------------------------------------

test stack-${impl}-10.0 {trim operation, wrong args, not enough} {
    stack mystack
    catch {mystack trim} msg
    mystack destroy
    set msg
} [tmWrong trim {newsize} 0]

test stack-${impl}-10.1 {trim operation, wrong args, too many} {
    stack mystack
    catch {mystack trim X Y} msg
    mystack destroy
    set msg
} [tmTooMany trim {newsize}]

test stack-${impl}-10.2 {trim operation, bad argument} {
    stack mystack
    catch {mystack trim X} msg
    mystack destroy
    set msg
} {expected integer but got "X"}

test stack-${impl}-10.3 {trim operation, bad argument} {
    stack mystack
    catch {mystack trim -4} msg
    mystack destroy
    set msg
} {invalid size -4}

test stack-${impl}-10.4 {trim operation, empty stack} {
    stack mystack
    set     result [mystack size]
    lappend result [mystack trim 1]
    lappend result [mystack size]
    mystack destroy
    set result
} {0 {} 0}

test stack-${impl}-10.5 {trim operation} {
    stack mystack
    mystack push a b c d
    set     result [mystack size]
    lappend result [mystack trim 1]
    lappend result [mystack size]
    mystack destroy
    set result
} {4 {d c b} 1}

test stack-${impl}-10.6 {trim operation} {
    stack mystack
    mystack push a
    mystack push b
    mystack push c
    mystack push d
    set     result [mystack size]
    lappend result [mystack trim 1]
    lappend result [mystack size]
    mystack destroy
    set result
} {4 {d c b} 1}

test stack-${impl}-10.7 {trim operation} {
    stack mystack
    mystack push a b c d
    set     result [mystack size]
    lappend result [mystack trim 5]
    lappend result [mystack size]
    mystack destroy
    set result
} {4 {} 4}

#----------------------------------------------------------------------

test stack-${impl}-11.0 {getr operation, wrong args, too many} {
    stack mystack
    catch {mystack getr X} msg
    mystack destroy
    set msg
} [tmTooMany getr {}]

test stack-${impl}-11.1 {getr operation, empty stack} {
    stack mystack
    set result [mystack getr]
    mystack destroy
    set result
} {}

test stack-${impl}-11.2 {getr operation} {
    stack mystack
    mystack push a b c d
    set result [mystack getr]
    mystack destroy
    set result
} {a b c d}

test stack-${impl}-11.3 {getr operation} {
    stack mystack
    mystack push a
    mystack push b
    mystack push c
    mystack push d
    set result [mystack getr]
    mystack destroy
    set result
} {a b c d}

#----------------------------------------------------------------------

test stack-${impl}-12.0 {trim* operation, wrong args, not enough} {
    stack mystack
    catch {mystack trim*} msg
    mystack destroy
    set msg
} [tmWrong trim* {newsize} 0]

test stack-${impl}-12.1 {trim* operation, wrong args, too many} {
    stack mystack
    catch {mystack trim* X Y} msg
    mystack destroy
    set msg
} [tmTooMany trim* {newsize}]

test stack-${impl}-12.2 {trim* operation, bad argument} {
    stack mystack
    catch {mystack trim* X} msg
    mystack destroy
    set msg
} {expected integer but got "X"}

test stack-${impl}-12.3 {trim* operation, bad argument} {
    stack mystack
    catch {mystack trim* -4} msg
    mystack destroy
    set msg
} {invalid size -4}

test stack-${impl}-12.4 {trim* operation, empty stack} {
    stack mystack
    set     result [mystack size]
    lappend result [mystack trim* 1]
    lappend result [mystack size]
    mystack destroy
    set result
} {0 {} 0}

test stack-${impl}-12.5 {trim* operation} {
    stack mystack
    mystack push a b c d
    set     result [mystack size]
    lappend result [mystack trim* 1]
    lappend result [mystack size]
    mystack destroy
    set result
} {4 {} 1}

test stack-${impl}-12.6 {trim* operation} {
    stack mystack
    mystack push a
    mystack push b
    mystack push c
    mystack push d
    set     result [mystack size]
    lappend result [mystack trim* 1]
    lappend result [mystack size]
    mystack destroy
    set result
} {4 {} 1}

test stack-${impl}-12.7 {trim* operation} {
    stack mystack
    mystack push a b c d
    set     result [mystack size]
    lappend result [mystack trim* 5]
    lappend result [mystack size]
    mystack destroy
    set result
} {4 {} 4}

#----------------------------------------------------------------------

test stack-${impl}-13.1 {peekr operation} {
    stack mystack
    mystack push a
    mystack push b
    mystack push c
    set result [list [mystack peekr] [mystack peekr] [mystack peekr]]
    mystack destroy
    set result
} {c c c}

test stack-${impl}-13.2 {peekr operation} {
    stack mystack
    catch {mystack peekr 0} msg
    mystack destroy
    set msg
} {invalid item count 0}

test stack-${impl}-13.3 {peekr operation} {
    stack mystack
    catch {mystack peekr -1} msg
    mystack destroy
    set msg
} {invalid item count -1}

test stack-${impl}-13.4 {peekr operation} {
    stack mystack
    catch {mystack peekr} msg
    mystack destroy
    set msg
} {insufficient items on stack to fill request}

test stack-${impl}-13.5 {peekr operation} {
    stack mystack
    mystack push a
    catch {mystack peekr 2} msg
    mystack destroy
    set msg
} {insufficient items on stack to fill request}

test stack-${impl}-13.6 {peekr operation} {
    stack mystack
    mystack push a
    mystack push b
    mystack push c
    mystack push d
    set result [mystack peekr 3]
    mystack destroy
    set result
} {b c d}

#----------------------------------------------------------------------