File: reduce_0.pm

package info (click to toggle)
liblist-moreutils-xs-perl 0.430-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,116 kB
  • sloc: perl: 9,038; ansic: 159; makefile: 3
file content (38 lines) | stat: -rw-r--r-- 938 bytes parent folder | download | duplicates (4)
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

use Test::More;
use Test::LMU;

use List::Util qw(sum);

SCOPE:
{
    my @exam_results = (2, 4, 6, 5, 3, 0);
    my $pupil        = sum @exam_results;
    my $wa           = reduce_0 { $a + ($_ + 1) * $b / $pupil } @exam_results;
    $wa = sprintf("%0.2f", $wa);
    is($wa, 3.15, "weighted average of exam");
}

leak_free_ok(
    'reduce_0' => sub {
        my @exam_results = (2, 4, 6, 5, 3, 0);
        my $pupil        = 20;
        my $wa           = reduce_0 { $a + ($_ + 1) * $b / $pupil } @exam_results;
    },
    'reduce_0 X' => sub {
        my @w  = map { int(rand(5)) + 1; } 1 .. 100;
        my $c1 = reduce_0 { $a + $w[$_] * $b } 1 .. 100;
    }
);
leak_free_ok(
    'reduce_0 with a coderef that dies' => sub {
        # This test is from Kevin Ryde; see RT#48669
        eval {
            my $ok = reduce_0 { die } 1;
        };
    }
);
is_dying('reduce_0 without sub' => sub { &reduce_0(42, 4711); });

done_testing