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 62673d6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 22 deletions.
16 changes: 16 additions & 0 deletions t/core.t
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,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 (
[pdl(1), pdl(2), zeroes(1), qr/dim has size 1/, 'output => [1]; required [2]. output too small'],
[pdl(1), pdl(2), zeroes(3,1), qr/dim has size 3/, 'output => [3,1]; required [2]'],
[pdl(1), pdl(2), null, [ 1, 2 ], 'output => null; required [2]'],
) {
my ($i1, $i2, $output, $exp, $label) = @$_;
if (ref $exp eq 'Regexp') {
throws_ok { append( $i1, $i2, $output ) } $exp, $label;
} else {
append( $i1, $i2, $output );
is_deeply( $output->unpdl, $exp, $label );
}
}
};

# test topdl

{ package # hide from PAUSE
Expand Down
22 changes: 0 additions & 22 deletions t/primitive-append.t
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,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 62673d6

Please sign in to comment.