File Coverage

blib/lib/Test/Deep/PDL.pm
Criterion Covered Total %
statement 28 28 100.0
branch 3 4 75.0
condition n/a
subroutine 8 8 100.0
pod 0 5 0.0
total 39 45 86.6


line stmt bran cond sub pod time code
1 1     1   8 use strict;
  1         3  
  1         45  
2 1     1   5 use warnings;
  1         4  
  1         156  
3              
4             package Test::Deep::PDL;
5              
6             =head1 NAME
7              
8             Test::Deep::PDL - Test ndarrays inside data structures with Test::Deep
9              
10             =for Pod::Coverage init descend diag_message renderExp renderGot
11              
12             =cut
13              
14             our $VERSION = '0.22';
15              
16 1     1   623 use Test::Deep::Cmp;
  1         1010  
  1         6  
17             require Test::PDL;
18              
19             =head1 DESCRIPTION
20              
21             This is just an implementation class. Look at the documentation for test_pdl()
22             in L.
23              
24             =cut
25              
26             sub init
27             {
28 109     109 0 1127 my $self = shift;
29 109         214 my $expected = shift;
30 109 50       223 die "Supplied value is not an ndarray" unless eval { $expected->isa('PDL') };
  109         658  
31 109         517 $self->{expected} = $expected;
32             }
33              
34             sub descend
35             {
36 93     93 0 306140 my $self = shift;
37 93         258 my $got = shift;
38 93         593 ( my $ok, $self->data->{diag} ) = Test::PDL::eq_pdl( $got, $self->{expected} );
39 93         1648 return $ok;
40             }
41              
42             sub diag_message
43             {
44 3     3 0 3989 my $self = shift;
45 3         8 my $where = shift;
46 3         11 return "Comparing $where as an ndarray:\n" . $self->data->{diag};
47             }
48              
49             sub renderExp
50             {
51 3     3 0 28 my $self = shift;
52 3         8 return $self->renderGot( $self->{expected} );
53             }
54              
55             sub renderGot
56             {
57 6     6 0 54 my $self = shift;
58 6         12 my $val = shift;
59 6         11 my $fmt = '%-8T %-12D (%-5S) ';
60 6 100       11 return eval { $val->isa('PDL') } ? ($val->info($fmt) . $val) : ("(" . Test::Deep::render_val($val) . ")");
  6         43  
61             }
62              
63             =head1 BUGS
64              
65             The implementation of this class depends on undocumented subroutines in
66             L. This may break if L gets refactored.
67              
68             =head1 SEE ALSO
69              
70             L, L, L
71              
72             =cut
73              
74             1;