X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=t%2F40-vshift.t;h=b45ffc1ac4bd344991889db01ac1c02ab1f40530;hb=2bade59206c8f2bd2ed64e1faa8b10cc9109b734;hp=39e14d54e280c2f6ad046b41bd21ab14efb2a596;hpb=0062dbd2da53db62346382e729b84097131c61ee;p=perl%2Fmodules%2FScalar-Vec-Util.git diff --git a/t/40-vshift.t b/t/40-vshift.t index 39e14d5..b45ffc1 100644 --- a/t/40-vshift.t +++ b/t/40-vshift.t @@ -3,27 +3,60 @@ use strict; use warnings; -use Test::More 'no_plan'; +use lib 't/lib'; +use Test::Leaner 'no_plan'; -use Scalar::Vec::Util qw/vshift SVU_SIZE/; +use Scalar::Vec::Util qw; + +BEGIN { + *myfill = *Scalar::Vec::Util::vfill_pp; + *myeq = *Scalar::Vec::Util::veq_pp; +} + +for ([ 1, 'offset', -1 ], [ 2, 'length', '-1' ]) { + my @args = ('1') x 4; + $args[$_->[0]] = $_->[2]; + local $@; + eval { &vshift(@args) }; + my $err = $@; + my $line = __LINE__-2; + like $err, qr/^Invalid\s+negative\s+$_->[1]\s+at\s+\Q$0\E\s+line\s+$line/, + "vshift(@args) failed"; +} my $p = SVU_SIZE; -$p = 8 if $p < 8; +$p = 8 if $p < 8; my $n = 3 * $p; my $q = 2; -*myfill = *Scalar::Vec::Util::vfill_pp; -*myeq = *Scalar::Vec::Util::veq_pp; - -sub rst { myfill($_[0], 0, $n, 0); $_[0] = '' } +sub rst { + myfill $_[0], 0, $n, 0; + $_[0] = ''; +} sub pat { - (undef, my $a, my $b, my $x) = @_; + my (undef, $a, $b, $x) = @_; $_[0] = ''; $x = $x ? 1 : 0; if (defined $b) { - myfill($_[0], 0, $a, $x); - myfill($_[0], $a, $b, 1 - $x); + myfill $_[0], 0, $a, $x; + myfill $_[0], $a, $b, 1 - $x; + } +} + +sub expect { + my (undef, $s, $l, $b, $left, $insert) = @_; + myfill $_[0], 0, $s, 0; + if ($b < $l) { + if ($left) { + myfill $_[0], $s, $b, defined $insert ? $insert : 1; + myfill $_[0], $s + $b, $l - $b, 1; + } else { + myfill $_[0], $s, $l - $b, 1; + myfill $_[0], $s + $l - $b, $b, defined $insert ? $insert : 1; + } + } else { + myfill $_[0], $s, $l, defined $insert ? $insert : 1; } } @@ -35,27 +68,21 @@ sub try { for my $s (@s) { for my $l (0 .. $n - 1) { last if $s + $l > $n; + rst $v0; pat $v0, $s, $l, 0; my @b = (0); my $l2 = int($l/2); push @b, $l2 if $l2 != $l; - push @b, $l if $l; + push @b, $l + 1; for my $b (@b) { + my $desc = "vshift $s, $l, $b, " . (defined $insert ? $insert : 'undef'); $v = $v0; - $c = ''; - myfill($c, 0, $s, 0); - if ($left) { - myfill($c, $s, $b, defined $insert ? $insert : 1); - myfill($c, $s + $b, $l - $b, 1); - } else { - myfill($c, $s, $l - $b, 1); - myfill($c, $s + $l - $b, $b, defined $insert ? $insert : 1); - } + rst $c; + expect $c, $s, $l, $b, $left, $insert; $b = -$b unless $left; vshift $v, $s, $l => $b, $insert; - my $i = defined $insert ? $insert : 'undef'; - ok(myeq($v, 0, $c, 0, $n), "vshift $s, $l, $b, $i"); - is(length $v, length $c, "vshift $s, $l, $b, $i length"); + is length $v, length $c, "$desc: length"; + ok myeq($v, 0, $c, 0, $n), "$desc: bits"; } } }