Skip to content

Commit

Permalink
generalise dim-compatibility tests, move to core.t
Browse files Browse the repository at this point in the history
  • Loading branch information
mohawk2 committed Feb 20, 2024
1 parent a2eb40e commit 4d220a5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 23 deletions.
17 changes: 17 additions & 0 deletions t/core.t
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use strict;
use warnings;
use Test::More;
use Test::Exception;
use PDL::LiteF;
use Config;
use PDL::Types;
Expand Down Expand Up @@ -144,6 +145,22 @@ ok all(tapprox((5*sequence(5))->maximum_n_ind(3), pdl(4,3,2))), 'named dim';
# pptest for dim with fixed value
ok all(tapprox(crossp([1..3],[4..6]), pdl(-3,6,-3))), 'named dim=3';

subtest 'dim compatibility' => sub {
for (
[\&append, [pdl(1), pdl(2), zeroes(1)], 2, qr/dim has size 1/, 'output => [1]; required [2]. output too small'],
[\&append, [pdl(1), pdl(2), zeroes(3,1)], 2, qr/dim has size 3/, 'output => [3,1]; required [2]. output too small'],
[\&append, [pdl(1), pdl(2), null], 2, [ 1, 2 ], 'output => null; required [2]'],
) {
my ($func, $args, $exp_index, $exp, $label) = @$_;
if (ref $exp eq 'Regexp') {
throws_ok { $func->( @$args ) } $exp, $label;
} else {
$func->( @$args );
is_deeply( $args->[$exp_index]->unpdl, $exp, $label );
}
}
};

# test topdl

{ package # hide from PAUSE
Expand Down
23 changes: 0 additions & 23 deletions t/primitive-append.t
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use strict;
use warnings;
use Test::More;
use Test::Exception;
use PDL::LiteF;

is_deeply(
Expand All @@ -24,28 +23,6 @@ subtest 'append(null, null, $output)' => sub {
is_deeply( $output->unpdl, [0], q{user's ndarray is unchanged} );
};

subtest 'output ndarray has different shape' => sub {

subtest 'output => [1]; required [2]. output too small' => sub {
my $output = zeroes(1);
throws_ok { append( pdl(1), pdl(2), $output ) }
qr/dim has size 1/;
};

subtest 'output => [3,1]; required [2]' => sub {
my $output = zeroes(3,1);
throws_ok { append( pdl(1), pdl(2), $output ) }
qr/dim has size 3/;
};

subtest 'output => null; required [2]' => sub {
my $output = null;
append( pdl(1), pdl(2), $output );
is_deeply( $output->unpdl, [ 1, 2 ], q{full append } );
};

};

subtest types => sub {

is( append( zeroes( float, 2, 0 ), zeroes( 3, 0 ) )->type,
Expand Down

0 comments on commit 4d220a5

Please sign in to comment.