]> git.vpit.fr Git - perl/modules/Scalar-Vec-Util.git/blob - t/21-vfill.t
Importing Scalar-Vec-Util-0.01.tar.gz
[perl/modules/Scalar-Vec-Util.git] / t / 21-vfill.t
1 #!perl -T
2
3 use strict;
4 use warnings;
5
6 use Test::More 'no_plan';
7
8 use Scalar::Vec::Util qw/vfill SVU_SIZE/;
9
10 eval { vfill undef, 0, 0, 0 };
11 like($@, qr/Invalid\s+argument/, 'first argument undef croaks');
12 eval { vfill my $x, undef, 0, 0 };
13 like($@, qr/Invalid\s+argument/, 'second argument undef croaks');
14 eval { vfill my $x, 0, undef, 0 };
15 like($@, qr/Invalid\s+argument/, 'third argument undef croaks');
16 eval { vfill my $x, 0, 0, undef };
17 like($@, qr/Invalid\s+argument/, 'fourth argument undef croaks');
18
19 my $p = SVU_SIZE;
20 $p = 8 if $p < 8;
21 my $n = 3 * $p;
22 my $q = 1;
23
24 *myfill = *Scalar::Vec::Util::vfill_pp;
25 *myeq   = *Scalar::Vec::Util::veq_pp;
26
27 sub rst { myfill($_[0], 0, $n, 0); $_[0] = '' }
28
29 sub pat {
30  (undef, my $a, my $b, my $x) = @_;
31  $_[0] = '';
32  if ($b) {
33   myfill($_[0], 0, $a, $x);
34   myfill($_[0], $a, $b, 1 - $x);
35  }
36 }
37
38 my ($v, $c) = ('') x 2;
39
40 my @s = ($p - $q) .. ($p + $q);
41 for my $s (@s) {
42  for my $l (0 .. $n - 1) {
43   next if $s + $l > $n;
44   pat $c, $s, $l, 0;
45   rst $v;
46   vfill $v, $s, $l, 1;
47   ok(myeq($v, 0, $c, 0, $n), "vfill $s, $l");
48   is(length $v, length $c, "length is ok");
49  }
50 }