Skip to content

Commit

Permalink
Some basic .KeySet and .Bag tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
colomon committed Jun 6, 2013
1 parent 060d569 commit b0f6ccb
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
20 changes: 19 additions & 1 deletion S02-types/bag.t
@@ -1,7 +1,7 @@
use v6;
use Test;

plan 114;
plan 125;

sub showkv($x) {
$x.keys.sort.map({ $^k ~ ':' ~ $x{$k} }).join(' ')
Expand Down Expand Up @@ -44,6 +44,24 @@ sub showkv($x) {
is +$b, 8, '+$bag gives sum of values';
}

#?rakudo skip ".Set NYI"
{
isa_ok "a".Bag, Bag, "Str.Bag makes a Bag";
is showkv("a".Bag), 'a:1', "'a'.Bag is bag a";

isa_ok (a => 100000).Bag, Bag, "Pair.Bag makes a Bag";
is showkv((a => 100000).Bag), 'a:100000', "(a => 100000).Bag is bag a:100000";
is showkv((a => 0).Bag), '', "(a => 0).Bag is the empty bag";

isa_ok <a b c>.Bag, Bag, "<a b c>.Bag makes a Bag";
is showkv(<a b c a>.Bag), 'a:2 b:1 c:1', "<a b c a>.Bag makes the bag a:2 b:1 c:1";
is showkv(["a", "b", "c", "a"].Bag), 'a:2 b:1 c:1', "[a b c a].Bag makes the bag a:2 b:1 c:1";
is showkv([a => 3, b => 0, 'c', 'a'].Bag), 'a:4 c:1', "[a => 3, b => 0, 'c', 'a'].Bag makes the bag a:4 c:1";

isa_ok {a => 2, b => 4, c => 0}.Bag, Bag, "{a => 2, b => 4, c => 0}.Bag makes a Bag";
is showkv({a => 2, b => 4, c => 0}.Bag), 'a:2 b:4', "{a => 2, b => 4, c => 0}.Bag makes the bag a:2 b:4";
}

{
my $s = bag <a a b foo>;
is $s<a>:exists, True, ':exists with existing element';
Expand Down
20 changes: 19 additions & 1 deletion S02-types/keyset.t
@@ -1,7 +1,7 @@
use v6;
use Test;

plan 111;
plan 122;

# L<S02/Mutable types/"KeyHash of Bool">

Expand Down Expand Up @@ -68,6 +68,24 @@ sub showset($s) { $s.keys.sort.join(' ') }
is showset($s), 'a foo', '... but only if they were there to start with';
}

#?rakudo skip ".Set NYI"
{
isa_ok "a".KeySet, KeySet, "Str.KeySet makes a KeySet";
is showset("a".KeySet), 'a', "'a'.KeySet is set a";

isa_ok (a => 1).KeySet, KeySet, "Pair.KeySet makes a KeySet";
is showset((a => 1).KeySet), 'a', "(a => 1).KeySet is set a";
is showset((a => 0).KeySet), '', "(a => 0).KeySet is the empty set";

isa_ok <a b c>.KeySet, KeySet, "<a b c>.KeySet makes a KeySet";
is showset(<a b c a>.KeySet), 'a b c', "<a b c a>.KeySet makes the set a b c";
is showset(["a", "b", "c", "a"].KeySet), 'a b c', "[a b c a].KeySet makes the set a b c";
is showset([a => 3, b => 0, 'c', 'a'].KeySet), 'a c', "[a => 3, b => 0, 'c', 'a'].KeySet makes the set a c";

isa_ok {a => 2, b => 4, c => 0}.KeySet, KeySet, "{a => 2, b => 4, c => 0}.KeySet makes a KeySet";
is showset({a => 2, b => 4, c => 0}.KeySet), 'a b', "{a => 2, b => 4, c => 0}.KeySet makes the set a b";
}

{
my $s = KeySet.new(<a b foo>);
is $s<a>:exists, True, ':exists with existing element';
Expand Down

0 comments on commit b0f6ccb

Please sign in to comment.