Skip to content

Commit

Permalink
use Test::PDL instead of approx in t/{bad,clump}.t
Browse files Browse the repository at this point in the history
  • Loading branch information
mohawk2 committed Jan 5, 2025
1 parent 318f023 commit 11212e2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 30 deletions.
19 changes: 8 additions & 11 deletions t/bad.t
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ use PDL::Types qw(types);
use Test::Warn;
use Test::PDL;

# although approx() caches the tolerance value, we
# use it in every call just to document things
#
use constant ABSTOL => 1.0e-4;
sub abstol { {atol=>1.0e-4, test_name=>$_[0]} }

{
my $a_bad = pdl double, '[1 BAD 3]';
Expand Down Expand Up @@ -181,12 +178,12 @@ is( $x->check_badflag, 0, "check_badflag did not find a bad value" );
$x = pdl( qw(42 47 98 13 22 96 74 41 79 76 96 3 32 76 25 59 5 96 32 6) );
$y = $x->setbadif( $x < 20 );
my @s = $y->stats();
ok( approx( $s[0], 61.9375, ABSTOL ), "setbadif/stats test 1" );
ok( approx( $s[1], 27.6079, ABSTOL ), "setbadif/stats test 2" );
is( $s[2], 66.5, "setbadif/stats test 3" );
is( $s[3], 22, "setbadif/stats test 4" );
is( $s[4], 98, "setbadif/stats test 5" );
ok( approx( $s[6], 26.7312, ABSTOL ), "setbadif/stats test 6" );
is_pdl $s[0], pdl(61.9375), abstol("setbadif/stats test 1");
is_pdl $s[1], pdl(27.6079), abstol("setbadif/stats test 2");
is_pdl $s[2], pdl(66.5), "setbadif/stats test 3";
is_pdl $s[3], pdl(22), "setbadif/stats test 4";
is_pdl $s[4], pdl(98), "setbadif/stats test 5";
is_pdl $s[6], pdl(26.7312), abstol("setbadif/stats test 6");

# how about setbadtoval
empty()->setbadtoval(20); # shouldn't segfault
Expand Down Expand Up @@ -315,7 +312,7 @@ is( PDL::Core::string( $x->rotate(2) ), "[4 5 0 1 BAD]", "rotate()" );
$x = float( 2, 0, 2, 2 )->setvaltobad(0.0);
$y = $x->norm;
$c = $x/sqrt(sum($x*$x));
ok( all( approx( $y, $c, ABSTOL ) ), "norm()" ) or diag "got=$y\nexpected=$c";
is_pdl $y, $c, abstol("norm()");

# propagation of badflag using inplace ops (ops.pd)

Expand Down
30 changes: 11 additions & 19 deletions t/clump.t
Original file line number Diff line number Diff line change
@@ -1,27 +1,17 @@
use strict;
use warnings;

# Test ->clump(). This is not yet good enough: we need
# nasty test cases

use Test::More tests => 5;
use Test::More;
use PDL::LiteF;

use strict;
use warnings;

$|=1;
use Test::PDL;

# PDL::Core::set_debugging(1);
kill 'INT',$$ if $ENV{UNDER_DEBUGGER}; # Useful for debugging.

#$pa = zeroes(4,4) * zeroes(4,4);
# $pa = zeroes(4,4) ;

#print $pa;
#
#print $pa->at(3,3);
#
#exit 4;

my $eps = 0.01; # tolerance for tests
sub abstol { {atol=>0.01, test_name=>$_[0]} } # tolerance for tests

if(0) {
# TODO dead code
Expand Down Expand Up @@ -66,7 +56,7 @@ if(0) {

note $pb;

ok(all(PDL::approx($pb,pdl([0,1,2,10,11,12,20,21,22]), $eps)),'clump(-1) entire ndarray');
is_pdl $pb, pdl([0,1,2,10,11,12,20,21,22]), abstol 'clump(-1) entire ndarray';

my $pc = $pa->slice('0:2:2,:');

Expand All @@ -82,9 +72,9 @@ if(0) {
# ok(2,$@ =~ /^clump: Increments do not match/);
# Clump supports this now.

ok(all(PDL::approx($pd,pdl([0,2,10,12,20,22]), $eps)),'clump(-1) slice with skip and whole dim');
is_pdl $pd,pdl([0,2,10,12,20,22]), abstol 'clump(-1) slice with skip and whole dim';

ok(all(PDL::approx($pe,pdl([10,12,20]), $eps)),'clump(-1) slice');
is_pdl $pe,pdl([10,12,20]), abstol 'clump(-1) slice';

# SF bug #406 clump(-N) failure
##-- test data
Expand All @@ -98,3 +88,5 @@ if(0) {
ok($a1->ndims == 2, "no-op clump(-2)");
ok($b2->ndims == 2, "general clump(-2)");
}

done_testing;

0 comments on commit 11212e2

Please sign in to comment.