Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Set/Bag test tweaks
  • Loading branch information
lizmat committed Sep 8, 2013
1 parent fe60380 commit 6d7b8ae
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 8 deletions.
28 changes: 27 additions & 1 deletion S02-types/bag.t
@@ -1,7 +1,7 @@
use v6;
use Test;

plan 142;
plan 154;

sub showkv($x) {
$x.keys.sort.map({ $^k ~ ':' ~ $x{$k} }).join(' ')
Expand Down Expand Up @@ -104,6 +104,11 @@ sub showkv($x) {
ok %h ~~ Hash, 'A hash to which a Bag has been assigned remains a hash';
is showkv(%h), 'a:2 b:1 o:3 p:2', '...with the right elements';
}
{
my %h := bag <a b o p a p o o>;
ok %h ~~ Bag, 'A hash to which a Bag has been bound becomes a Bag';
is showkv(%h), 'a:2 b:1 o:3 p:2', '...with the right elements';
}

{
my $b = bag <a b o p a p o o>;
Expand Down Expand Up @@ -299,6 +304,27 @@ sub showkv($x) {
ok @a.grep(* eq 'b') < 2, '.pick(100) (2)';
}

{
my $b1 = bag ( bag <a b c> ), <c c c d d d d>;
is +$b1, 8, "Three elements";
is $b1<c>, 3, "One of them is 'c'";
is $b1<d>, 4, "One of them is 'd'";
my $inner-bag = $b1.list.first(Bag);
#?niecza 2 todo 'Bag in Bag does not work correctly yet'
isa_ok $inner-bag, Bag, "One of the bag's elements is indeed a bag!";
is showkv($inner-bag), "a:1 b:1 c:1", "With the proper elements";

my $b = bag <a b c>;
$b1 = bag $b, <c d>;
is +$b1, 3, "Three elements";
is $b1<c>, 1, "One of them is 'c'";
is $b1<d>, 1, "One of them is 'd'";
$inner-bag = $b1.list.first(Bag);
#?niecza 2 todo 'Bag in Bag does not work correctly yet'
isa_ok $inner-bag, Bag, "One of the bag's elements is indeed a bag!";
is showkv($inner-bag), "a:1 b:1 c:1", "With the proper elements";
}

{
isa_ok 42.Bag, Bag, "Method .Bag works on Int-1";
is showkv(42.Bag), "42:1", "Method .Bag works on Int-2";
Expand Down
20 changes: 13 additions & 7 deletions S02-types/set.t
@@ -1,7 +1,7 @@
use v6;
use Test;

plan 139;
plan 146;

sub showset($s) { $s.keys.sort.join(' ') }

Expand Down Expand Up @@ -97,11 +97,15 @@ sub showset($s) { $s.keys.sort.join(' ') }
{
my %h = set <a b o p a p o o>;
ok %h ~~ Hash, 'A hash to which a Set has been assigned remains a hash';
#?rakudo todo "got ao"
is %h.keys.sort.join, 'abop', '...with the right keys';
#?rakudo todo "got bp"
is %h.values, (True, True, True, True), '...and values all True';
}
{
my %h := set <a b o p a p o o>;
ok %h ~~ Set, 'A hash to which a Set has been bound becomes a set';
is %h.keys.sort.join, 'abop', '...with the right keys';
is %h.values, (True xx 4), '...and values all True';
}

{
my $s = set <foo bar foo bar baz foo>;
Expand Down Expand Up @@ -160,6 +164,10 @@ sub showset($s) { $s.keys.sort.join(' ') }
my $s = set <foo bar baz>;
isa_ok $s.list.elems, 3, ".list returns 3 things";
is $s.list.grep(Str).elems, 3, "... all of which are Str";
isa_ok $s.pairs.elems, 3, ".pairs returns 3 things";
is $s.pairs.grep(Pair).elems, 3, "... all of which are Pair";
is $s.pairs.grep({ .key ~~ Str }).elems, 3, "... the keys of which are Strs";
is $s.pairs.grep({ .value ~~ Bool }).elems, 3, "... and the values of which are Bool";
#?rakudo skip "Set is no longer Iterable"
is $s.iterator.grep(Str).elems, 3, ".iterator yields three Strs";
}
Expand Down Expand Up @@ -271,21 +279,19 @@ sub showset($s) { $s.keys.sort.join(' ') }
is +$s1, 3, "Three elements";
ok $s1<c>, "One of them is 'c'";
ok $s1<d>, "One of them is 'd'";
my $inner-set = $s1.first(Set);
my $inner-set = $s1.list.first(Set);
#?niecza 2 todo 'Set in Set does not work correctly yet'
isa_ok $inner-set, Set, "One of the set's elements is indeed a set!";
#?rakudo todo "Set does not conform to new standard yet"
is showset($inner-set), "a b c", "With the proper elements";

my $s = set <a b c>;
$s1 = set $s, <c d>;
is +$s1, 3, "Three elements";
ok $s1<c>, "One of them is 'c'";
ok $s1<d>, "One of them is 'd'";
$inner-set = $s1.first(Set);
$inner-set = $s1.list.first(Set);
#?niecza 2 todo 'Set in Set does not work correctly yet'
isa_ok $inner-set, Set, "One of the set's elements is indeed a set!";
#?rakudo todo "Set does not conform to new standard yet"
is showset($inner-set), "a b c", "With the proper elements";
}

Expand Down

0 comments on commit 6d7b8ae

Please sign in to comment.