Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix for string parsing and dimension handling (fixes SF#367)
There was a logic error where ->setdims([]) would get called when trying to remove the outermost dimension, but this would run after using clump() on a string that had a single value and ->dims() == 1. This also fixes the BAD value parsing bug in SF#367 which led to an incorrect BAD value when parsing the string "[BAD]". See <http://sourceforge.net/p/pdl/bugs/367/>, <#47>.
- Loading branch information
Showing
2 changed files
with
53 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use Test::More; | ||
|
||
use strict; | ||
use warnings; | ||
|
||
use PDL::Config; | ||
|
||
plan skip_all => "Bad values disabled" unless $PDL::Config{WITH_BADVAL}; | ||
|
||
use PDL::LiteF; | ||
|
||
## Issue information | ||
## | ||
## Name: BAD value parsing breakage | ||
## | ||
## Parsing of BAD values fails to set the correct BAD value when parsing from | ||
## the string "[BAD]". | ||
## | ||
## <http://sourceforge.net/p/pdl/bugs/367/> | ||
## <https://github.com/PDLPorters/pdl/issues/47> | ||
|
||
my $cases = { | ||
q|BAD| => q|BAD|, | ||
q|BAD BAD| => q|[BAD BAD]|, | ||
q|BAD BAD BAD| => q|[BAD BAD BAD]|, | ||
q|[BAD]| => q|[BAD]|, | ||
q|[ BAD ]| => q|[BAD]|, | ||
q|[BAD BAD]| => q|[BAD BAD]|, | ||
q|[ BAD BAD ]| => q|[BAD BAD]|, | ||
}; | ||
|
||
plan tests => scalar keys %$cases; | ||
|
||
while( my ($case_string, $expected_string) = each %$cases ) { | ||
my $bad_pdl = pdl( $case_string ); | ||
subtest "Testing case: $case_string" => sub { | ||
ok( $bad_pdl->badflag, 'has badflag enabled'); | ||
ok( $bad_pdl->isbad->all, 'all values in PDL are BAD'); | ||
|
||
is($bad_pdl->string, $expected_string, "PDL stringifies back to input string: @{[ $bad_pdl->string ]}"); | ||
}; | ||
} | ||
|
||
done_testing; |