Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
update various reduction-related tests
  • Loading branch information
TimToady committed Mar 31, 2015
1 parent 6fb9590 commit 849f96c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
7 changes: 6 additions & 1 deletion S32-container/zip.t
Expand Up @@ -11,7 +11,7 @@ The zip() builtin and operator tests
# L<S03/"Traversing arrays in parallel">
# L<S32::Containers/Container/"=item zip">

plan 10;
plan 14;

{
my @a = (0, 2, 4);
Expand Down Expand Up @@ -67,4 +67,9 @@ is ('a'..'c' Z 1, 2, 3).join(','), 'a,1,b,2,c,3',
is ("a".."c" Z "?", "a".."b").join('|'), 'a|?|b|a|c|b',
'can mix arrays and ranges for infix:<Z>';

is zip(1,2; 3,4; 5,6):with(&infix:<~>), '135 246', 'zip:with works on list associative';
is zip(1,2; 1,3; 1,4):with(&infix:</>), '1 ' ~ 1/6, 'zip:with works on left associative';
is zip(1,2; 1,3; 1,4):with(&infix:<**>), '1 2417851639229258349412352', 'zip:with works on right associative';
is zip(1,2; 1,2; 1,2):with(&infix:<eqv>), 'True True', 'zip:with works on chain associative';

# vim: ft=perl6
17 changes: 13 additions & 4 deletions S32-list/reduce.t
Expand Up @@ -11,7 +11,7 @@ L<"http://groups.google.com/groups?selm=420DB295.3000902%40conway.org">
=end description

plan 14;
plan 15;

# L<S32::Containers/List/=item reduce>

Expand All @@ -25,14 +25,23 @@ plan 14;

# Reduce with n-ary functions
{
my @array = <1 2 3 4 5 6 7 8>, Any;
my $result = (((1 + 2 * 3) + 4 * 5) + 6 * 7) + 8 * Any;
my @array = <1 2 3 4 5 6 7 8 9>;
my $result = (((1 + 2 * 3) + 4 * 5) + 6 * 7) + 8 * 9;

#?rakudo todo 'n-ary reduce'
#?niecza skip 'n-ary reduce'
is (@array.reduce: { $^a + $^b * $^c }), $result, "n-ary reduce() works";
}

# Reduce with right associative n-ary functions
{
my @array = <1 2 3 4 5 6 7 8 9>;
my $result = 1 + 2 * (3 + 4 * (5 + 6 * (7 + 8 * 9)));
sub rightly is assoc<right> { $^a + $^b * $^c }

#?niecza skip 'n-ary reduce'
is (@array.reduce: &rightly), $result, "right assoc n-ary reduce() works";
}


{
is( 42.reduce( {$^a+$^b} ), 42, "method form of reduce works on numbers");
Expand Down

0 comments on commit 849f96c

Please sign in to comment.