projects
/
convert-color-husl.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
b7799d3
)
Improve tests by also testing reverse conversions
author
Marius Gavrilescu
<marius@ieval.ro>
Wed, 8 Jul 2015 22:13:30 +0000
(
01:13
+0300)
committer
Marius Gavrilescu
<marius@ieval.ro>
Thu, 9 Jul 2015 12:05:55 +0000
(15:05 +0300)
t/Convert-Color-HUSL.t
patch
|
blob
|
blame
|
history
diff --git
a/t/Convert-Color-HUSL.t
b/t/Convert-Color-HUSL.t
index e5e16736f105835f12b3d791d0f5f8370aa697c3..3474d3cdcdca8e0f93b257f5ec1e0714ee0de0ce 100644
(file)
--- a/
t/Convert-Color-HUSL.t
+++ b/
t/Convert-Color-HUSL.t
@@
-4,35
+4,45
@@
use strict;
use warnings;
use Convert::Color::RGB8;
use warnings;
use Convert::Color::RGB8;
-use JSON::PP qw/decode_json/;
-use Test::More tests => 5 * 4096;
+use Test::More tests => 7 * ($ENV{RELEASE_TESTING} ? 4096 : 512);
use constant EPSILON => $ENV{RELEASE_TESTING} ? 1e-11 : 2e-4;
my @spaces = qw/XYZ LUV LCh HUSL HUSLp/;
sub isf {
use constant EPSILON => $ENV{RELEASE_TESTING} ? 1e-11 : 2e-4;
my @spaces = qw/XYZ LUV LCh HUSL HUSLp/;
sub isf {
- my ($x, $y, $name) = @_;
- ok !grep({ abs ($_ - shift @$y) > EPSILON } @$x), $name;
+ my ($xx, $yy, $name) = @_;
+ for (0 .. 2) {
+ my ($x, $y) = ($xx->[$_], $yy->[$_]);
+ do { diag "$x != $y"; return fail $name } if abs ($x - $y) > EPSILON;
+ }
+ pass $name;
}
}
+my @tests;
+
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};
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;
- }
+ @tests = map { [$_, $tests{$_}] } sort keys %tests;
} else {
open my $fh, '<', 't/snapshot-rev4.csv';
<$fh>;
while (<$fh>) {
my ($color, @good) = split ',';
} 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
+ my %test;
+ $test{rgb} = [Convert::Color::RGB8->new($color)->rgb];
+ $test{lc $spaces[$_]} = [@good[$_ * 3 .. $_ * 3 + 2]] for 0 .. $#spaces;
+ push @tests, ["#$color", \%test]
}
}
}
}
+
+for my $test (@tests) {
+ my ($color, $data) = @$test;
+ my $col = Convert::Color::RGB8->new(substr $color, 1);
+ isf $col->convert_to(lc), $data->{lc()}, "convert $color to $_" for @spaces;
+ isf [$col->convert_to(lc)->rgb], $data->{rgb}, "convert $color to $_ and back" for qw/HUSL HUSLp/;
+}
This page took
0.010496 seconds
and
4
git commands to generate.