Skip to content

Commit 71f1532

Browse files
author
Tadeusz Sośnierz
committed
Tune and fudge bag, keybag, keyset and set tests for Rakudo and for Greater Good
1 parent fbfc883 commit 71f1532

File tree

4 files changed

+36
-11
lines changed

4 files changed

+36
-11
lines changed

S02-types/bag.t

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ sub showkv($x) {
4343
is +$b, 8, '+$bag gives sum of values';
4444
}
4545

46+
#?rakudo skip ':exists and :delete NYI'
4647
{
4748
my $s = bag <a a b foo>;
4849
is $s<a>:exists, True, ':exists with existing element';
@@ -54,6 +55,7 @@ sub showkv($x) {
5455
my $b = bag 'a', False, 2, 'a', False, False;
5556
my @ks = $b.keys;
5657
#?niecza 2 todo
58+
#?rakudo 2 todo ''
5759
is @ks.grep(Int)[0], 2, 'Int keys are left as Ints';
5860
is @ks.grep(* eqv False).elems, 1, 'Bool keys are left as Bools';
5961
is @ks.grep(Str)[0], 'a', 'And Str keys are permitted in the same set';
@@ -204,7 +206,7 @@ sub showkv($x) {
204206
is +@a, 2, '.roll(2) returns the right number of items';
205207
is @a.grep(* eq 'a').elems + @a.grep(* eq 'b').elems, 2, '.roll(2) returned "a"s and "b"s';
206208

207-
my @a = $b.roll: 100;
209+
@a = $b.roll: 100;
208210
is +@a, 100, '.roll(100) returns 100 items';
209211
ok 2 < @a.grep(* eq 'a') < 75, '.roll(100) (1)';
210212
ok @a.grep(* eq 'a') + 2 < @a.grep(* eq 'b'), '.roll(100) (2)';

S02-types/keybag.t

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ sub showkv($x) {
6565
nok $b.exists("farve"), "... and everything is still okay";
6666
}
6767

68+
#?rakudo skip ':exists and :delete NYI'
6869
{
6970
my $s = KeyBag.new(<a a b foo>);
7071
is $s<a>:exists, True, ':exists with existing element';
@@ -77,6 +78,7 @@ sub showkv($x) {
7778
my $b = KeyBag.new('a', False, 2, 'a', False, False);
7879
my @ks = $b.keys;
7980
#?niecza 2 todo
81+
#?rakudo 2 todo ''
8082
is @ks.grep(Int)[0], 2, 'Int keys are left as Ints';
8183
is @ks.grep(* eqv False).elems, 1, 'Bool keys are left as Bools';
8284
is @ks.grep(Str)[0], 'a', 'And Str keys are permitted in the same set';
@@ -221,7 +223,7 @@ sub showkv($x) {
221223
is +@a, 2, '.roll(2) returns the right number of items';
222224
is @a.grep(* eq 'a').elems + @a.grep(* eq 'b').elems, 2, '.roll(2) returned "a"s and "b"s';
223225

224-
my @a = $b.roll: 100;
226+
@a = $b.roll: 100;
225227
is +@a, 100, '.roll(100) returns 100 items';
226228
ok 2 < @a.grep(* eq 'a') < 75, '.roll(100) (1)';
227229
ok @a.grep(* eq 'a') + 2 < @a.grep(* eq 'b'), '.roll(100) (2)';
@@ -273,10 +275,14 @@ sub showkv($x) {
273275
#?niecza skip "Trait name not available on variables"
274276
{
275277
my %h is KeyBag = a => 1, b => 0, c => 2;
278+
#?rakudo todo 'todo'
276279
nok %h.exists( 'b' ), '"b", initialized to zero, does not exist';
280+
#?rakudo todo 'todo'
277281
is +%h.keys, 2, 'Inititalization worked';
278282
is %h.elems, 3, '.elems works';
283+
#?rakudo todo 'todo'
279284
isa_ok %h<nonexisting>, Int, '%h<nonexisting> is an Int';
285+
#?rakudo todo 'todo'
280286
is %h<nonexisting>, 0, '%h<nonexisting> is 0';
281287
}
282288

@@ -285,11 +291,15 @@ sub showkv($x) {
285291
my %h is KeyBag = a => 1, b => 0, c => 2;
286292

287293
lives_ok { %h<c> = 0 }, 'can set an item to 0';
294+
#?rakudo todo 'todo'
288295
nok %h.exists( 'c' ), '"c", set to zero, does not exist';
296+
#?rakudo todo 'todo'
289297
is %h.elems, 1, 'one item left';
298+
#?rakudo todo 'todo'
290299
is %h.keys, ('a'), '... and the right one is gone';
291300

292301
lives_ok { %h<c>++ }, 'can add (++) an item that was removed';
302+
#?rakudo todo 'todo'
293303
is %h.keys.sort, <a c>, '++ on an item reinstates it';
294304
}
295305

@@ -302,12 +312,16 @@ sub showkv($x) {
302312
is %h.keys.sort, <a c>, '++ on an existing item does not add a key';
303313

304314
lives_ok { %h<a>-- }, 'can remove an item with decrement (--)';
315+
#?rakudo todo 'todo'
305316
is %h.keys, ('c'), 'decrement (--) removes items';
317+
#?rakudo todo 'todo'
306318
nok %h.exists( 'a' ), 'item is gone according to .exists too';
307319
is %h<a>, 0, 'removed item is zero';
308320

309321
lives_ok { %h<a>-- }, 'remove a missing item lives';
322+
#?rakudo todo 'todo'
310323
is %h.keys, ('c'), 'removing missing item does not change contents';
324+
#?rakudo todo 'todo'
311325
is %h<a>, 0, 'item removed again is still zero';
312326
}
313327

S02-types/keyset.t

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ sub showset($s) { $s.keys.sort.join(' ') }
6767
is showset($s), 'a foo', '... but only if they were there to start with';
6868
}
6969

70+
#?rakudo skip ':exists and :delete NYI'
7071
{
7172
my $s = KeySet.new(<a b foo>);
7273
is $s<a>:exists, True, ':exists with existing element';
@@ -164,7 +165,6 @@ sub showset($s) { $s.keys.sort.join(' ') }
164165

165166
{
166167
my $s = KeySet.new(<foo bar baz>);
167-
my $s;
168168
lives_ok { $s = $s.Str }, ".Str lives";
169169
isa_ok $s, Str, "... and produces a string";
170170
ok $s ~~ /foo/, "... which mentions foo";
@@ -174,7 +174,6 @@ sub showset($s) { $s.keys.sort.join(' ') }
174174

175175
{
176176
my $s = KeySet.new(<foo bar baz>);
177-
my $s;
178177
lives_ok { $s = $s.gist }, ".gist lives";
179178
isa_ok $s, Str, "... and produces a string";
180179
ok $s ~~ /foo/, "... which mentions foo";
@@ -207,7 +206,7 @@ sub showset($s) { $s.keys.sort.join(' ') }
207206
is +@a, 2, '.roll(2) returns the right number of items';
208207
is @a.grep(* eq 'a' | 'b' | 'c').elems, 2, '.roll(2) returned "a"s, "b"s, and "c"s';
209208

210-
my @a = $s.roll: 100;
209+
@a = $s.roll: 100;
211210
is +@a, 100, '.roll(100) returns 100 items';
212211
is @a.grep(* eq 'a' | 'b' | 'c').elems, 100, '.roll(100) returned "a"s, "b"s, and "c"s';
213212
}
@@ -239,23 +238,32 @@ sub showset($s) { $s.keys.sort.join(' ') }
239238
#?niecza skip "is KeySet doesn't work yet"
240239
{
241240
my %h is KeySet = a => True, b => False, c => True;
241+
#?rakudo todo 'todo'
242242
is +%h.elems, 2, 'Inititalization worked';
243243

244244
lives_ok { %h<c> = False }, 'can set an item to False';
245+
#?rakudo todo 'todo'
245246
is %h.elems, 1, '... and an item is gone';
247+
#?rakudo todo 'todo'
246248
is ~%h.keys, 'a', '... and the right one is gone';
247249

248250
%h<c>++;
251+
#?rakudo todo 'todo'
249252
is %h.keys.sort.join, 'ac', '++ on an item reinstates it';
250253
%h<c>++;
254+
#?rakudo todo 'todo'
251255
is %h.keys.sort.join, 'ac', '++ on an existing item does nothing';
252256

253257
%h<a>--;
258+
#?rakudo todo 'todo'
254259
is ~%h.keys, 'c', '-- removes items';
255260
%h<b>--;
261+
#?rakudo todo 'todo'
256262
is ~%h.keys, 'c', '... but only if they were there from the beginning';
257263

264+
#?rakudo todo 'todo'
258265
lives_ok { %h = set <Q P R> }, 'Assigning a Set to a KeySet';
266+
#?rakudo todo 'todo'
259267
is %h.keys.sort.join, 'PQR', '... works as expected';
260268
}
261269

S02-types/set.t

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,16 @@ sub showset($s) { $s.keys.sort.join(' ') }
4141

4242
{
4343
my $s = set <a b foo>;
44-
is $s<a>:exists, True, ':exists with existing element';
45-
is $s<santa>:exists, False, ':exists with nonexistent element';
46-
dies_ok { $s<a>:delete }, ':delete does not work on set';
44+
is $s.exists(<a>), True, ':exists with existing element';
45+
is $s.exists(<santa>), False, ':exists with nonexistent element';
46+
dies_ok { $s.delete(<a>) }, ':delete does not work on set';
4747
}
4848

4949
{
5050
my $s = set 2, 'a', False;
5151
my @ks = $s.keys;
5252
#?niecza 3 todo
53+
#?rakudo 3 todo ''
5354
is @ks.grep(Int)[0], 2, 'Int keys are left as Ints';
5455
is @ks.grep(* eqv False).elems, 1, 'Bool keys are left as Bools';
5556
is @ks.grep(Str)[0], 'a', 'And Str keys are permitted in the same set';
@@ -58,6 +59,7 @@ sub showset($s) { $s.keys.sort.join(' ') }
5859

5960
# RT #77760
6061
#?niecza skip "Unmatched key in Hash.LISTSTORE"
62+
#?rakudo skip "Odd number of elements found where hash expected"
6163
{
6264
my %h = set <a b o p a p o o>;
6365
ok %h ~~ Hash, 'A hash to which a Set has been assigned remains a hash';
@@ -132,7 +134,6 @@ sub showset($s) { $s.keys.sort.join(' ') }
132134

133135
{
134136
my $s = set <foo bar baz>;
135-
my $s;
136137
lives_ok { $s = $s.Str }, ".Str lives";
137138
isa_ok $s, Str, "... and produces a string";
138139
ok $s ~~ /foo/, "... which mentions foo";
@@ -142,7 +143,6 @@ sub showset($s) { $s.keys.sort.join(' ') }
142143

143144
{
144145
my $s = set <foo bar baz>;
145-
my $s;
146146
lives_ok { $s = $s.gist }, ".gist lives";
147147
isa_ok $s, Str, "... and produces a string";
148148
ok $s ~~ /foo/, "... which mentions foo";
@@ -166,6 +166,7 @@ sub showset($s) { $s.keys.sort.join(' ') }
166166

167167
# L<S03/Hyper operators/'unordered type'>
168168
#?niecza skip "Hypers not yet Set compatible"
169+
#?rakudo skip "Hypers not yet Set compatible"
169170
{
170171
is showset(set(1, 2, 3) »+» 6), '7 8 9', 'Set »+» Int';
171172
is showset("a" «~« set(<pple bbot rmadillo>)), 'abbot apple armadillo', 'Str «~« Set';
@@ -193,7 +194,7 @@ sub showset($s) { $s.keys.sort.join(' ') }
193194
is +@a, 2, '.roll(2) returns the right number of items';
194195
is @a.grep(* eq 'a' | 'b' | 'c').elems, 2, '.roll(2) returned "a"s, "b"s, and "c"s';
195196

196-
my @a = $s.roll: 100;
197+
@a = $s.roll: 100;
197198
is +@a, 100, '.roll(100) returns 100 items';
198199
is @a.grep(* eq 'a' | 'b' | 'c').elems, 100, '.roll(100) returned "a"s, "b"s, and "c"s';
199200
}

0 commit comments

Comments
 (0)