Convert snapshot to CSV for faster tests and a smaller dist
[convert-color-husl.git] / t / Convert-Color-HUSL.t
index 9d993e432a016cb9e2d85c451c8a3f862dfcd0a7..42aab41f1f92ddf650fbf17c6c317d8a0ccb94d7 100644 (file)
@@ -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
+       }
 }
This page took 0.009718 seconds and 4 git commands to generate.