]> git.vpit.fr Git - perl/modules/Scalar-Vec-Util.git/blob - t/30-vcopy-pp.t
2ce27731c773c808bb4fe053b3044cd2103a8ead
[perl/modules/Scalar-Vec-Util.git] / t / 30-vcopy-pp.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/SVU_SIZE/;
9
10 for ([ 1, 'offset', -1 ], [ 3, 'offset', '-1' ], [ 4, 'length', -1 ]) {
11  my @args  = ('1') x 5;
12  $args[$_->[0]] = $_->[2];
13  eval { &Scalar::Vec::Util::vcopy_pp(@args) }; my $line = __LINE__;
14  like $@, qr/^Invalid\s+negative\s+$_->[1]\s+at\s+\Q$0\E\s+line\s+$line/;
15 }
16
17 my $p = SVU_SIZE;
18 $p = 8 if $p < 8;
19 my $n = 3 * $p;
20 my $q = 1;
21
22 *myfill = *Scalar::Vec::Util::vfill_pp;
23
24 sub rst { myfill($_[0], 0, $n, 0) }
25   
26 sub pat {
27  (undef, my $a, my $b, my $x) = @_;
28  myfill($_[0], 0, $a, $x);
29  myfill($_[0], $a, $b, 1 - $x);
30  myfill($_[0], $a + $b, $n - ($a + $b) , $x);
31 }  
32
33 my ($f, $t, $c) = ('') x 3;
34
35 my @s = ($p - $q) .. ($p + $q);
36 for my $s1 (@s) {
37  for my $s2 (@s) {
38   for my $l (0 .. $n - 1) {
39    last if $s1 + $l > $n or $s2 + $l > $n;
40    pat $f, $s1, $l, 0;
41    rst $t;
42    pat $c, $s2, $l, 0;
43    Scalar::Vec::Util::vcopy_pp($f => $s1, $t => $s2, $l);
44    is($t, $c, "vcopy_pp $s1, $s2, $l");
45   }
46  }
47 }