Skip to content

Commit

Permalink
also fail if zero N given.
Browse files Browse the repository at this point in the history
  • Loading branch information
mohawk2 committed Sep 11, 2024
1 parent d26726b commit 344f800
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Changes
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Revision history for PDL-DSP-Windows
{{$NEXT}}

Fixes:
* Make window and init fail if no defined N given.
* Make window and init fail if undefined or zero N given.

0.100 2021-11-01 20:51:14 GMT

Expand Down
7 changes: 4 additions & 3 deletions lib/PDL/DSP/Windows.pm
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ number. For example C<3> or C<[3]>.
=item B<N>
number of points in window function (the same as the order of the filter).
As of 0.102, throws exception if the value for C<N> is undefined.
As of 0.102, throws exception if the value for C<N> is undefined or zero.
=item B<periodic>
Expand Down Expand Up @@ -394,7 +394,7 @@ sub new {
Initialize (or reinitialize) a window object. C<ARGS> are interpreted in
exactly the same way as arguments for the L</window> subroutine.
As of 0.102, throws exception if the value for C<N> is undefined.
As of 0.102, throws exception if the value for C<N> is undefined or zero.
=for example
Expand Down Expand Up @@ -423,7 +423,7 @@ sub init {
})->options( shift // {} );

$name ||= $opts->{name};
$N ||= $opts->{N};
$N //= $opts->{N};
$periodic ||= $opts->{periodic};
$params //= $opts->{params};
$params = [$params] if defined $params && !ref $params;
Expand All @@ -438,6 +438,7 @@ sub init {

$self->{name} = $name;
$self->{N} = $N // die "Can't continue with undefined value for N";
die "Can't continue with zero value for N" if !$self->{N};
$self->{periodic} = $periodic;
$self->{params} = $params;
$self->{code} = __PACKAGE__->can( $name . ( $periodic ? '_per' : '' ) );
Expand Down
9 changes: 8 additions & 1 deletion t/oo.t
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ subtest 'Empty constructor' => sub {
'Constructor called from instance creates new instance';

try {
# TODO: Should this die earlier?
PDL::DSP::Windows->new->samples;
fail 'Did not die';
}
Expand All @@ -50,6 +49,14 @@ subtest 'Empty constructor' => sub {
like $_, qr/undefined value/,
"Can't construct incomplete window";
};
try {
PDL::DSP::Windows->new->init(0);
fail 'Did not die';
}
catch {
like $_, qr/zero/,
"Can't construct 0-sized window";
};
};

subtest 'Simple accesors' => sub {
Expand Down

0 comments on commit 344f800

Please sign in to comment.