Skip to content

Commit

Permalink
incorporate Test::PDL
Browse files Browse the repository at this point in the history
  • Loading branch information
mohawk2 committed Oct 28, 2024
1 parent 3a56cef commit c4374ea
Show file tree
Hide file tree
Showing 11 changed files with 1,384 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Basic/Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ my %pm = map { my $h = '$(INST_LIBDIR)/';
$pm{'PDLdb.pl'} = '$(INST_LIB)/PDLdb.pl';
$pm{'threads.pm'} = '$(INST_LIB)/PDL/Parallel/threads.pm';
$pm{'SIMD.pm'} = '$(INST_LIB)/PDL/Parallel/threads/SIMD.pm';
$pm{'TestPDL.pm'} = '$(INST_LIB)/Test/PDL.pm';
$pm{'TestDeepPDL.pm'} = '$(INST_LIB)/Test/Deep/PDL.pm';

my %man3pods = map { my $h = '$(INST_MAN3DIR)/';
$h .= 'PDL::' if $_ !~ /PDL.pm$/;
Expand Down
70 changes: 70 additions & 0 deletions Basic/TestDeepPDL.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
use strict;
use warnings;

package Test::Deep::PDL;

# ABSTRACT: Test ndarrays inside data structures with Test::Deep

=for Pod::Coverage init descend diag_message renderExp renderGot
=cut

use Test::Deep::Cmp;
require Test::PDL;

=head1 DESCRIPTION
This is just an implementation class. Look at the documentation for test_pdl()
in L<Test::PDL>.
=cut

sub init
{
my $self = shift;
my $expected = shift;
die "Supplied value is not an ndarray" unless eval { $expected->isa('PDL') };
$self->{expected} = $expected;
}

sub descend
{
my $self = shift;
my $got = shift;
( my $ok, $self->data->{diag} ) = Test::PDL::eq_pdl( $got, $self->{expected} );
return $ok;
}

sub diag_message
{
my $self = shift;
my $where = shift;
return "Comparing $where as an ndarray:\n" . $self->data->{diag};
}

sub renderExp
{
my $self = shift;
return $self->renderGot( $self->{expected} );
}

sub renderGot
{
my $self = shift;
my $val = shift;
my $fmt = '%-8T %-12D (%-5S) ';
return eval { $val->isa('PDL') } ? ($val->info($fmt) . $val) : ("(" . Test::Deep::render_val($val) . ")");
}

=head1 BUGS
The implementation of this class depends on undocumented subroutines in
L<Test::Deep>. This may break if L<Test::Deep> gets refactored.
=head1 SEE ALSO
L<PDL>, L<Test::PDL>, L<Test::Deep>
=cut

1;
Loading

0 comments on commit c4374ea

Please sign in to comment.