diff -Nuar List-MoreUtils-0.22/MoreUtils.xs List-MoreUtils-0.22-minmax-fix/MoreUtils.xs
--- List-MoreUtils-0.22/MoreUtils.xs 2006-07-02 10:25:16.000000000 -0500
+++ List-MoreUtils-0.22-minmax-fix/MoreUtils.xs 2009-01-15 10:13:29.000000000 -0600
@@ -1204,6 +1204,14 @@
minsv = maxsv = ST(0);
min = max = slu_sv_value(minsv);
+ if (items == 1) {
+ EXTEND(SP, 1);
+ ST(0) = minsv;
+ ST(1) = maxsv;
+
+ XSRETURN(2);
+ }
+
for (i = 1; i < items; i += 2) {
asv = ST(i-1);
bsv = ST(i);
diff -Nuar List-MoreUtils-0.22/lib/List/MoreUtils.pm List-MoreUtils-0.22-minmax-fix/lib/List/MoreUtils.pm
--- List-MoreUtils-0.22/lib/List/MoreUtils.pm 2006-07-02 10:26:35.000000000 -0500
+++ List-MoreUtils-0.22-minmax-fix/lib/List/MoreUtils.pm 2009-01-14 15:49:00.000000000 -0600
@@ -287,6 +287,8 @@
return if ! @_;
my $min = my $max = $_[0];
+ return ($min, $max) if @_ == 1;
+
for (my $i = 1; $i < @_; $i += 2) {
if ($_[$i-1] <= $_[$i]) {
$min = $_[$i-1] if $min > $_[$i-1];
diff -Nuar List-MoreUtils-0.22/t/List-MoreUtils-pp.t List-MoreUtils-0.22-minmax-fix/t/List-MoreUtils-pp.t
--- List-MoreUtils-0.22/t/List-MoreUtils-pp.t 2006-07-02 10:12:05.000000000 -0500
+++ List-MoreUtils-0.22-minmax-fix/t/List-MoreUtils-pp.t 2009-01-15 10:44:02.000000000 -0600
@@ -458,7 +458,7 @@
}
#minmax(104...)
-BEGIN { $TESTS += 6 }
+BEGIN { $TESTS += 14 }
{
my @list = reverse 0 .. 100_000;
my ($min, $max) = minmax @list;
@@ -477,9 +477,23 @@
# floating-point comparison cunningly avoided
ok(sprintf("%i", $min), -3);
ok($max, 100_000);
+
+ # single item
+ for (9, 0, 1) {
+ @list = ($_);
+ ($min, $max) = minmax(@list);
+ ok($min, $_);
+ ok($max, $_);
+ }
+
+ # no items
+ @list = ();
+ ($min, $max) = minmax(@list);
+ ok(!defined $min);
+ ok(!defined $max);
}
-#part(110...)
+#part(118...)
BEGIN { $TESTS += 14 }
{
my @list = 1 .. 12;
diff -Nuar List-MoreUtils-0.22/t/List-MoreUtils.t List-MoreUtils-0.22-minmax-fix/t/List-MoreUtils.t
--- List-MoreUtils-0.22/t/List-MoreUtils.t 2006-07-02 10:12:05.000000000 -0500
+++ List-MoreUtils-0.22-minmax-fix/t/List-MoreUtils.t 2009-01-15 10:44:20.000000000 -0600
@@ -228,7 +228,7 @@
ok(!@x);
}
-#lastval/last_value (67...)
+#lastval/last_value (66...)
BEGIN { $TESTS += 4 }
{
my $x = last_value {$_ > 5} 4..9;
@@ -242,7 +242,7 @@
ok(!defined $x);
}
-#firstval/first_value (71...)
+#firstval/first_value (70...)
BEGIN { $TESTS += 4 }
{
my $x = first_value {$_ > 5} 4..9;
@@ -257,7 +257,7 @@
}
-#each_array (75...)
+#each_array (74...)
BEGIN { $TESTS += 10 }
{
my @a = (7, 3, 'a', undef, 'r');
@@ -313,7 +313,7 @@
ok(arrayeq(\@b, ['A' .. 'Z']));
}
-#each_array (85...)
+#each_array (84...)
BEGIN { $TESTS += 5 }
{
my @a = (7, 3, 'a', undef, 'r');
@@ -349,7 +349,7 @@
}
-#pairwise (90...)
+#pairwise (89...)
BEGIN { $TESTS += 10 }
{
my @a = (1, 2, 3, 4, 5);
@@ -416,7 +416,7 @@
ok($@, "I died\n");
}
-#natatime (100...)
+#natatime (99...)
BEGIN { $TESTS += 3 }
{
my @x = ('a'..'g');
@@ -445,7 +445,7 @@
ok(arrayeq(\@r, [1 .. 26]), 1, "natatime3");
}
-#mesh (103...)
+#mesh (102...)
BEGIN { $TESTS += 3 }
{
my @x = qw/a b c d/;
@@ -466,7 +466,7 @@
6, undef, 7, undef, 8, undef, 9, undef, 10, undef]));
}
-#zip (just an alias for mesh) (106...)
+#zip (just an alias for mesh) (105...)
BEGIN { $TESTS += 3 }
{
my @x = qw/a b c d/;
@@ -487,7 +487,7 @@
6, undef, 7, undef, 8, undef, 9, undef, 10, undef]));
}
-#uniq (109...)
+#uniq (108...)
BEGIN { $TESTS += 2 }
{
my @a = map { (1 .. 10000) } 0 .. 1;
@@ -497,8 +497,8 @@
ok(10000, $u);
}
-#minmax (111...)
-BEGIN { $TESTS += 6 }
+#minmax (110...)
+BEGIN { $TESTS += 14 }
{
my @list = reverse 0 .. 100_000;
my ($min, $max) = minmax(@list);
@@ -517,9 +517,25 @@
# floating-point comparison cunningly avoided
ok(sprintf("%.2f", $min), "-3.33");
ok($max, 100_000);
+
+ # used to return old stack items for min/max
+ # done multiple times so old stack problem appears
+ # see: CPAN RT 39847
+ for (9, 0, 1) {
+ @list = ($_);
+ ($min, $max) = minmax(@list);
+ ok($min, $_);
+ ok($max, $_);
+ }
+
+ # no items
+ @list = ();
+ ($min, $max) = minmax(@list);
+ ok(!defined $min);
+ ok(!defined $max);
}
-#part (116...)
+#part (124...)
BEGIN { $TESTS += 24 }
{
my @list = 1 .. 12;