Skip to content

Commit

Permalink
(Set|Bag|Mix)(|Hash).(min|max)->(minpairs|maxpairs)
Browse files Browse the repository at this point in the history
  • Loading branch information
lizmat committed Apr 14, 2014
1 parent a783d7b commit 36be63e
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 52 deletions.
32 changes: 22 additions & 10 deletions S02-types/bag.t
@@ -1,7 +1,7 @@
use v6;
use Test;

plan 179;
plan 187;

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

#?pugs skip '.total/.min/.max NYI'
#?niecza skip '.total/.min/.max NYI'
#?pugs skip '.total/.minpairs/.maxpairs NYI'
#?niecza skip '.total/.minpairs/.maxpairs 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 $b1 = <a b b c c c d d d d>.Bag;
is $b1.total, 10, '.total gives sum of values (non-empty 10)';
is +$b1, 10, '+$bag gives sum of values (non-empty 10)';
is $b1.minpairs, [a=>1], '.minpairs works (non-empty 10)';
is $b1.maxpairs, [d=>4], '.maxpairs works (non-empty 10)';

my $b2 = <a b c c c d d d>.Bag;
is $b2.total, 8, '.total gives sum of values (non-empty 8)';
is +$b2, 8, '+$bag gives sum of values (non-empty 8)';
is $b2.minpairs.sort, [a=>1, b=>1], '.minpairs works (non-empty 8)';
is $b2.maxpairs.sort, [c=>3, d=>3], '.maxpairs works (non-empty 8)';

my $b2 = <a b c d>.Bag;
is $b2.total, 4, '.total gives sum of values (non-empty 4)';
is +$b2, 4, '+$bag gives sum of values (non-empty 4)';
is $b2.minpairs.sort,[a=>1,b=>1,c=>1,d=>1], '.minpairs works (non-empty 4)';
is $b2.maxpairs.sort,[a=>1,b=>1,c=>1,d=>1], '.maxpairs works (non-empty 4)';

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)';
is $e.minpairs, (), '.minpairs works (empty)';
is $e.maxpairs, (), '.maxpairs works (empty)';
}

# vim: ft=perl6
32 changes: 22 additions & 10 deletions S02-types/baghash.t
@@ -1,7 +1,7 @@
use v6;
use Test;

plan 234;
plan 242;

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

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

#?pugs skip '.total/.min/.max NYI'
#?niecza skip '.total/.min/.max NYI'
#?pugs skip '.total/.minpairs/.maxpairs NYI'
#?niecza skip '.total/.minpairs/.maxpairs 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 $b1 = <a b b c c c d d d d>.BagHash;
is $b1.total, 10, '.total gives sum of values (non-empty) 10';
is +$b1, 10, '+$bag gives sum of values (non-empty) 10';
is $b1.minpairs, [a=>1], '.minpairs works (non-empty) 10';
is $b1.maxpairs, [d=>4], '.maxpairs works (non-empty) 10';

my $b2 = <a b c c c d d d>.BagHash;
is $b2.total, 8, '.total gives sum of values (non-empty) 8';
is +$b2, 8, '+$bag gives sum of values (non-empty) 8';
is $b2.minpairs.sort, [a=>1,b=>1], '.minpairs works (non-empty) 8';
is $b2.maxpairs.sort, [c=>3,d=>3], '.maxpairs works (non-empty) 8';

my $b3 = <a b c d>.BagHash;
is $b3.total, 4, '.total gives sum of values (non-empty) 4';
is +$b3, 4, '+$bag gives sum of values (non-empty) 4';
is $b3.minpairs.sort,[a=>1,b=>1,c=>1,d=>1], '.minpairs works (non-empty) 4';
is $b3.maxpairs.sort,[a=>1,b=>1,c=>1,d=>1], '.maxpairs works (non-empty) 4';

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)';
is $e.minpairs, (), '.minpairs works (empty)';
is $e.maxpairs, (), '.maxpairs works (empty)';
}

# vim: ft=perl6
32 changes: 22 additions & 10 deletions S02-types/mix.t
@@ -1,7 +1,7 @@
use v6;
use Test;

plan 161;
plan 169;

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

#?pugs skip '.total/.min/.max NYI'
#?niecza skip '.total/.min/.max NYI'
#?pugs skip '.total/.minpairs/.maxpairs NYI'
#?niecza skip '.total/.minpairs/.maxpairs 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 $m1 = (a => 1.1, b => 2.2, c => 3.3, d => 4.4).Mix;
is $m1.total, 11, '.total gives sum of values (non-empty) 11';
is +$m1, 11, '+$set gives sum of values (non-empty) 11';
is $m1.minpairs, [a=>1.1], '.minpairs works (non-empty) 11';
is $m1.maxpairs, [d=>4.4], '.maxpairs works (non-empty) 11';

