Skip to content

Commit 987bced

Browse files
committed
Add tests for (Bag|BagHash).pickpairs
1 parent d12ea39 commit 987bced

File tree

2 files changed

+52
-2
lines changed

2 files changed

+52
-2
lines changed

S02-types/bag.t

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use v6;
22
use Test;
33

4-
plan 162;
4+
plan 173;
55

66
sub showkv($x) {
77
$x.keys.sort.map({ $^k ~ ':' ~ $x{$k} }).join(' ')
@@ -323,6 +323,31 @@ sub showkv($x) {
323323
is $b.total, 100000000001, '.pick should not change Bag';
324324
}
325325

326+
# L<S32::Containers/Bag/pickpairs>
327+
328+
{
329+
my $b = Bag.new("a", "b", "b");
330+
331+
my $a = $b.pickpairs;
332+
isa_ok $a, List, 'Did we get a List';
333+
is $a.elems, 1, 'Did we get one element';
334+
isa_ok $a[0], Pair, 'Did we get a Pair in the List';
335+
ok ($a[0] eq "a\t1" or $a[0] eq "b\t2"), "We got one of the two choices";
336+
337+
my @a = $b.pickpairs(2);
338+
is +@a, 2, '.pickpairs(2) returns the right number of items';
339+
is @a.grep(* eq "a\t1").elems, 1, '.pickpairs(2) returned one "a"';
340+
is @a.grep(* eq "b\t2").elems, 1, '.pickpairs(2) returned one "b"';
341+
342+
@a = $b.pickpairs: *;
343+
is +@a, 2, '.pickpairs(*) returns the right number of items';
344+
is @a.grep(* eq "a\t1").elems, 1, '.pickpairs(*) (1)';
345+
is @a.grep(* eq "b\t2").elems, 1, '.pickpairs(*) (2)';
346+
#?pugs skip '.total NYI'
347+
#?niecza skip '.total NYI'
348+
is $b.total, 3, '.pickpairs should not change Bag';
349+
}
350+
326351
# L<S32::Containers/Bag/grab>
327352

328353
#?pugs skip '.grab NYI'

S02-types/baghash.t

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use v6;
22
use Test;
33

4-
plan 214;
4+
plan 225;
55

66
# L<S02/Mutable types/QuantHash of UInt>
77

@@ -333,6 +333,31 @@ sub showkv($x) {
333333
is $b.elems, 2, '.pick should not change BagHash';
334334
}
335335

336+
# L<S32::Containers/BagHash/pickpairs>
337+
338+
{
339+
my $b = BagHash.new("a", "b", "b");
340+
341+
my $a = $b.pickpairs;
342+
isa_ok $a, List, 'Did we get a List';
343+
is $a.elems, 1, 'Did we get one element';
344+
isa_ok $a[0], Pair, 'Did we get a Pair in the List';
345+
ok ($a[0] eq "a\t1" or $a[0] eq "b\t2"), "We got one of the two choices";
346+
347+
my @a = $b.pickpairs(2);
348+
is +@a, 2, '.pickpairs(2) returns the right number of items';
349+
is @a.grep(* eq "a\t1").elems, 1, '.pickpairs(2) returned one "a"';
350+
is @a.grep(* eq "b\t2").elems, 1, '.pickpairs(2) returned one "b"';
351+
352+
@a = $b.pickpairs: *;
353+
is +@a, 2, '.pickpairs(*) returns the right number of items';
354+
is @a.grep(* eq "a\t1").elems, 1, '.pickpairs(*) (1)';
355+
is @a.grep(* eq "b\t2").elems, 1, '.pickpairs(*) (2)';
356+
#?pugs skip '.total NYI'
357+
#?niecza skip '.total NYI'
358+
is $b.total, 3, '.pickpairs should not change Bag';
359+
}
360+
336361
# L<S32::Containers/BagHash/grab>
337362

338363
#?pugs skip '.grab NYI'

0 commit comments

Comments
 (0)