fixed bug in disasm engine
[k8lst.git] / samples / testBag.st
blobf715ebee87a9e4655480318417d1b1a3ab92790b
1 Requires [ collections ]
5   | bag dumpBag dumpBagX |
7   dumpBag := [:s |
8     'bag:(' print. s size print. ')' print.
9     s do: [:e | ' ' print. e print. ].
10     ';' printNl.
11   ].
13   dumpBagX := [:s |
14     'bag:(' print. s size print. ')' print.
15     s itemsDo: [:e | ' ' print. e print. ].
16     ';' printNl.
17   ].
19   bag := Bag new.
20   dumpBag value: bag.
22   bag << 10.
23   bag << 13.
24   bag << 42.
25   bag << 56.
26   dumpBag value: bag.
28   bag << 42.
29   bag << 56.
30   dumpBag value: bag.
32   bag remove: 13.
33   dumpBag value: bag.
35   bag remove: 128 ifAbsent: [ 'no element!' printNl ].
36   dumpBag value: bag.
38   "and now for something big"
39   1 to: 32 do: [:i | bag << i ].
40   dumpBag value: bag.
42   2 to: 32 by: 2 do: [:i | bag remove: i ].
43   dumpBag value: bag.
45   (bag includes: 5) ifFalse: [ 'FAIL!' printNl ].
46   (bag includes: 6) ifTrue: [ 'FAIL!' printNl ].
48   dumpBagX value: bag.
50   bag clear.
51   dumpBag value: bag.