Skip to content

Commit

Permalink
ImageRGB tests replace tapprox with is_pdl - #34
Browse files Browse the repository at this point in the history
  • Loading branch information
mohawk2 committed Oct 29, 2024
1 parent 6551403 commit 5ffd3c5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 24 deletions.
22 changes: 8 additions & 14 deletions Basic/Lib-ImageRGB/t/picnorgb.t
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
use strict;
use warnings;

use PDL::LiteF;
use PDL::IO::Pic;
use PDL::ImageRGB;
use PDL::Dbg;
use File::Temp qw(tempdir);
use File::Spec;

use strict;
use warnings;

use Test::More;

sub tapprox {
my($pa,$pb,$mdiff) = @_;
all approx($pa, $pb,$mdiff || 0.01);
}
use Test::PDL;

sub rpic_unlink {
my $file = shift;
Expand Down Expand Up @@ -69,7 +64,6 @@ if ($PDL::debug) {
# for some reason the pnmtotiff converter coredumps when trying
# to do the conversion for the ushort data, haven't yet tried to
# figure out why
my $usherr = 0;
my $tmpdir = tempdir( CLEANUP => 1 );
sub tmpfile { File::Spec->catfile($tmpdir, $_[0]); }
foreach my $format (sort @allowed) {
Expand All @@ -91,23 +85,23 @@ foreach my $format (sort @allowed) {
$im2->wpic($tbyte,{IFORM => "$iform"});
$im3->wpic($tbin,{COLOR => 'bw', IFORM => "$iform"});
my $in1 = rpic_unlink($tushort) unless
$usherr || $format eq 'TIFF';
$format eq 'TIFF';
my $in2 = rpic_unlink($tbyte);
my $in3 = rpic_unlink($tbin);

if ($format ne 'TIFF') {
my $scale = ($form->[2] || rgb($in1) ? $im1->dummy(0,3) : $im1);
my $comp = $scale / PDL::ushort($form->[1]);
ok($usherr || tapprox($comp,$in1,$form->[3]));
is_pdl $comp,$in1,$form->[3];
}
{
my $comp = ($form->[2] || rgb($in2) ? $im2->dummy(0,3) : $im2);
ok(tapprox($comp,$in2));
is_pdl $comp,$in2;
}
{
my $comp = ($form->[2] || rgb($in3) ? ($im3->dummy(0,3)>0)*255 : ($im3 > 0));
$comp = $comp->ushort*$in3->max if $format eq 'SGI' && $in3->max > 0;
ok(tapprox($comp,$in3));
is_pdl $comp,$in3;
}

if ($PDL::debug) {
Expand Down
14 changes: 4 additions & 10 deletions Basic/Lib-ImageRGB/t/picrgb.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,13 @@ use strict;
use warnings;
use Test::More;
use PDL::LiteF;
use Test::PDL;
use PDL::IO::Pic;
use PDL::ImageRGB;
use PDL::Dbg;
use File::Temp qw(tempdir);
use File::Spec;

sub tapprox {
my($pa,$pb,$mdiff) = @_;
all approx($pa, $pb,$mdiff || 0.01);
}

sub rpic_unlink {
my $file = shift;
my $pdl = PDL->rpic($file);
Expand Down Expand Up @@ -68,7 +64,6 @@ if ($PDL::debug){
note $im2;
}

my $usherr = 0;
my $tmpdir = tempdir( CLEANUP => 1 );
sub tmpfile { File::Spec->catfile($tmpdir, $_[0]); }
foreach my $form (sort @allowed) {
Expand All @@ -91,16 +86,15 @@ foreach my $form (sort @allowed) {
my $determined_format;
$determined_format = imageformat($tushort);
is($determined_format, $form, "image $tushort is format $form");
my $in1 = rpic_unlink($tushort) unless $usherr;
my $in1 = rpic_unlink($tushort);

$determined_format = imageformat($tbyte);
is($determined_format, $form, "image $tbyte is format $form");
my $in2 = rpic_unlink($tbyte);

my $comp = $im1 / PDL::ushort(mmax(depends_on($form),$arr->[1]));
ok($usherr || tapprox($in1,$comp,$arr->[3]), $form)
or diag "got=$in1\nexpected:$comp";
ok(tapprox($in2,$im2));
is_pdl $in1, $comp, {atol=>$arr->[3], test_name=>$form, require_equal_types => 0};
is_pdl $in2, $im2;

if ($PDL::debug) {
note $in1->px;
Expand Down

0 comments on commit 5ffd3c5

Please sign in to comment.