From: Vincent Pit Date: Mon, 24 Sep 2012 20:38:19 +0000 (+0200) Subject: Restyle tests X-Git-Tag: v0.07~5 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=2bade59206c8f2bd2ed64e1faa8b10cc9109b734;p=perl%2Fmodules%2FScalar-Vec-Util.git Restyle tests --- diff --git a/t/02-pp.t b/t/02-pp.t index 0e41842..35e3d85 100644 --- a/t/02-pp.t +++ b/t/02-pp.t @@ -19,8 +19,8 @@ BEGIN { use Scalar::Vec::Util qw; -is(SVU_PP, 1, 'using pure perl subroutines'); +is SVU_PP, 1, 'using pure perl subroutines'; for (qw) { no strict 'refs'; - is(*{$_}{CODE}, *{'Scalar::Vec::Util::'.$_}{CODE}, $_ .' is ' . $_ . '_pp'); + is *{$_}{CODE}, *{'Scalar::Vec::Util::'.$_}{CODE}, $_ .' is ' . $_ . '_pp'; } diff --git a/t/03-size.t b/t/03-size.t index d32e3d9..d8953b2 100644 --- a/t/03-size.t +++ b/t/03-size.t @@ -10,14 +10,14 @@ use Scalar::Vec::Util qw; if (SVU_PP) { plan tests => 1; - diag('Using pure perl fallbacks'); + diag 'Using pure perl fallbacks'; - is(SVU_SIZE, 1, 'SVU_SIZE is 1'); + is SVU_SIZE, 1, 'SVU_SIZE is 1'; } else { plan tests => 2; - diag('Using an unit of ' . SVU_SIZE . ' bits'); + diag 'Using an unit of ' . SVU_SIZE . ' bits'; - ok(SVU_SIZE >= 8, 'SVU_SIZE is greater than 8'); - is(SVU_SIZE % 8, 0, 'SVU_SIZE is a multiple of 8'); + cmp_ok SVU_SIZE, '>=', 8, 'SVU_SIZE is greater than 8'; + is SVU_SIZE % 8, 0, 'SVU_SIZE is a multiple of 8'; } diff --git a/t/10-veq-pp.t b/t/10-veq-pp.t index 509fd98..78092cc 100644 --- a/t/10-veq-pp.t +++ b/t/10-veq-pp.t @@ -10,8 +10,12 @@ use Scalar::Vec::Util; for ([ 1, 'offset', -1 ], [ 3, 'offset', '-1' ], [ 4, 'length', -1 ]) { my @args = ('1') x 5; $args[$_->[0]] = $_->[2]; - eval { &Scalar::Vec::Util::veq_pp(@args) }; my $line = __LINE__; - like $@, qr/^Invalid\s+negative\s+$_->[1]\s+at\s+\Q$0\E\s+line\s+$line/; + local $@; + eval { &Scalar::Vec::Util::veq_pp(@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/, + "veq_pp(@args) failed"; } my $p = 8; @@ -19,19 +23,21 @@ my $n = 3 * $p; my $q = 1; sub myfill { - (undef, my $s, my $l, my $x) = @_; + my (undef, $s, $l, $x) = @_; $x = 1 if $x; vec($_[0], $_, 1) = $x for $s .. $s + $l - 1; } -sub rst { myfill($_[0], 0, $n, 0) } - +sub rst { + myfill $_[0], 0, $n, 0; +} + sub pat { - (undef, my $a, my $b, my $x) = @_; - myfill($_[0], 0, $a, $x); - myfill($_[0], $a, $b, 1 - $x); - myfill($_[0], $a + $b, $n - ($a + $b) , $x); -} + my (undef, $a, $b, $x) = @_; + myfill $_[0], 0, $a, $x; + myfill $_[0], $a, $b, 1 - $x; + myfill $_[0], $a + $b, $n - ($a + $b), $x; +} my ($v1, $v2) = ('') x 2; @@ -42,9 +48,14 @@ for my $s1 (@s) { last if $s1 + $l > $n or $s2 + $l > $n; pat $v1, $s1, $l, 0; pat $v2, $s2, $l, 0; - ok(Scalar::Vec::Util::veq_pp($v1 => $s1, $v2 => $s2, $l), "veq_pp $s1, $s2, $l"); - ok(!Scalar::Vec::Util::veq_pp($v1 => $s1 - 1, $v2 => $s2, $l), 'not veq_pp ' . ($s1 - 1) . ", $s2, $l") if $l > 0; - ok(!Scalar::Vec::Util::veq_pp($v1 => $s1 + 1, $v2 => $s2, $l), 'not veq_pp ' . ($s1 + 1) . ", $s2, $l") if $l > 0; + ok Scalar::Vec::Util::veq_pp($v1 => $s1, $v2 => $s2, $l), + "veq_pp $s1, $s2, $l"; + if ($l > 0) { + ok !Scalar::Vec::Util::veq_pp($v1 => $s1 - 1, $v2 => $s2, $l), + 'not veq_pp ' . ($s1-1) . ", $s2, $l"; + ok !Scalar::Vec::Util::veq_pp($v1 => $s1 + 1, $v2 => $s2, $l), + 'not veq_pp ' . ($s1+1) . ", $s2, $l"; + } } } } diff --git a/t/11-veq.t b/t/11-veq.t index 00e90a9..924bc12 100644 --- a/t/11-veq.t +++ b/t/11-veq.t @@ -10,29 +10,35 @@ use Scalar::Vec::Util qw; for ([ 1, 'offset', -1 ], [ 3, 'offset', '-1' ], [ 4, 'length', -1 ]) { my @args = ('1') x 5; $args[$_->[0]] = $_->[2]; - eval { &veq(@args) }; my $line = __LINE__; - like $@, qr/^Invalid\s+negative\s+$_->[1]\s+at\s+\Q$0\E\s+line\s+$line/; + local $@; + eval { &veq(@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/, + "veq(@args) failed"; } my $p = SVU_SIZE; -$p = 8 if $p < 8; +$p = 8 if $p < 8; my $n = 3 * $p; my $q = 1; sub myfill { - (undef, my $s, my $l, my $x) = @_; + my (undef, $s, $l, $x) = @_; $x = 1 if $x; vec($_[0], $_, 1) = $x for $s .. $s + $l - 1; } -sub rst { myfill($_[0], 0, $n, 0) } - +sub rst { + myfill $_[0], 0, $n, 0; +} + sub pat { - (undef, my $a, my $b, my $x) = @_; - myfill($_[0], 0, $a, $x); - myfill($_[0], $a, $b, 1 - $x); - myfill($_[0], $a + $b, $n - ($a + $b) , $x); -} + my (undef, $a, $b, $x) = @_; + myfill $_[0], 0, $a, $x; + myfill $_[0], $a, $b, 1 - $x; + myfill $_[0], $a + $b, $n - ($a + $b), $x; +} my ($v1, $v2) = ('') x 2; @@ -43,9 +49,11 @@ for my $s1 (@s) { last if $s1 + $l > $n or $s2 + $l > $n; pat $v1, $s1, $l, 0; pat $v2, $s2, $l, 0; - ok(veq($v1 => $s1, $v2 => $s2, $l), "veq $s1, $s2, $l"); - ok(!veq($v1 => $s1 - 1, $v2 => $s2, $l), 'not veq ' . ($s1 - 1) . ", $s2, $l") if $l > 0; - ok(!veq($v1 => $s1 + 1, $v2 => $s2, $l), 'not veq ' . ($s1 + 1) . ", $s2, $l") if $l > 0; + ok veq($v1 => $s1, $v2 => $s2, $l), "veq $s1, $s2, $l"; + if ($l > 0) { + ok !veq($v1 => $s1 - 1, $v2 => $s2, $l), 'not veq ' . ($s1-1) . ", $s2, $l"; + ok !veq($v1 => $s1 + 1, $v2 => $s2, $l), 'not veq ' . ($s1+1) . ", $s2, $l"; + } } } } diff --git a/t/12-veq-long.t b/t/12-veq-long.t index ea0c7a0..aa1faa0 100644 --- a/t/12-veq-long.t +++ b/t/12-veq-long.t @@ -18,4 +18,4 @@ while ($i >= 1) { vec($v2, $i + 1, 1) = 1; $i /= 2; } -ok(veq($v1, 0, $v2, 1, 10 * $n), 'long veq is loooong'); +ok veq($v1, 0, $v2, 1, 10 * $n), 'long veq is loooong'; diff --git a/t/20-vfill-pp.t b/t/20-vfill-pp.t index 3bb893d..2d9e00e 100644 --- a/t/20-vfill-pp.t +++ b/t/20-vfill-pp.t @@ -7,11 +7,19 @@ use Test::More 'no_plan'; use Scalar::Vec::Util; +BEGIN { + *myeq = *Scalar::Vec::Util::veq_pp; +} + for ([ 1, 'offset', -1 ], [ 2, 'length', '-1' ]) { my @args = ('1') x 4; $args[$_->[0]] = $_->[2]; - eval { &Scalar::Vec::Util::vfill_pp(@args) }; my $line = __LINE__; - like $@, qr/^Invalid\s+negative\s+$_->[1]\s+at\s+\Q$0\E\s+line\s+$line/; + local $@; + eval { &Scalar::Vec::Util::vfill_pp(@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/, + "vfill_pp(@args) failed"; } my $p = 8; @@ -19,14 +27,15 @@ my $n = 3 * $p; my $q = 1; sub myfill { - (undef, my $s, my $l, my $x) = @_; + my (undef, $s, $l, $x) = @_; $x = 1 if $x; vec($_[0], $_, 1) = $x for $s .. $s + $l - 1; } -*myeq = *Scalar::Vec::Util::veq_pp; - -sub rst { myfill($_[0], 0, $n, 0); $_[0] = '' } +sub rst { + myfill $_[0], 0, $n, 0; + $_[0] = ''; +} my ($v, $c) = ('') x 2; @@ -34,13 +43,14 @@ my @s = ($p - $q) .. ($p + $q); for my $s (@s) { for my $l (0 .. $n - 1) { next if $s + $l > $n; + my $desc = "vfill_pp $s, $l"; rst $c; - myfill($c, 0, $s, 0); - myfill($c, $s, $l, 1); + myfill $c, 0, $s, 0; + myfill $c, $s, $l, 1; rst $v; Scalar::Vec::Util::vfill_pp($v, 0, $s, 0); Scalar::Vec::Util::vfill_pp($v, $s, $l, 1); - ok(myeq($v, 0, $c, 0, $n), "vfill_pp $s, $l"); - is(length $v, length $c, "vfill_pp $s, $l length"); + is length $v, length $c, "$desc: length"; + ok myeq($v, 0, $c, 0, $n), "$desc: bits"; } } diff --git a/t/21-vfill.t b/t/21-vfill.t index 8403174..3b6a27a 100644 --- a/t/21-vfill.t +++ b/t/21-vfill.t @@ -7,29 +7,38 @@ use Test::More 'no_plan'; 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 = (~0) x 4; $args[$_->[0]] = $_->[2]; - eval { &vfill(@args) }; my $line = __LINE__; - like $@, qr/^Invalid\s+negative\s+$_->[1]\s+at\s+\Q$0\E\s+line\s+$line/; + local $@; + eval { &vfill(@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/, + "vfill(@args) failed"; } my $p = SVU_SIZE; -$p = 8 if $p < 8; +$p = 8 if $p < 8; my $n = 3 * $p; my $q = 1; -*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] = ''; if ($b) { - myfill($_[0], 0, $a, $x); - myfill($_[0], $a, $b, 1 - $x); + myfill $_[0], 0, $a, $x; + myfill $_[0], $a, $b, 1 - $x; } } @@ -39,10 +48,11 @@ my @s = ($p - $q) .. ($p + $q); for my $s (@s) { for my $l (0 .. $n - 1) { next if $s + $l > $n; + my $desc = "vfill $s, $l"; pat $c, $s, $l, 0; rst $v; vfill $v, $s, $l, 1; - ok(myeq($v, 0, $c, 0, $n), "vfill $s, $l"); - is(length $v, length $c, "length is ok"); + is length $v, length $c, "$desc: length"; + ok myeq($v, 0, $c, 0, $n), "$desc: bits"; } } diff --git a/t/22-vfill-long.t b/t/22-vfill-long.t index 3325f2d..81d0041 100644 --- a/t/22-vfill-long.t +++ b/t/22-vfill-long.t @@ -7,18 +7,21 @@ use Test::More tests => 34; use Scalar::Vec::Util qw; -my $n = 2 ** 16; +BEGIN { + *myfill = *Scalar::Vec::Util::vfill_pp; + *myeq = *Scalar::Vec::Util::veq_pp; +} -*myfill = *Scalar::Vec::Util::vfill_pp; -*myeq = *Scalar::Vec::Util::veq_pp; +my $n = 2 ** 16; my ($v, $c) = ('') x 2; my $l = 1; while ($l <= $n) { - myfill($c, 0, $l, 1); - vfill($v, 0, $l, 1); - ok(myeq($v, 0, $c, 0, $l), "vfill 0, $l, 1"); - is(length $v, length $c, "length is ok"); + my $desc = "vfill 0, $l, 1"; + myfill $c, 0, $l, 1; + vfill $v, 0, $l, 1; + is length $v, length $c, "$desc: length"; + ok myeq($v, 0, $c, 0, $l), "$desc: bits"; $l *= 2; } diff --git a/t/30-vcopy-pp.t b/t/30-vcopy-pp.t index fda3803..911b5a1 100644 --- a/t/30-vcopy-pp.t +++ b/t/30-vcopy-pp.t @@ -8,28 +8,36 @@ use Test::Leaner 'no_plan'; use Scalar::Vec::Util qw; +BEGIN { + *myfill = *Scalar::Vec::Util::vfill_pp; +} + for ([ 1, 'offset', -1 ], [ 3, 'offset', '-1' ], [ 4, 'length', -1 ]) { my @args = ('1') x 5; $args[$_->[0]] = $_->[2]; - eval { &Scalar::Vec::Util::vcopy_pp(@args) }; my $line = __LINE__; - like $@, qr/^Invalid\s+negative\s+$_->[1]\s+at\s+\Q$0\E\s+line\s+$line/; + local $@; + eval { &Scalar::Vec::Util::vcopy_pp(@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/, + "vcopy_pp(@args) failed"; } my $p = SVU_SIZE; -$p = 8 if $p < 8; +$p = 8 if $p < 8; my $n = 3 * $p; my $q = 1; -*myfill = *Scalar::Vec::Util::vfill_pp; +sub rst { + myfill $_[0], 0, $n, 0; +} -sub rst { myfill($_[0], 0, $n, 0) } - sub pat { - (undef, my $a, my $b, my $x) = @_; - myfill($_[0], 0, $a, $x); - myfill($_[0], $a, $b, 1 - $x); - myfill($_[0], $a + $b, $n - ($a + $b) , $x); -} + my (undef, $a, $b, $x) = @_; + myfill $_[0], 0, $a, $x; + myfill $_[0], $a, $b, 1 - $x; + myfill $_[0], $a + $b, $n - ($a + $b), $x; +} my ($f, $t, $c) = ('') x 3; @@ -38,11 +46,12 @@ for my $s1 (@s) { for my $s2 (@s) { for my $l (0 .. $n - 1) { last if $s1 + $l > $n or $s2 + $l > $n; + my $desc = "vcopy_pp $s1, $s2, $l"; pat $f, $s1, $l, 0; rst $t; pat $c, $s2, $l, 0; Scalar::Vec::Util::vcopy_pp($f => $s1, $t => $s2, $l); - is($t, $c, "vcopy_pp $s1, $s2, $l"); + is $t, $c, $desc; } } } diff --git a/t/31-vcopy-copy.t b/t/31-vcopy-copy.t index 68b136b..af8d3a6 100644 --- a/t/31-vcopy-copy.t +++ b/t/31-vcopy-copy.t @@ -8,31 +8,40 @@ use Test::Leaner 'no_plan'; use Scalar::Vec::Util qw; -for ([ 1, 'offset', -1 ], [ 3, 'offset', '-1' ], [ 4, 'length', -1 ]) { +BEGIN { + *myfill = *Scalar::Vec::Util::vfill_pp; + *myeq = *Scalar::Vec::Util::veq_pp; +} + +for ([ 1, 'offset', -1 ], [ 3, 'offset', -1 ], [ 4, 'length', -1 ]) { my @args = (~0) x 5; $args[$_->[0]] = $_->[2]; - eval { &vcopy(@args) }; my $line = __LINE__; - like $@, qr/^Invalid\s+negative\s+$_->[1]\s+at\s+\Q$0\E\s+line\s+$line/; + local $@; + eval { &vcopy(@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/, + "vcopy(@args) failed"; } my $p = SVU_SIZE; -$p = 8 if $p < 8; +$p = 8 if $p < 8; my $n = 3 * $p; my $q = 1; -*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] = ''; if ($b) { - myfill($_[0], 0, $a, $x); - myfill($_[0], $a, $b, 1 - $x); + myfill $_[0], 0, $a, $x; + myfill $_[0], $a, $b, 1 - $x; } -} +} my ($f, $t, $c) = ('') x 3; @@ -41,12 +50,13 @@ for my $s1 (@s) { for my $s2 (@s) { for my $l (0 .. $n - 1) { last if $s1 + $l > $n or $s2 + $l > $n; + my $desc = "vcopy $s1, $s2, $l"; pat $f, $s1, $l, 0; rst $t; pat $c, $s2, $l, 0; vcopy $f => $s1, $t => $s2, $l; - ok(myeq($t, 0, $c, 0, $n), "vcopy $s1, $s2, $l"); - is(length $t, length $c, "length is ok"); + is length $t, length $c, "$desc: length"; + ok myeq($t, 0, $c, 0, $n), "$desc: bits"; } } } diff --git a/t/32-vcopy-move.t b/t/32-vcopy-move.t index 43776c0..f95fbd4 100644 --- a/t/32-vcopy-move.t +++ b/t/32-vcopy-move.t @@ -8,33 +8,37 @@ use Test::Leaner 'no_plan'; use Scalar::Vec::Util qw; +BEGIN { + *myfill = *Scalar::Vec::Util::vfill_pp; + *myeq = *Scalar::Vec::Util::veq_pp; +} + my $p = SVU_SIZE; -$p = 8 if $p < 8; +$p = 8 if $p < 8; my $n = 3 * $p; my $q = 1; -*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) = @_; - unless ($b) { - rst $_[0]; - } else { + my (undef, $a, $b, $x) = @_; + if ($b) { $_[0] = ''; - myfill($_[0], 0, $a, $x); - myfill($_[0], $a, $b, 1 - $x); - myfill($_[0], $a + $b, $n - ($a + $b), $x) if $a + $b < $n; + myfill $_[0], 0, $a, $x; + myfill $_[0], $a, $b, 1 - $x; + myfill $_[0], $a + $b, $n - ($a + $b), $x if $a + $b < $n; + } else { + rst $_[0]; } } sub prnt { - (undef, my $n, my $desc) = @_; - my $i = 0; - my $s; - $s .= vec($_[0], $i++, 1) while $i < $n; + my (undef, $n, $desc) = @_; + my $s = ''; + $s .= vec($_[0], $_, 1) for 0 .. $n - 1; diag "$desc: $s"; } @@ -48,20 +52,21 @@ for my $s1 (@s) { for my $y (0 .. $q) { last if $s1 + $l + $x > $n or $s1 + $x + $y > $l or $s2 + $l + $x > $n or $s2 + $x + $y > $l; + my $desc = "vcopy [ $x, $y ], $s1, $s2, $l (move)"; pat $v, $s1 + $x, $l - $x - $y, 0; my $v0 = $v; $c = $v; - myfill($c, $s2, $x, 0) if $x; - myfill($c, $s2 + $x, $l - $x - $y, 1); - myfill($c, $s2 + $l - $y, $y, 0) if $y; + myfill $c, $s2, $x, 0 if $x; + myfill $c, $s2 + $x, $l - $x - $y, 1; + myfill $c, $s2 + $l - $y, $y, 0 if $y; vcopy $v => $s1, $v => $s2, $l; - ok(myeq($v, 0, $c, 0, $n), "vcopy [ $x, $y ], $s1, $s2, $l (move)") or do { + is length $v, length $c, "$desc: length"; + ok myeq($v, 0, $c, 0, $n), "$desc: bits" or do { diag "n = $n, s1 = $s1, s2 = $s2, l = $l, x = $x, y = $y"; prnt $v0, $n, 'original'; prnt $v, $n, 'got '; prnt $c, $n, 'expected'; - }; - is(length $v, length $c, "length is ok"); + } } } } diff --git a/t/33-vcopy-long.t b/t/33-vcopy-long.t index 865055d..1e26573 100644 --- a/t/33-vcopy-long.t +++ b/t/33-vcopy-long.t @@ -8,10 +8,12 @@ use Config qw<%Config>; use Scalar::Vec::Util qw; -my $n = 2 ** 16; +BEGIN { + *myfill = *Scalar::Vec::Util::vfill_pp; + *myeq = *Scalar::Vec::Util::veq_pp; +} -*myfill = *Scalar::Vec::Util::vfill_pp; -*myeq = *Scalar::Vec::Util::veq_pp; +my $n = 2 ** 16; my ($v, $c) = ('') x 2; @@ -19,19 +21,23 @@ my $l = 1; vec($v, 0, 1) = 1; vec($c, 0, 1) = 1; while ($l <= $n) { - myfill($c, $l, $l, 1); - vcopy $v, 0, $v, $l, $l; + my $desc = "vcopy $l"; + myfill $c, $l, $l, 1; + vcopy $v, 0, $v, $l, $l; $l *= 2; - ok(myeq($v, 0, $c, 0, $l), "vcopy $l"); - is(length $v, length $c, "length is ok"); + is length $v, length $c, "$desc: length"; + ok myeq($v, 0, $c, 0, $l), "$desc: bits"; } -my ($w, $k) = ('') x 2; -$n = ($Config{alignbytes} - 1) * 8; -my $p = 4 + $n / 2; -vec($w, $_, 1) = 1 for 0 .. $n - 1; -vec($k, $_, 1) = 0 for 0 .. $n - 1; -vec($k, $_ - $p, 1) = 1 for $p .. $n - 1; -vcopy $w, $p, $w, 0, $n; -ok(myeq($w, 0, $k, 0, $n), "vcopy with fill"); -is(length $w, length $k, "length is ok"); +{ + my $desc = 'vcopy with fill'; + my ($w, $k) = ('') x 2; + $n = ($Config{alignbytes} - 1) * 8; + my $p = 4 + $n / 2; + vec($w, $_, 1) = 1 for 0 .. $n - 1; + vec($k, $_, 1) = 0 for 0 .. $n - 1; + vec($k, $_ - $p, 1) = 1 for $p .. $n - 1; + vcopy $w, $p, $w, 0, $n; + is length $w, length $k, "$desc: length"; + ok myeq($w, 0, $k, 0, $n), "$desc: bits"; +} diff --git a/t/40-vshift.t b/t/40-vshift.t index 15d1dec..b45ffc1 100644 --- a/t/40-vshift.t +++ b/t/40-vshift.t @@ -8,46 +8,55 @@ use Test::Leaner 'no_plan'; 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]; - eval { &vshift(@args) }; my $line = __LINE__; - like $@, qr/^Invalid\s+negative\s+$_->[1]\s+at\s+\Q$0\E\s+line\s+$line/; + 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 { - (undef, my $s, my $l, my $b, my $left, my $insert) = @_; - myfill($_[0], 0, $s, 0); + 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); + 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); + 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); + myfill $_[0], $s, $l, defined $insert ? $insert : 1; } } @@ -66,14 +75,14 @@ sub try { push @b, $l2 if $l2 != $l; push @b, $l + 1; for my $b (@b) { + my $desc = "vshift $s, $l, $b, " . (defined $insert ? $insert : 'undef'); $v = $v0; 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"; } } } diff --git a/t/50-vrot.t b/t/50-vrot.t index 227ca52..d897762 100644 --- a/t/50-vrot.t +++ b/t/50-vrot.t @@ -8,73 +8,81 @@ use Test::Leaner 'no_plan'; 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]; - eval { &vrot(@args) }; my $line = __LINE__; - like $@, qr/^Invalid\s+negative\s+$_->[1]\s+at\s+\Q$0\E\s+line\s+$line/; + local $@; + eval { &vrot(@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/, + "vrot(@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 $c, my $x) = @_; + my (undef, $a, $b, $c, $x) = @_; $_[0] = ''; - myfill($_[0], 0, $a, $x); - myfill($_[0], $a, $b, 1 - $x); - myfill($_[0], $a + $b, $c, $x); - myfill($_[0], $a + $b + $c, $n - ($a + $b + $c), 1 - $x); + myfill $_[0], 0, $a, $x; + myfill $_[0], $a, $b, 1 - $x; + myfill $_[0], $a + $b, $c, $x; + myfill $_[0], $a + $b + $c, $n - ($a + $b + $c), 1 - $x; } sub expected { - (undef, my $s, my $l, my $b, my $left) = @_; + my (undef, $s, $l, $b, $left) = @_; unless ($l) { - myfill($_[0], 0, $s, 0); - myfill($_[0], $s, $n - $s, 1); + myfill $_[0], 0, $s, 0; + myfill $_[0], $s, $n - $s, 1; return; } my $lx = int($l / 2); my $ly = $l - $lx; $b %= $l; $_[0] = ''; - myfill($_[0], 0, $s, 0); + myfill $_[0], 0, $s, 0; if ($left) { if ($b <= $ly) { - myfill($_[0], $s, $b, 0); - myfill($_[0], $s + $b, $lx, 1); - myfill($_[0], $s + $b + $lx, $l - $lx - $b, 0); + myfill $_[0], $s, $b, 0; + myfill $_[0], $s + $b, $lx, 1; + myfill $_[0], $s + $b + $lx, $l - $lx - $b, 0; } else { - myfill($_[0], $s, $b - $ly, 1); - myfill($_[0], $s + $b - $ly, $ly, 0); - myfill($_[0], $s + $b, $l - $b, 1); + myfill $_[0], $s, $b - $ly, 1; + myfill $_[0], $s + $b - $ly, $ly, 0; + myfill $_[0], $s + $b, $l - $b, 1; } } else { if ($b <= $lx) { - myfill($_[0], $s, $lx - $b, 1); - myfill($_[0], $s + $lx - $b, $l - $lx, 0); - myfill($_[0], $s + $l - $b, $b, 1); + myfill $_[0], $s, $lx - $b, 1; + myfill $_[0], $s + $lx - $b, $l - $lx, 0; + myfill $_[0], $s + $l - $b, $b, 1; } else { - myfill($_[0], $s, $ly - ($b - $lx), 0); - myfill($_[0], $s + $l - $b, $lx, 1); - myfill($_[0], $s + $l + $lx - $b, $b - $lx, 0); + myfill $_[0], $s, $ly - ($b - $lx), 0; + myfill $_[0], $s + $l - $b, $lx, 1; + myfill $_[0], $s + $l + $lx - $b, $b - $lx, 0; } } - myfill($_[0], $s + $l, $n - $s - $l, 1); + myfill $_[0], $s + $l, $n - $s - $l, 1; } sub prnt { - (undef, my $n, my $desc) = @_; - my $i = 0; + my (undef, $n, $desc) = @_; my $s; - $s .= vec($_[0], $i++, 1) while $i < $n; + $s .= vec($_[0], $_, 1) for 0 .. $n - 1; diag "$desc: $s"; } @@ -92,17 +100,18 @@ sub try { my @b = (0, 3, 5, 7, 11, 13, 17, $l2, $l2 + 1, $l + 1); @b = do { my %seen; ++$seen{$_} for @b; sort keys %seen }; for my $b (@b) { + my $desc = "vrot $s, $l, $b"; $v = $v0; expected $c, $s, $l, $b, $left; $b = -$b unless $left; vrot $v, $s, $l, $b; - ok(myeq($v, 0, $c, 0, $n), "vrot $s, $l, $b") or do { + is length $v, length $c, "$desc: length"; + ok myeq($v, 0, $c, 0, $n), "$desc: bits" or do { diag "n = $n, s = $s, l = $l, l2 = $l2"; prnt $v0, $n, 'original'; prnt $v, $n, 'got '; prnt $c, $n, 'expected'; - }; - is(length $v, length $c, "vrot $s, $l, $b length"); + } } } }