-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Basic/Lib* tests replace approx with is_pdl - #34
- Loading branch information
Showing
4 changed files
with
95 additions
and
210 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
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 |
---|---|---|
@@ -1,64 +1,21 @@ | ||
use strict; | ||
use warnings; | ||
use Test::More; | ||
use Test::PDL; | ||
use PDL::LiteF; | ||
use PDL::ImageRGB; | ||
use PDL::Dbg; | ||
|
||
sub vars_ipv { | ||
PDL::Dbg::vars() if $PDL::debug; | ||
} | ||
|
||
sub p { | ||
print @_ if $PDL::debug; | ||
} | ||
|
||
$PDL::debug = 0; | ||
|
||
vars_ipv; | ||
|
||
{ | ||
my $im = float [1,2,3,4,5]; | ||
my $out = bytescl($im,100); | ||
ok(all approx($im,$out)); | ||
cmp_ok($out->get_datatype, '==', $PDL::Types::PDL_B); | ||
} | ||
|
||
{ | ||
my $im = float [1,2,3,4,5]; | ||
my $out = bytescl($im,-100); | ||
ok(all approx(pdl([0,25,50,75,100]),$out)); | ||
p "$out\n"; | ||
} | ||
|
||
{ | ||
my $rgb = double [[1,1,1],[1,0.5,0.7],[0.1,0.2,0.1]]; | ||
my $out = rgbtogr($rgb); | ||
ok(all approx($out,pdl([1,0.67,0.16]), 0.01)); | ||
cmp_ok($out->get_datatype, '==', $PDL::Types::PDL_D); | ||
vars_ipv; | ||
p $out; | ||
} | ||
is_pdl bytescl(float(1..5),100), byte(1..5); | ||
is_pdl bytescl(float(1,2,3,4,5),-100), byte([0,25,50,75,100]); | ||
is_pdl rgbtogr(pdl([1,1,1],[1,0.5,0.7],[0.1,0.2,0.1])), pdl([1,0.67,0.16]), {atol=>1e-2}; | ||
|
||
{ | ||
my $im = byte [[1,2,3],[0,3,0]]; | ||
my $lut = byte [[0,0,0], | ||
[10,1,10], | ||
[2,20,20], | ||
[30,30,3] | ||
]; | ||
# do the interlacing the lengthy way | ||
my $interl = zeroes(byte,3,$im->dims); | ||
for my $i (0..($im->dims)[0]-1) { | ||
for my $j (0..($im->dims)[1]-1) { | ||
my $pos = $im->at($i,$j); | ||
(my $tmp = $interl->slice(":,($i),($j)")) .= $lut->slice(":,($pos)"); | ||
} | ||
} | ||
my $out = interlrgb($im,$lut); | ||
vars_ipv; | ||
p $out; | ||
ok(all approx($out,$interl)); | ||
my $im = byte('1 2 3;0 3 0'); | ||
my $lut = byte('0 0 0;10 1 10;2 20 20;30 30 3'); | ||
# also works: $lut->indexND(sequence(1,3)->append($im->slice('*1,*3'))) | ||
my $interl = byte('[10 1 10;2 20 20;30 30 3] [0 0 0;30 30 3;0 0 0]'); | ||
is_pdl interlrgb($im,$lut),$interl; | ||
} | ||
|
||
done_testing; |
Oops, something went wrong.