File: 18_chunksOf.t

package info (click to toggle)
libperlude-perl 0.61-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 360 kB
  • sloc: perl: 903; makefile: 2
file content (47 lines) | stat: -rw-r--r-- 863 bytes parent folder | download
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
#! /usr/bin/perl
use 5.010;
use strict;
use warnings;
use Test::More 'no_plan';
use Perlude;

# this is the reference: don't touch it
# because chunksOf means to preserve the content of the original array 

my @reference = 'a'..'f'; # alpha symbols of hexadecimal base

# this is the copy of the reference array!
my @source    = @reference;

my $got = chunksOf 3, \@source;

# what we expect $got to produce
my @expect = 
( [ qw[ a b c ]]
, [ qw[ d e f ]] );

now {
    state $counter = 0;
    $counter++;

    @expect or BAIL_OUT
        ( "the ${counter}th call to chunksOf wasn't expected. it contains "
        . join ',',@$_ );

    my $e = shift @expect;

    is_deeply $e, $_
    , "row $counter is expected";

} $got;

ok
( (0 == @expect)
, 'chunksOf finish the job' );

my @unused = fold $got;
ok
( (0 == @unused)
, 'chunksOf dont send extra stuff' );