]> git.vpit.fr Git - perl/modules/Scalar-Vec-Util.git/blob - t/31-vcopy-copy.t
Importing Scalar-Vec-Util-0.01.tar.gz
[perl/modules/Scalar-Vec-Util.git] / t / 31-vcopy-copy.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/vcopy SVU_SIZE/;
9
10 eval { vcopy undef, 0, my $y, 0, 0 };
11 like($@, qr/Invalid\s+argument/, 'first argument undef croaks');
12 eval { vcopy my $x, undef, my $y, 0, 0 };
13 like($@, qr/Invalid\s+argument/, 'second argument undef croaks');
14 eval { vcopy my $x, 0, undef, 0, 0 };
15 like($@, qr/Invalid\s+argument/, 'third argument undef croaks');
16 eval { vcopy my $x, 0, my $y, undef, 0 };
17 like($@, qr/Invalid\s+argument/, 'fourth argument undef croaks');
18 eval { vcopy my $x, 0, my $y, 0, undef };
19 like($@, qr/Invalid\s+argument/, 'fifth argument undef croaks');
20
21 my $p = SVU_SIZE;
22 $p = 8 if $p < 8;
23 my $n = 3 * $p;
24 my $q = 1;
25
26 *myfill = *Scalar::Vec::Util::vfill_pp;
27 *myeq   = *Scalar::Vec::Util::veq_pp;
28
29 sub rst { myfill($_[0], 0, $n, 0); $_[0] = '' }
30   
31 sub pat {
32  (undef, my $a, my $b, my $x) = @_;
33  $_[0] = '';
34  if ($b) {
35   myfill($_[0], 0, $a, $x);
36   myfill($_[0], $a, $b, 1 - $x);
37  }
38 }  
39
40 my ($f, $t, $c) = ('') x 3;
41
42 my @s = ($p - $q) .. ($p + $q);
43 for my $s1 (@s) {
44  for my $s2 (@s) {
45   for my $l (0 .. $n - 1) {
46    last if $s1 + $l > $n or $s2 + $l > $n;
47    pat $f, $s1, $l, 0;
48    rst $t;
49    pat $c, $s2, $l, 0;
50    vcopy $f => $s1, $t => $s2, $l;
51    ok(myeq($t, 0, $c, 0, $n), "vcopy $s1, $s2, $l");
52    is(length $t, length $c, "length is ok");
53   }
54  }
55 }