X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2Fautovivification.git;a=blobdiff_plain;f=t%2F44-multideref.t;h=85f3c1cfcff839bbea6bf9d4e2703ad34fb2bd2e;hp=b19b8ce1af8b338fe7150f8217a97c83bb3b5b7c;hb=9d5da0550c8d76bd95070e317ab931fc86b2b8c7;hpb=f272f375c8bc23ea4a0ba73742bb878af622b9a6 diff --git a/t/44-multideref.t b/t/44-multideref.t index b19b8ce..85f3c1c 100644 --- a/t/44-multideref.t +++ b/t/44-multideref.t @@ -54,11 +54,30 @@ sub reset_vars { sub new { my $class = shift; + my (@lists, @max); + for my $arg (@_) { + next unless defined $arg; + my $type = ref $arg; + my $list; + if ($type eq 'ARRAY') { + $list = $arg; + } elsif ($type eq '') { + $list = [ 1 .. $arg ]; + } else { + die "Invalid argument of type $type"; + } + my $max = @$list; + die "Empty list" unless $max; + push @lists, $list; + push @max, $max; + } + my $len = @_; bless { - len => $len, - max => \@_, - idx => [ (0) x $len ], + len => $len, + max => \@max, + lists => \@lists, + idx => [ (0) x $len ], }, $class; } @@ -81,19 +100,20 @@ sub reset_vars { return $i < $len; } - sub pick { + sub items { my $self = shift; - my ($len, $idx) = @$self{qw}; + my ($len, $lists, $idx) = @$self{qw}; - return map $_[$_]->[$idx->[$_]], 0 .. ($len - 1); + return map $lists->[$_]->[$idx->[$_]], 0 .. ($len - 1); } } -my $iterator = autovivification::TestIterator->new(4, 4, (8) x $depth); +my $iterator = autovivification::TestIterator->new( + \@prefixes, \@heads, (\@derefs) x $depth, +); do { - my ($prefix, @elems) - = $iterator->pick(\@prefixes, \@heads, (\@derefs) x $depth); + my ($prefix, @elems) = $iterator->items; my $code = $prefix->(join '', @elems); my $exp = ($code =~ /^\s*exists/) ? !1 : (($code =~ /=\s*$magic_val/) ? $magic_val