line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# -*- Mode: CPerl -*- |
2
|
|
|
|
|
|
|
# File: t/common.plt |
3
|
|
|
|
|
|
|
# Description: re-usable test subs; requires Test::More |
4
|
13
|
|
|
13
|
|
216952
|
BEGIN { $| = 1; } |
5
|
13
|
|
|
13
|
|
150
|
use strict; |
|
13
|
|
|
|
|
24
|
|
|
13
|
|
|
|
|
14556
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# isok($label,@_) -- prints helpful label |
8
|
|
|
|
|
|
|
sub isok { |
9
|
4994
|
|
|
4994
|
|
209648
|
my $label = shift; |
10
|
4994
|
100
|
|
|
|
13480
|
if (@_==1) { |
|
|
50
|
|
|
|
|
|
11
|
2650
|
|
|
|
|
7492
|
ok($_[0],$label); |
12
|
|
|
|
|
|
|
} elsif (@_==2) { |
13
|
2344
|
|
|
|
|
6880
|
is($_[0],$_[1], $label); |
14
|
|
|
|
|
|
|
} else { |
15
|
0
|
|
|
|
|
0
|
die("isok(): expected 1 or 2 non-label arguments, but got ", scalar(@_)); |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# skipok($label,$skip_if_true,@_) -- prints helpful label |
20
|
|
|
|
|
|
|
# skipok($label,$skip_if_true,\&CODE) -- prints helpful label |
21
|
|
|
|
|
|
|
sub skipok { |
22
|
70
|
|
|
70
|
|
5984
|
my ($label,$skip_if_true) = splice(@_,0,2); |
23
|
70
|
50
|
|
|
|
145
|
if ($skip_if_true) { |
24
|
0
|
|
|
0
|
|
0
|
subtest $label => sub { plan skip_all => $skip_if_true; }; |
|
0
|
|
|
|
|
0
|
|
25
|
|
|
|
|
|
|
} else { |
26
|
70
|
100
|
66
|
|
|
228
|
if (@_==1 && ref($_[0]) && ref($_[0]) eq 'CODE') { |
|
|
|
66
|
|
|
|
|
27
|
2
|
|
|
|
|
8
|
isok($label, $_[0]->()); |
28
|
|
|
|
|
|
|
} else { |
29
|
68
|
|
|
|
|
165
|
isok($label,@_); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# skipordo($label,$skip_if_true,sub { ok ... },@args_for_sub) |
35
|
|
|
|
|
|
|
sub skipordo { |
36
|
1
|
|
|
1
|
|
6
|
my ($label,$skip_if_true) = splice(@_,0,2); |
37
|
1
|
50
|
|
|
|
4
|
if ($skip_if_true) { |
38
|
0
|
|
|
0
|
|
0
|
subtest $label => sub { plan skip_all => $skip_if_true; }; |
|
0
|
|
|
|
|
0
|
|
39
|
|
|
|
|
|
|
} else { |
40
|
1
|
|
|
|
|
4
|
$_[0]->(@_[1..$#_]); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# ulistok($label,\@got,\@expect) |
45
|
|
|
|
|
|
|
# --> ok() for unsorted lists |
46
|
|
|
|
|
|
|
sub ulistok { |
47
|
0
|
|
|
0
|
|
0
|
my ($label,$l1,$l2) = @_; |
48
|
0
|
|
|
|
|
0
|
is_deeply([sort @$l1],[sort @$l2],$label); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# matchpdl($a,$b) : returns pdl identity check, including BAD |
52
|
|
|
|
|
|
|
sub matchpdl { |
53
|
2504
|
|
|
2504
|
|
349700
|
my ($a,$b) = map {PDL->topdl($_)->setnantobad} @_[0,1]; |
|
5008
|
|
|
|
|
60422
|
|
54
|
2504
|
|
|
|
|
217459
|
return ($a==$b)->setbadtoval(0) | ($a->isbad & $b->isbad) | ($a->isfinite->not & $b->isfinite->not); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
# matchpdl($a,$b,$eps) : returns pdl approximation check, including BAD |
57
|
|
|
|
|
|
|
sub matchpdla { |
58
|
7
|
|
|
7
|
|
948
|
my ($a,$b) = map {$_->setnantobad} @_[0,1]; |
|
14
|
|
|
|
|
113
|
|
59
|
7
|
|
|
|
|
13
|
my $eps = $_[2]; |
60
|
7
|
50
|
|
|
|
50
|
$eps = 1e-5 if (!defined($eps)); |
61
|
7
|
|
|
|
|
22
|
return $a->approx($b,$eps)->setbadtoval(0) | ($a->isbad & $b->isbad) | ($a->isfinite->not & $b->isfinite->not); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# cmp_dims($got_pdl,$expect_pdl) |
65
|
|
|
|
|
|
|
sub cmp_dims { |
66
|
2502
|
|
|
2502
|
|
4467
|
my ($p1,$p2) = @_; |
67
|
2502
|
|
33
|
|
|
14570
|
return $p1->ndims==$p2->ndims && all(pdl(PDL::long(),[$p1->dims])==pdl(PDL::long(),[$p2->dims])); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub pdlstr { |
71
|
0
|
|
|
0
|
|
0
|
my $a = shift; |
72
|
0
|
0
|
|
|
|
0
|
my $str = defined($a) ? "$a" : '(undef)'; |
73
|
|
|
|
|
|
|
#$str =~ s/\n/ /g; |
74
|
0
|
|
|
|
|
0
|
return $str; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
sub labstr { |
77
|
2511
|
|
|
2511
|
|
6393
|
my ($label,$ok,$got,$want) = @_; |
78
|
2511
|
50
|
|
|
|
5455
|
$label .= "\n : got=".pdlstr($got)."\n : wanted=".pdlstr($want) if (!$ok); |
79
|
2511
|
|
|
|
|
6545
|
return $label; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
# pdlok($label, $got, $want) |
83
|
|
|
|
|
|
|
sub pdlok { |
84
|
2495
|
|
|
2495
|
|
467636
|
my ($label,$got,$want) = @_; |
85
|
2495
|
50
|
|
|
|
9516
|
$got = PDL->topdl($got) if (defined($got)); |
86
|
2495
|
50
|
|
|
|
27595
|
$want = PDL->topdl($want) if (defined($want)); |
87
|
2495
|
|
33
|
|
|
29145
|
my $ok = (defined($got) && defined($want) |
88
|
|
|
|
|
|
|
&& cmp_dims($got,$want) |
89
|
|
|
|
|
|
|
&& all(matchpdl($want,$got)) |
90
|
|
|
|
|
|
|
); |
91
|
2495
|
|
|
|
|
142385
|
isok(labstr($label,$ok,$got,$want), $ok); |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
# pdlok_nodims($label, $got, $want) |
95
|
|
|
|
|
|
|
# + ignores dimensions |
96
|
|
|
|
|
|
|
sub pdlok_nodims { |
97
|
9
|
|
|
9
|
|
213
|
my ($label,$got,$want) = @_; |
98
|
9
|
50
|
|
|
|
35
|
$got = PDL->topdl($got) if (defined($got)); |
99
|
9
|
50
|
|
|
|
115
|
$want = PDL->topdl($want) if (defined($want)); |
100
|
9
|
|
33
|
|
|
99
|
my $ok = (defined($got) && defined($want) |
101
|
|
|
|
|
|
|
#&& cmp_dims($got,$want) |
102
|
|
|
|
|
|
|
&& all(matchpdl($want,$got))); |
103
|
9
|
|
|
|
|
507
|
isok(labstr($label,$ok,$got,$want), $ok); |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
# pdlapprox($label, $got, $want, $eps=1e-5) |
107
|
|
|
|
|
|
|
sub pdlapprox { |
108
|
7
|
|
|
7
|
|
38
|
my ($label,$got,$want,$eps) = @_; |
109
|
7
|
50
|
|
|
|
32
|
$got = PDL->topdl($got) if (defined($got)); |
110
|
7
|
50
|
|
|
|
88
|
$want = PDL->topdl($want) if (defined($want)); |
111
|
7
|
50
|
|
|
|
60
|
$eps = 1e-5 if (!defined($eps)); |
112
|
7
|
|
33
|
|
|
34
|
my $ok = (defined($got) && defined($want) |
113
|
|
|
|
|
|
|
&& cmp_dims($got,$want) |
114
|
|
|
|
|
|
|
&& all(matchpdla($want,$got,$eps))); |
115
|
7
|
|
|
|
|
1082
|
isok(labstr($label,$ok,$got,$want), $ok); |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
print "loaded ", __FILE__, "\n"; |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
1; |
122
|
|
|
|
|
|
|
|