Skip to content

Commit

Permalink
Graphics::Limits tests replace approx with is_pdl - #34
Browse files Browse the repository at this point in the history
  • Loading branch information
mohawk2 committed Oct 30, 2024
1 parent 0b3cd01 commit a6073c0
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
3 changes: 2 additions & 1 deletion Graphics/Limits/t/limits_range.t
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use strict;
use warnings;
use Test::More;
use Test::PDL;
use PDL;
use PDL::Graphics::Limits;

Expand Down Expand Up @@ -34,7 +35,7 @@ $x1 = pdl( 1, 2, 3, 4 );
$y1 = pdl( 0, 10, 3, 4 );

@range = limits( [ $x1, $y1 ], { Bounds => 'Zscale', Clean => 'None' } );
ok( all(approx( pdl(@range), pdl ( 1, 4, -0.4, 8.9 ) )), 'Zscale, None' ) or diag explain \@range;
is_pdl pdl(@range), pdl(1, 4, -0.4, 8.9), 'Zscale, None';

@range = limits( [ 1, 2 ], [ 3, 4 ], { Bounds => 'MinMax', Clean => 'None' } );
is_deeply \@range, [ 1, 3, 2, 4 ], "scalars in the mix " or diag explain \@range;
Expand Down
10 changes: 5 additions & 5 deletions Graphics/Limits/t/limits_round.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use strict;
use warnings;
use PDL::LiteF;
use Test::More;
use Test::PDL;
use PDL::Graphics::Limits;
use Config;

Expand Down Expand Up @@ -55,11 +56,10 @@ my @round_tests =

for my $test ( @round_tests )
{
my $down = round_pow( down => $test->[0] );
my $up = round_pow( up => $test->[0] );
my $eps = abs($test->[0]) > 1 ? abs($test->[0])/1.0e-6 : 1.0e-6;

ok( approx($test->[1],$down,$eps) && approx($test->[2],$up,$eps), 'round_pow('. $test->[0] .')' );
my $down = pdl round_pow( down => $test->[0] );
my $up = pdl round_pow( up => $test->[0] );
is_pdl $down, pdl($test->[1]), "round_pow($test->[0])";
is_pdl $up, pdl($test->[2]), "round_pow($test->[0])";
}

done_testing;
7 changes: 4 additions & 3 deletions Graphics/Limits/t/limits_trans_err.t
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use strict;
use warnings;
use Test::More;
use Test::PDL;
use PDL;
use PDL::Graphics::Limits;

Expand All @@ -16,18 +17,18 @@ my $y2 = pdl( -1, 2, 4 );
my @udsets = ( [ [ $x1, $xn ], $y1], [ $x2, $y2 ] );
my $range = pdl limits( @udsets, { Bounds => 'MinMax', Clean => 'None', Trans => [ \&log10 ], } );

ok all(approx($range, pdl([ log10(1-0.5), log10(4), -1, 10 ]))), 'x symmetric trans';
is_pdl $range, pdl([ log10(1-0.5), log10(4), -1, 10 ]), 'x symmetric trans';

@udsets = ( [ [ $x1, $xn ], $y1], [ [ $x2, undef, $xp ], $y2 ] );
$range = pdl limits( @udsets, { Bounds => 'MinMax', Clean => 'None', Trans => [ \&log10 ], } );

ok all(approx($range, pdl([ log10(1-0.5), log10(4+0.25), -1, 10 ]))), 'x asymmetric trans';
is_pdl $range, pdl([ log10(1-0.5), log10(4+0.25), -1, 10 ]), 'x asymmetric trans';

$y1 = pdl( 0.5, 1, 5 );
$y2 = pdl( 0.5, 0.5, 0.5 );
@udsets = ( [ [ $y1, $y2 ] ] );
$range = pdl limits( @udsets, { Bounds => 'MinMax', Clean => 'None', Trans => [ \&log10 ], } );

ok all(approx($range, pdl([ log10(0.5), log10(5+0.5) ]))), 'illegal errbar lower bounds';
is_pdl $range, pdl([ log10(0.5), log10(5+0.5) ]), 'illegal errbar lower bounds';

done_testing;
7 changes: 4 additions & 3 deletions Graphics/Limits/t/limits_ulimits.t
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use strict;
use warnings;
use Test::More;
use Test::PDL;
use PDL;
use PDL::Graphics::Limits;

Expand Down Expand Up @@ -84,7 +85,7 @@ my @tests = (
foreach my $test ( @tests ) {
my ( $msg, $limits, $exp ) = @$test;
my $range = pdl limits( @udsets_arr, { %attr, Limits => $limits } );
ok( all(approx $range, pdl $exp), "array: $msg" );
is_pdl $range, pdl($exp), "array: $msg";
}

@tests = (
Expand Down Expand Up @@ -133,7 +134,7 @@ foreach my $test ( @tests ) {
foreach my $test ( @tests ) {
my ( $msg, $limits, $exp ) = @$test;
my $range = pdl limits( @udsets_hash, { %attr, Limits => $limits, VecKeys => [ qw/ x y / ] } );
ok( all(approx $range, pdl $exp), "hash: $msg" );
is_pdl $range, pdl($exp), "hash: $msg";
}

#############################################################
Expand Down Expand Up @@ -189,7 +190,7 @@ foreach my $test ( @tests ) {
foreach my $test ( @tests ) {
my ( $msg, $limits, $exp ) = @$test;
my $range = pdl limits( @udsets_arr, { %attr, Limits => $limits } );
ok( all(approx $range, pdl $exp), "array: $msg" ) or diag "($range), [@$exp]\n";
is_pdl $range, pdl($exp), "array: $msg";
}

done_testing;

0 comments on commit a6073c0

Please sign in to comment.