1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
use Test::More tests => 7;
use strict;
use warnings;
use Iterator::Simple qw(:all);
my $itr;
{
my $ary = [qw(a b c d e f g h i j)];
$itr = islice($ary, 2, 8);
is_deeply list($itr) => [qw(c d e f g h)], 'islice';
}
{
my $ary = [qw(a b c d e f g h i j)];
$itr = islice($ary, 2, 8, 2);
is_deeply list($itr) => [qw(c e g)], 'islice with step';
}
{
my $ary = [qw(a b c d e f g h i j)];
$itr = islice($ary, 1, 8, 2);
is_deeply list($itr) => [qw(b d f h)], 'islice with step2';
}
{
my $ary = [qw(a b c d e f g h i j)];
$itr = islice($ary, 4, undef, 2);
is_deeply list($itr) => [qw(e g i )], 'islice with step without $end';
}
{
my $ary = [qw(a b c d e f g h i j)];
$itr = ihead(5, $ary);
is_deeply list($itr) => [qw(a b c d e)], 'ihead';
}
{
my $ary = [qw(a b c d e f g h i j)];
$itr = iskip(5, $ary);
is_deeply list($itr) => [qw(f g h i j)], 'iskip';
}
{
my $ary = [qw(1 0 3 7)];
$itr = islice($ary, 0, 3);
is_deeply list($itr) => [qw(1 0 3)], 'islice including 0';
}
|