Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add tests for .min/.max on (Set|Bag|Mix)Hash
  • Loading branch information
lizmat committed Apr 13, 2014
1 parent a503ffa commit 02346c6
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 10 deletions.
22 changes: 17 additions & 5 deletions S02-types/bag.t
@@ -1,7 +1,7 @@
use v6;
use Test;

plan 173;
plan 179;

sub showkv($x) {
$x.keys.sort.map({ $^k ~ ':' ~ $x{$k} }).join(' ')
Expand Down Expand Up @@ -41,10 +41,6 @@ sub showkv($x) {

is ~$b<a b>, "5 1", 'Multiple-element access';
is ~$b<a santa b easterbunny>, "5 0 1 0", 'Multiple-element access (with nonexistent elements)';

#?pugs skip '.total NYI'
is $b.total, 8, '.total gives sum of values';
is +$b, 8, '+$bag gives sum of values';
}

{
Expand Down Expand Up @@ -397,4 +393,20 @@ sub showkv($x) {
"Method .Bag works on Parcel-2";
}

#?pugs skip '.total/.min/.max NYI'
#?niecza skip '.total/.min/.max NYI'
{
my $b = <a b b c c c d d d d>.Bag;
is $b.total, 10, '.total gives sum of values (non-empty)';
is +$b, 10, '+$bag gives sum of values (non-empty)';
is $b.min, 1, '.min works (non-empty)';
is $b.max, 4, '.max works (non-empty)';

my $e = ().Bag;
is $e.total, 0, '.total gives sum of values (empty)';
is +$e, 0, '+$bag gives sum of values (empty)';
is $e.min, Inf, '.min works (empty)';
is $e.max, -Inf, '.max works (empty)';
}

# vim: ft=perl6
18 changes: 17 additions & 1 deletion S02-types/baghash.t
@@ -1,7 +1,7 @@
use v6;
use Test;

plan 226;
plan 234;

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

Expand Down Expand Up @@ -524,4 +524,20 @@ sub showkv($x) {
"Method .BagHash works on Parcel-2";
}

#?pugs skip '.total/.min/.max NYI'
#?niecza skip '.total/.min/.max NYI'
{
my $b = <a b b c c c d d d d>.BagHash;
is $b.total, 10, '.total gives sum of values (non-empty)';
is +$b, 10, '+$bag gives sum of values (non-empty)';
is $b.min, 1, '.min works (non-empty)';
is $b.max, 4, '.max works (non-empty)';

my $e = ().BagHash;
is $e.total, 0, '.total gives sum of values (empty)';
is +$e, 0, '+$bag gives sum of values (empty)';
is $e.min, Inf, '.min works (empty)';
is $e.max, -Inf, '.max works (empty)';
}

# vim: ft=perl6
18 changes: 17 additions & 1 deletion S02-types/mix.t
@@ -1,7 +1,7 @@
use v6;
use Test;

plan 153;
plan 161;

sub showkv($x) {
$x.keys.sort.map({ $^k ~ ':' ~ $x{$k} }).join(' ')
Expand Down Expand Up @@ -350,4 +350,20 @@ sub showkv($x) {
"Method .Mix works on Parcel-2";
}

#?pugs skip '.total/.min/.max NYI'
#?niecza skip '.total/.min/.max NYI'
{
my $m = (a => 1.1, b => 2.2, c => 3.3, d => 4.4).Mix;
is $m.total, 11, '.total gives sum of values (non-empty)';
is +$m, 11, '+$set gives sum of values (non-empty)';
is $m.min, 1.1, '.min works (non-empty)';
is $m.max, 4.4, '.max works (non-empty)';

my $e = ().Mix;
is $e.total, 0, '.total gives sum of values (empty)';
is +$e, 0, '+$mix gives sum of values (empty)';
is $e.min, Inf, '.min works (empty)';
is $e.max, -Inf, '.max works (empty)';
}

# vim: ft=perl6
18 changes: 17 additions & 1 deletion S02-types/mixhash.t
@@ -1,7 +1,7 @@
use v6;
use Test;

plan 191;
plan 199;

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

Expand Down Expand Up @@ -438,4 +438,20 @@ sub showkv($x) {
"Method .MixHash works on Parcel-2";
}

#?pugs skip '.total/.min/.max NYI'
#?niecza skip '.total/.min/.max NYI'
{
my $m = (a => 1.1, b => 2.2, c => 3.3, d => 4.4).MixHash;
is $m.total, 11, '.total gives sum of values (non-empty)';
is +$m, 11, '+$set gives sum of values (non-empty)';
is $m.min, 1.1, '.min works (non-empty)';
is $m.max, 4.4, '.max works (non-empty)';

my $e = ().MixHash;
is $e.total, 0, '.total gives sum of values (empty)';
is +$e, 0, '+$mix gives sum of values (empty)';
is $e.min, Inf, '.min works (empty)';
is $e.max, -Inf, '.max works (empty)';
}

# vim: ft=perl6
18 changes: 17 additions & 1 deletion S02-types/set.t
@@ -1,7 +1,7 @@
use v6;
use Test;

plan 151;
plan 159;

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

Expand Down Expand Up @@ -340,4 +340,20 @@ sub showset($s) { $s.keys.sort.join(' ') }
is showset((@a, %x).Set), "Now Paradise a b cross-handed set the was way", "Method .Set works on Parcel-2";
}

#?pugs skip '.total/.min/.max NYI'
#?niecza skip '.total/.min/.max NYI'
{
my $s = <a b b c c c d d d d>.Set;
is $s.total, 4, '.total gives sum of values (non-empty)';
is +$s, 4, '+$set gives sum of values (non-empty)';
is $s.min, 1, '.min works (non-empty)';
is $s.max, 1, '.max works (non-empty)';

my $e = ().Set;
is $e.total, 0, '.total gives sum of values (empty)';
is +$e, 0, '+$set gives sum of values (empty)';
is $e.min, Inf, '.min works (empty)';
is $e.max, -Inf, '.max works (empty)';
}

# vim: ft=perl6
18 changes: 17 additions & 1 deletion S02-types/sethash.t
@@ -1,7 +1,7 @@
use v6;
use Test;

plan 183;
plan 191;

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

Expand Down Expand Up @@ -408,4 +408,20 @@ sub showset($s) { $s.keys.sort.join(' ') }
is showset((@a, %x).SetHash), "Now Paradise a b cross-handed set the was way", "Method .SetHash works on Parcel-2";
}

#?pugs skip '.total/.min/.max NYI'
#?niecza skip '.total/.min/.max NYI'
{
my $s = <a b b c c c d d d d>.SetHash;
is $s.total, 4, '.total gives sum of values (non-empty)';
is +$s, 4, '+$set gives sum of values (non-empty)';
is $s.min, 1, '.min works (non-empty)';
is $s.max, 1, '.max works (non-empty)';

my $e = ().SetHash;
is $e.total, 0, '.total gives sum of values (empty)';
is +$e, 0, '+$set gives sum of values (empty)';
is $e.min, Inf, '.min works (empty)';
is $e.max, -Inf, '.max works (empty)';
}

# vim: ft=perl6

0 comments on commit 02346c6

Please sign in to comment.