fix pagesize comparison on random test
authorMischa POSLAWSKY <perl@shiar.org>
Mon, 16 Nov 2009 02:47:46 +0000 (03:47 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Mon, 16 Nov 2009 02:47:46 +0000 (03:47 +0100)
t/25-apply.t

index c06ae0645e2141ea075ac9eda26552936aa00b2a..eadc285540ae2befa0290b48ab51c75ed284191b 100644 (file)
@@ -7,19 +7,21 @@ use Test::NoWarnings;
 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;
        }
@@ -61,13 +63,13 @@ BEGIN { use_ok('List::Index' => 'rangematch'); }
        }
 
        # 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);