File: ipairwise.t

package info (click to toggle)
libiterator-util-perl 0.02%2Bds1-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 136 kB
  • ctags: 12
  • sloc: perl: 234; makefile: 2
file content (33 lines) | stat: -rw-r--r-- 761 bytes parent folder | download | duplicates (3)
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
use strict;
use Test::More tests => 2;
use Iterator::Util;

# Check that ipairwise works as promised.


sub begins_with
{
    my ($actual, $expected, $test_name) = @_;

    $actual = substr($actual, 0, length $expected);
    @_ =  ($actual, $expected, $test_name);
    goto &is;
}

my ($iter, @vals);

# ipairwise (2)
eval
{
    no warnings 'once';

    my $first  = irange 1;                              # 1,  2,  3,  4, ...
    my $second = irange 4, undef, 2;                    # 4,  6,  8, 10, ...
    my $third  = ipairwise {$a * $b} $first, $second;   # 4, 12, 24, 40, ...

    push @vals, $third->value  for (1..4)
};

is $@, q{},   q{Created ipairwise iterator, no errors};
is_deeply (\@vals, [4, 12, 24, 40], q{ipairwise returned expected values});