X-Git-Url: http://git.ieval.ro/?p=convert-color-husl.git;a=blobdiff_plain;f=t%2FConvert-Color-HUSL.t;fp=t%2FConvert-Color-HUSL.t;h=42aab41f1f92ddf650fbf17c6c317d8a0ccb94d7;hp=9d993e432a016cb9e2d85c451c8a3f862dfcd0a7;hb=3d128ec5a01fb9c71fc148e246e606e82de92576;hpb=d1ec99790157d329abc74989017495fa6cbbd237 diff --git a/t/Convert-Color-HUSL.t b/t/Convert-Color-HUSL.t index 9d993e4..42aab41 100644 --- a/t/Convert-Color-HUSL.t +++ b/t/Convert-Color-HUSL.t @@ -4,35 +4,34 @@ use warnings; use Convert::Color::RGB8; use JSON::PP qw/decode_json/; -use Test::More; +use Test::More tests => 5 * 4096; -use constant EPSILON => 1e-4; # 1e-11 is OK on amd64 - -open my $fh, '<', 't/snapshot-rev4.json'; -my $snapshot = join '', <$fh>; -close $fh; - -my %tests = %{decode_json $snapshot}; -my @colors = sort keys %tests; - -plan tests => 5 * @colors; +use constant EPSILON => $ENV{RELEASE_TESTING} ? 1e-11 : 2e-4; +my @spaces = qw/XYZ LUV LCh HUSL HUSLp/; sub isf { my ($x, $y, $name) = @_; - my $ok = 1; - $ok &&= abs ($x->[$_] - $y->[$_]) < EPSILON for 0, 1, 2; - return pass $name if $ok; - local $" = ', '; - fail $name; - diag "[@$x] != [@$y]"; + ok !grep({ abs ($_ - shift @$y) > EPSILON } @$x), $name; } -for my $color (@colors) { - my %color = %{$tests{$color}}; - my $col = Convert::Color::RGB8->new(substr $color, 1); - isf $col->convert_to('xyz'), $color{xyz}, "convert $color to XYZ"; - isf $col->convert_to('luv'), $color{luv}, "convert $color to LUV"; - isf $col->convert_to('lch'), $color{lch}, "convert $color to LCh"; - isf $col->convert_to('husl'), $color{husl}, "convert $color to HUSL"; - isf $col->convert_to('huslp'), $color{huslp}, "convert $color to HUSLp"; +if ($ENV{RELEASE_TESTING}) { + require JSON::MaybeXS; + open my $fh, '<', 't/snapshot-rev4.json'; + my $snapshot = join '', <$fh>; + + my %tests = %{JSON::MaybeXS::decode_json $snapshot}; + + for my $color (sort keys %tests) { + my $col = Convert::Color::RGB8->new(substr $color, 1); + isf $col->convert_to(lc), $tests{$color}{lc()}, "convert $color to $_" for @spaces; + } +} else { + open my $fh, '<', 't/snapshot-rev4.csv'; + <$fh>; + + while (<$fh>) { + my ($color, @good) = split ','; + my $col = Convert::Color::RGB8->new($color); + isf $col->convert_to(lc), \@good, "convert $color to $_" for @spaces + } }