my $m2 = (a => 1.1, b => 1.1, c => 3.3, d => 3.3).Mix;
is $m2.total, 8.8, '.total gives sum of values (non-empty) 8.8';
is +$m2, 8.8, '+$set gives sum of values (non-empty) 8.8';
is $m2.minpairs.sort, [a=>1.1,b=>1.1], '.minpairs works (non-empty) 8.8';
is $m2.maxpairs.sort, [c=>3.3,d=>3.3], '.maxpairs works (non-empty) 8.8';

my $m3 = (a => 1.1, b => 1.1, c => 1.1, d => 1.1).Mix;
is $m3.total, 4.4, '.total gives sum of values (non-empty) 4.4';
is +$m3, 4.4, '+$set gives sum of values (non-empty) 4.4';
is $m3.minpairs.sort,[a=>1.1,b=>1.1,c=>1.1,d=>1.1], '.minpairs works (non-empty) 4.4';
is $m3.maxpairs.sort,[a=>1.1,b=>1.1,c=>1.1,d=>1.1], '.maxpairs works (non-empty) 4.4';

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)';
is $e.minpairs, (), '.minpairs works (empty)';
is $e.maxpairs, (), '.maxpairs works (empty)';
}

# vim: ft=perl6
32 changes: 22 additions & 10 deletions S02-types/mixhash.t
@@ -1,7 +1,7 @@
use v6;
use Test;

plan 199;
plan 207;

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

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

#?pugs skip '.total/.min/.max NYI'
#?niecza skip '.total/.min/.max NYI'
#?pugs skip '.total/.minpairs/.maxpairs NYI'
#?niecza skip '.total/.minpairs/.maxpairs 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 $m1 = (a => 1.1, b => 2.2, c => 3.3, d => 4.4).MixHash;
is $m1.total, 11, '.total gives sum of values (non-empty) 11';
is +$m1, 11, '+$mix gives sum of values (non-empty) 11';
is $m1.minpairs, [a=>1.1], '.minpairs works (non-empty) 11';
is $m1.maxpairs, [d=>4.4], '.maxpairs works (non-empty) 11';

my $m2 = (a => 1.1, b => 1.1, c => 3.3, d => 3.3).MixHash;
is $m2.total, 8.8, '.total gives sum of values (non-empty) 8.8';
is +$m2, 8.8, '+$mix gives sum of values (non-empty) 8.8';
is $m2.minpairs.sort, [a=>1.1,b=>1.1], '.minpairs works (non-empty) 8.8';
is $m2.maxpairs.sort, [c=>3.3,d=>3.3], '.maxpairs works (non-empty) 8.8';

my $m3 = (a => 1.1, b => 1.1, c => 1.1, d => 1.1).MixHash;
is $m3.total, 4.4, '.total gives sum of values (non-empty) 4.4';
is +$m3, 4.4, '+$mix gives sum of values (non-empty) 4.4';
is $m3.minpairs.sort,[a=>1.1,b=>1.1,c=>1.1,d=>1.1], '.minpairs works (non-empty) 4.4';
is $m3.maxpairs.sort,[a=>1.1,b=>1.1,c=>1.1,d=>1.1], '.maxpairs works (non-empty) 4.4';

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)';
is $e.minpairs, (), '.minpairs works (empty)';
is $e.maxpairs, (), '.maxpairs works (empty)';
}

# vim: ft=perl6
12 changes: 6 additions & 6 deletions S02-types/set.t
Expand Up @@ -340,20 +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'
#?pugs skip '.total/.minpairs/.maxpairs NYI'
#?niecza skip '.total/.minpairs/.maxpairs 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)';
is $s.minpairs.sort,[a=>True,b=>True,c=>True,d=>True], '.minpairs works (non-empty)';
is $s.maxpairs.sort,[a=>True,b=>True,c=>True,d=>True], '.maxpairs 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)';
is $e.minpairs, (), '.minpairs works (empty)';
is $e.maxpairs, (), '.maxpairs works (empty)';
}

# vim: ft=perl6
12 changes: 6 additions & 6 deletions S02-types/sethash.t
Expand Up @@ -408,20 +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'
#?pugs skip '.total/.minpairs/.maxpairs NYI'
#?niecza skip '.total/.minpairs/.maxpairs 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)';
is $s.minpairs, [a=>True,b=>True,c=>True,d=>True], '.minpairs works (non-empty)';
is $s.maxpairs, [a=>True,b=>True,c=>True,d=>True], '.maxpairs 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)';
is $e.minpairs, (), '.minpairs works (empty)';
is $e.maxpairs, (), '.maxpairs works (empty)';
}

# vim: ft=perl6

0 comments on commit 36be63e

Please sign in to comment.