File: minmaxstr.pm

package info (click to toggle)
liblist-moreutils-perl 0.430-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 1,228 kB
  • sloc: perl: 13,167; makefile: 17
file content (42 lines) | stat: -rw-r--r-- 948 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
39
40
41
42
use Test::More;
use Test::LMU;

use POSIX qw(setlocale LC_COLLATE);
setlocale(LC_COLLATE, "C");

my @list = reverse 'AA' .. 'ZZ';
my ($min, $max) = minmaxstr @list;
is($min, 'AA');
is($max, 'ZZ');

# Odd number of elements
push @list, 'ZZ Top';
($min, $max) = minmaxstr @list;
is($min, 'AA');
is($max, 'ZZ Top');

# COW causes missing max when optimization for 1 argument is applied
@list = grep { defined $_ } map { my ($min, $max) = minmaxstr(sprintf("%s", rand)); ($min, $max) } (0 .. 19);
is(scalar @list, 40, "minmaxstr swallows max on COW");

# Test with a single list value
my $input = 'foo';
($min, $max) = minmaxstr $input;
is($min, 'foo');
is($max, 'foo');

# Confirm output are independant copies of input
$input = 'bar';
is($min, 'foo');
is($max, 'foo');
$min = 'bar';
is($max, 'foo');

leak_free_ok(
    minmaxstr => sub {
        @list = reverse 'AA' .. 'ZZ', 'ZZ Top';
        ($min, $max) = minmaxstr @list;
    }
);

done_testing;