sort.t revision 7c478bd95313f5f23a4c958a745db2134aa03244
#!./perl
# This tests the behavior of sort() under the different 'use sort' forms.
# Algorithm by John P. Linderman.
my ($BigWidth, $BigEnough, $RootWidth, $ItemFormat, @TestSizes, $WellSoaked);
BEGIN {
chdir 't' if -d 't';
$BigWidth = 6; # Digits in $BigEnough-1
$BigEnough = 10**$BigWidth; # Largest array we'll attempt
# Testing all the way up to $BigEnough takes too long
# for casual testing. There are some cutoffs (~256)
# in pp_sort that should be tested, but 10_000 is ample.
$WellSoaked = 10_000; # <= $BigEnough
}
}
use strict;
use warnings;
* 4 # number of pragmas to test
+ 1 # extra test for qsort instability
+ 3 # tests for sort::current
+ 3; # tests for "defaults" and "no sort"
# Generate array of specified size for testing sort.
#
# We ensure repeated items, where possible, by drawing the $size items
# from a pool of size sqrt($size). Each randomly chosen item is
# tagged with the item index, so we can detect original input order,
# and reconstruct the original array order.
sub genarray {
my @a;
$#a = $size - 1; # preallocate array
}
return \@a;
}
# Check for correct order (including stability)
sub checkorder {
my $aref = shift;
# Equality shouldn't happen, but catch it in the contents check
"Instability" : "Disorder";
# Keep checking if merely unstable... disorder is much worse.
$status =
}
return $status;
}
# Verify that the two array refs reference identical arrays
sub checkequal {
my $i;
} else {
last;
}
}
return $status;
}
# Test sort on arrays of various sizes (set up in @TestSizes)
sub main {
my $unstable_num = 0;
# Sort only on item portion of each element.
# There will typically be many repeated items,
# and their order had better be preserved.
# Put the items back into the original order.
# The contents of the arrays had better be identical.
}
}
# If the following test (#58) fails, see the comments in pp_sort.c
# for Perl_sortsv().
}
}
# Test with no pragma still loaded -- stability expected (this is a mergesort)
# XXX We're using this eval "..." trick to force recompilation,
# to ensure that the correct pragma is enabled when main() is run.
# Currently 'use sort' modifies $sort::hints at compile-time, but
# pp_sort() fetches its value at run-time.
# The order of those evals is important.
eval q{
};
die $@ if $@;
eval q{
};
die $@ if $@;
eval q{
};
die $@ if $@;
# Tests added to check "defaults" subpragma, and "no sort"
eval q{
};
die $@ if $@;
eval q{
};
die $@ if $@;
eval q{
};
die $@ if $@;