X-Git-Url: http://git.shiar.net/perl/list-index.git/blobdiff_plain/97973476dd225680059f6b58a12cef3ef950ffde..HEAD:/t/10-ranges.t diff --git a/t/10-ranges.t b/t/10-ranges.t index a394945..9befbb6 100644 --- a/t/10-ranges.t +++ b/t/10-ranges.t @@ -2,14 +2,21 @@ use strict; use warnings; -use Test::More tests => 9; +use Test::More tests => 10; use Test::NoWarnings; use Data::Dump 'pp'; BEGIN { use_ok('List::Index'); } ok(eval { List::Index->VERSION(1) }, 'version 1.00 compatibility'); -subtest 'single-char alphabet' => sub { +eval { Test::More->VERSION(0.93) } or eval q{ + diag "Install Test::More v0.93 to run subtests\n"; + sub subtest { + SKIP: { skip 'subtest', 1; } + } +}; + +subtest('single-char alphabet' => sub { plan tests => 5; my @data = ('a'..'z'); @@ -30,9 +37,9 @@ subtest 'single-char alphabet' => sub { ['-a', 'b'..'y', 'z-'], 'max pages' ); -}; +}); -subtest 'uniform alphanumeric' => sub { +subtest('uniform alphanumeric' => sub { plan tests => 2; my @data = ('aa'..'zz', 1..202); my $index = List::Index->new or return; @@ -40,8 +47,8 @@ subtest 'uniform alphanumeric' => sub { is_deeply( $index->ranges(\@data), [qw( - -. - .-bp bq-dm dn-fi fj-hf hg-i j-k l-m n-os ot-qp qq-sm sn-uj uk-wf wg-x y- + -.. ..-... + ...-bp bq-dm dn-fi fj-hf hg-i j-k l-m n-os ot-qp qq-sm sn-uj uk-wf wg-x y- )], 'default ranges' ); @@ -50,14 +57,14 @@ subtest 'uniform alphanumeric' => sub { [qw(-c d-n o-)], 'large pagesize' ); -}; +}); -subtest 'context' => sub { +subtest('context' => sub { plan tests => 9; my @data = qw( kkeg kl km kmlu knsy koxb kpeo kuaa kuab kuac kuapa kuq kur kux kzb lc lg lgu lgua lguc - lguq lgur lgws lgx lka lkq lks lln llq llx + lguq lgur lgus lgx lka lkq lks lln llq llx ); my $index = List::Index->new({ pagesize => 10 }) or return; @@ -80,15 +87,12 @@ subtest 'context' => sub { [qw(-kup kuq-lgup lguq-)], 'lookahead' ); -TODO: { - local $TODO = 'backtrack'; is_deeply( $index->ranges(\@data, { context => 2 }), # allowed to advance to 'kur', but provides no benefits over 'kuq' [qw(-kup kuq-lgup lguq-)], 'minimal lookahead' ); -} is_deeply( $index->ranges(\@data, { context => 3 }), # shorten 'kuap' to 'ku' because lookbehind is 'kp...' @@ -121,9 +125,9 @@ TODO: { [qw(-k l-)], 'full overlap' ); -}; +}); -subtest 'distribution' => sub { +subtest('distribution' => sub { plan tests => 2; my @data = qw( gnihka gniub go gsearnrqns gtdvcxyt gw gwoufolwcvmtueyg gysgphci h habkdgifjfxoh @@ -147,30 +151,38 @@ subtest 'distribution' => sub { # page #14 [gn-g] (8): gnihka gniub go gsearnrqns gtdvcxyt gwawkvmueovdjtfj gwoufolwcvmtueyg gysgphci # page #15 [h] (17): h habkdgifjfxoh hbbvjf hbqleexnqts hccgszftbaymfu hdaqzkow hdoeqwdmgqwaoya hfbegicieu hfmlpzzioqjbthz hj hkoysmws hmylu hnvtvpievbdlkrmb hsodfpkatk hvdvcqn hvn hyrybeurqtevjfmi # page #16 [i-ie] (5): i iaab ibiavqyar idfniqvxpohbk idh -}; +}); -subtest 'modulo' => sub { +subtest('modulo' => sub { plan tests => 2; - my @data = qw( a b ccb ccd cce gf gg gh i j ); + my @data = qw( a b ccb ccd cce gf ggg ggh i j ); my $index = List::Index->new({ pagesize => 4, context => 0 }) or return; # 10 entries at 4 per page requires 3 pages # so actual target page sizes should be 3,4,3 (not 4,4,2) is_deeply( $index->ranges(\@data), - [qw(-ccc ccd-gg gh-)], + [qw(-ccc ccd-ggg ggh-)], 'uniform page sizes' ); -{ local $TODO = 'early lookbehind causing [c-gg]'; is_deeply( $index->ranges(\@data, { context => 1 }), - [qw(-b c-h i-)], + [qw(-b c-gf gg-)], 'context at new intervals' ); -} -}; +}); -subtest 'context' => sub { +subtest('corner cases' => sub { + plan tests => 1; + + is_deeply( + List::Index->new->ranges(['foo','bar']), + ['-'], + '2 rows 1 page' + ); +}); + +subtest('context' => sub { plan tests => 4; my @data = qw( baa1 baa2 baa3 baaa bbc cbc daaa ea eaaa zed ); my $index = List::Index->new({ pagesize => 2 }) or return; @@ -182,13 +194,13 @@ subtest 'context' => sub { ); is_deeply( $index->ranges(\@data, { context => undef }), - [qw(-a b c d e-)], #TODO + [qw(-baa. baa.-b c d e-)], 'default context' # context should be 1 ); is_deeply( $index->ranges(\@data, { context => 2 }), # first item equals second due to large context - [qw(-a b-c d e-)], + [qw(-ba bb-b c d e-)], 'overlap' ); is_deeply( @@ -198,5 +210,5 @@ subtest 'context' => sub { ); #pp(List::Index->new({pagesize => 2, context => 2, length => 1}))->ranges(\@data); -}; +});