use Data::Dump 'pp';
use List::Util qw(first min max);
use List::MoreUtils qw(uniq firstidx);
+use POSIX qw(ceil);
BEGIN { use_ok('List::Index' => 'rangematch'); }
{
- my %options = (pagesize => 10, context => 2);
+ my $rows = rand(100) ** 2;
+ my %options = (pagesize => 50, context => 4, length => 4);
# generate random test data
my @values;
- for (0 .. rand 1000) {
+ for (0 .. $rows) {
my $string = join '', map {
# random character (a-z or random digit)
chr((int rand(27) || rand(10)-ord('0')*0) + ord('a')-1)
- } 0 .. rand(16);
+ } 0 .. rand($options{length});
push @values, $string
unless @values and $values[-1] eq $string;
}
}
# analyse final page sizes
- if (my $limit = $options{pagesize} + $options{context}) {
+ my $pagesize = scalar(@values) / scalar(@matches);
+ if (my $limit = ceil($pagesize) + $options{context}) {
my $largest = max(map { scalar @$_ } @matches);
cmp_ok($largest, '<=', $limit, "page sizes under $limit")
or pagecontext($largest);
}
-# pop @matches;
- if (my $limit = $options{pagesize} - $options{context}) {
+ if (my $limit = int($pagesize) - $options{context}) {
my $smallest = min(map {scalar @$_} @matches);
cmp_ok($smallest, '>=', $limit, "page sizes over $limit")
or pagecontext($smallest);