File: 04_min_by.t

package info (click to toggle)
liblist-utilsby-xs-perl 0.06-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 212 kB
  • sloc: perl: 198; makefile: 3; sh: 1
file content (36 lines) | stat: -rw-r--r-- 998 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
34
35
36
use strict;
use warnings;

use Test::More;

use List::UtilsBy::XS qw(min_by nmin_by);

my $expected;
my $got;
my @gots;
my @array;

is_deeply( [ min_by {} ], [], 'empty list yields empty' );

$got = scalar (min_by { $_ } 10);
ok($got == 10, 'unit list yields value in scalar context');
is_deeply( [ min_by { $_ } 10 ], [ 10 ], 'unit list yields unit list value' );

is_deeply( ( scalar min_by { $_ } 10, 20 ), 10, 'identity function on $_' );

$got = scalar(min_by { length $_ } "a", "ccc", "bb");
ok($got eq 'a', "length function in scalar context");

@gots = min_by { length $_ } "a", "ccc", "bb";
is_deeply(\@gots, [ 'a' ], "length function in list context");

$got = scalar(min_by { length $_ } "a", "ccc", "bb", "ddd");
ok($got eq 'a', "first max element");

@gots = min_by { length $_ } "a", "ccc", "b", "ddd";
$expected = [ qw/a b/ ];
is_deeply(\@gots, $expected, 'ties yield all maximal in list context');

is_deeply( ( scalar nmin_by { $_ } 10, 20 ), 10, 'nmin_by alias' );

done_testing;