Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
is() => is_deeply(). Corrections/unfudges, Deleted one invalid test.
  • Loading branch information
dwarring committed Jul 25, 2014
1 parent 2944d8b commit d5f7eb6
Showing 1 changed file with 19 additions and 21 deletions.
40 changes: 19 additions & 21 deletions integration/99problems-01-to-10.t
@@ -1,6 +1,6 @@
use v6;
use Test;
plan 22;
plan 21;

{
# P01 (*) Find the last box of a list.
Expand Down Expand Up @@ -103,17 +103,14 @@ plan 22;

my $flatten = { $_ ~~ List ?? ( map $flatten, @($_) ) !! $_ };
my @flattened = map $flatten, ('a', ['b', ['c', 'd', 'e']]);
is @flattened, <a b c d e>, 'We should be able to flatten lists';
is_deeply @flattened, [<a b c d e>], 'We should be able to flatten lists';

# XXX this doesn't work that way...
sub my_flatten (@xs) {
sub my_flatten (*@xs) {
sub inner_flatten (*@xs) { return @xs; }

return inner_flatten(@xs);
}

is my_flatten( ('a', ['b', ['c', 'd', 'e']]) ), <a b c d e>,
'We should be able to flatten lists by func';
}

{
Expand All @@ -129,21 +126,21 @@ plan 22;

# parens required in the assignment. See http://perlmonks.org/?node=587242
my $compress = sub ($x) {
state $previous;
state $previous = '';
return $x ne $previous ?? ($previous = $x) !! ();
}
my @compressed = map $compress, <a a a a b c c a a d e e e e>;
#?niecza todo
is @compressed, <a b c a d e>, 'We should be able to compress lists';
is_deeply @compressed, [<a b c a d e>], 'We should be able to compress lists';
}

{
multi compress2 () { () }
multi compress2 ($a) { $a }
multi compress2 ($x, $y, *@xs) { $x xx ($x !=== $y), compress2($y, |@xs) }
multi compress2 ($x, $y, *@xs) { @( $x xx ($x !=== $y), @( compress2($y, |@xs) )) }

my @x = <a a a a b c c a a d e e e e>;
is compress2(|@x), <a b c a d e>, '... even with multi subs';
is_deeply [compress2(|@x)], [<a b c a d e>], '... even with multi subs';
}

{
Expand All @@ -159,7 +156,8 @@ plan 22;
my @packed;
while @array {
my @list;
@list.push(@array.shift) while !@list || @list[0] eq @array[0];
@list.push(@array.shift)
while @array && (!@list || @list[0] eq @array[0]);
@packed.push([@list]);
}
return @packed;
Expand Down Expand Up @@ -190,21 +188,21 @@ plan 22;
'... even using gather/take';
}

#?rakudo skip 'groupless gather/take'
# ? rakudo skip 'groupless gather/take'
#?niecza skip 'Unable to resolve method reverse in class Parcel'
{
sub group2 (*@array is copy) {
gather while @array {
take [
my $h = shift @array,
my $h = @array[0];
gather while @array and $h eq @array[0] {
take shift @array;
}
];
}
}
is group2(<a a a a b c c a a d e e e e>).join('+'),
'a a a a+b+c c+a a+d+e e e e',
is_deeply [group2(<a a a a b c c a a d e e e e>)],
[[<a a a a>], [<b>], [<c c>], [<a a>], [<d>], [<e e e e>]],
'... even using blockless gather/take';

}
Expand All @@ -227,11 +225,11 @@ plan 22;

for @list {
$x = $_;
if $x eq $previous {
$count++;
next;
}
if defined $previous {
if $x eq $previous {
$count++;
next;
}
@encoded.push([$count, $previous]);
$count = 1;
}
Expand All @@ -241,8 +239,8 @@ plan 22;
return @encoded;
}

is encode(<a a a a b c c a a d e e e e>).join('+'),
'4 a+1 b+2 c+2 a+1 d+4 e',
is_deeply encode(<a a a a b c c a a d e e e e>),
[[4, "a"], [1, "b"], [2, "c"], [2, "a"], [1, "d"], [4, "e"]],
'We should be able to run-length encode lists';
}

Expand Down

0 comments on commit d5f7eb6

Please sign in to comment.