use Scalar::Vec::Util qw<vfill vcopy veq SVU_PP>;
-is(SVU_PP, 1, 'using pure perl subroutines');
+is SVU_PP, 1, 'using pure perl subroutines';
for (qw<vfill vcopy veq>) {
no strict 'refs';
- is(*{$_}{CODE}, *{'Scalar::Vec::Util::'.$_}{CODE}, $_ .' is ' . $_ . '_pp');
+ is *{$_}{CODE}, *{'Scalar::Vec::Util::'.$_}{CODE}, $_ .' is ' . $_ . '_pp';
}
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';
}
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;
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;
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";
+ }
}
}
}
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;
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";
+ }
}
}
}
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';
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;
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;
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";
}
}
use Scalar::Vec::Util qw<vfill SVU_SIZE>;
+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;
}
}
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";
}
}
use Scalar::Vec::Util qw<vfill>;
-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;
}
use Scalar::Vec::Util qw<SVU_SIZE>;
+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;
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;
}
}
}
use Scalar::Vec::Util qw<vcopy SVU_SIZE>;
-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;
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";
}
}
}
use Scalar::Vec::Util qw<vcopy SVU_SIZE>;
+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";
}
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");
+ }
}
}
}
use Scalar::Vec::Util qw<vcopy>;
-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;
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";
+}
use Scalar::Vec::Util qw<vshift SVU_SIZE>;
+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;
}
}
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";
}
}
}
use Scalar::Vec::Util qw<vrot vcopy SVU_SIZE>;
+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";
}
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");
+ }
}
}
}