This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Update to Scalar-List-Utils-1.15
[perl5.git] / ext / List / Util / t / max.t
CommitLineData
1bfb5477
GB
1#!./perl
2
f4a2945e 3BEGIN {
1bfb5477 4 unless (-d 'blib') {
f4a2945e
JH
5 chdir 't' if -d 't';
6 @INC = '../lib';
6b05f64e 7 require Config; import Config;
1bfb5477 8 keys %Config; # Silence warning
6b05f64e
PP
9 if ($Config{extensions} !~ /\bList\/Util\b/) {
10 print "1..0 # Skip: List::Util was not built\n";
11 exit 0;
12 }
1bfb5477 13 }
f4a2945e
JH
14}
15
cf083cf9
GB
16use strict;
17use Test::More tests => 5;
f4a2945e
JH
18use List::Util qw(max);
19
cf083cf9 20my $v;
f4a2945e 21
cf083cf9 22ok(defined &max, 'defined');
f4a2945e 23
cf083cf9
GB
24$v = max(1);
25is($v, 1, 'single arg');
f4a2945e 26
cf083cf9
GB
27$v = max (1,2);
28is($v, 2, '2-arg ordered');
f4a2945e 29
cf083cf9
GB
30$v = max(2,1);
31is($v, 2, '2-arg reverse ordered');
f4a2945e
JH
32
33my @a = map { rand() } 1 .. 20;
34my @b = sort { $a <=> $b } @a;
cf083cf9
GB
35$v = max(@a);
36is($v, $b[-1], '20-arg random order');