|
2 | 2 |
|
3 | 3 | use v5.12;
|
4 | 4 | use warnings;
|
5 |
| -use Test::More tests => 57; |
| 5 | +use Test::More tests => 92; |
6 | 6 |
|
7 |
| -BEGIN { unshift @INC, 'lib', '../lib'} |
| 7 | +BEGIN { unshift @INC, 'lib', '../lib', 't/lib'} |
8 | 8 | my $module = 'Graphics::Toolkit::Color::Space::Instance::LAB';
|
9 | 9 |
|
10 | 10 | my $space = eval "require $module";
|
11 | 11 | use Graphics::Toolkit::Color::Space::Util ':all';
|
| 12 | +#use Test::Color ':all'; |
12 | 13 |
|
13 | 14 | is( not($@), 1, 'could load the module');
|
14 | 15 | is( ref $space, 'Graphics::Toolkit::Color::Space', 'got tight return value by loading module');
|
@@ -44,69 +45,96 @@ is( $val->[2], -0.1, 'third value good');
|
44 | 45 | is( $space->format([0,1,0], 'css_string'), 'cielab(0, 1, 0)', 'can format css string');
|
45 | 46 |
|
46 | 47 | $val = $space->deconvert( [ 0, 0, 0], 'RGB');
|
47 |
| -is( ref $val, 'ARRAY', 'deconverted tuple of zeros'); |
| 48 | +is( ref $val, 'ARRAY', 'deconverted tuple of zeros (black)'); |
| 49 | +is( int @$val, 3, 'right amount of values'); |
| 50 | +is( close_enough( $val->[0] , 0), 1, 'first value good'); |
| 51 | +is( close_enough( $val->[1] , 0.5), 1, 'second value good'); |
| 52 | +is( close_enough( $val->[2] , 0.5), 1, 'third value good'); |
| 53 | + |
| 54 | +$val = $space->denormalize( [0, .5, .5] ); |
| 55 | +is( ref $val, 'ARRAY', 'denormalized deconverted tuple of zeros'); |
48 | 56 | is( int @$val, 3, 'right amount of values');
|
49 | 57 | is( close_enough( $val->[0] , 0), 1, 'first value good');
|
50 | 58 | is( close_enough( $val->[1] , 0), 1, 'second value good');
|
51 | 59 | is( close_enough( $val->[2] , 0), 1, 'third value good');
|
52 | 60 |
|
53 |
| -$val = $space->convert( [ 0, 0, 0], 'RGB'); |
54 |
| -is( ref $val, 'ARRAY', 'converted tuple of zeros'); |
55 |
| -is( int @$val, 3, 'right amount of values'); |
| 61 | +$val = $space->normalize( [0, 0, 0] ); |
| 62 | +is( ref $val, 'ARRAY', 'normalized tuple of zeros'); |
| 63 | +is( int @$val, 3, 'right amount of values'); |
| 64 | +is( close_enough( $val->[0] , 0), 1, 'first value good'); |
| 65 | +is( close_enough( $val->[1] , 0.5), 1, 'second value good'); |
| 66 | +is( close_enough( $val->[2] , 0.5), 1, 'third value good'); |
| 67 | + |
| 68 | +$val = $space->convert( [ 0, 0.5, 0.5], 'RGB'); |
| 69 | +is( ref $val, 'ARRAY', 'converted white to RGB'); |
| 70 | +is( int @$val, 3, 'right amount of values'); |
56 | 71 | is( close_enough( $val->[0] , 0), 1, 'first value good');
|
57 | 72 | is( close_enough( $val->[1] , 0), 1, 'second value good');
|
58 | 73 | is( close_enough( $val->[2] , 0), 1, 'third value good');
|
59 | 74 |
|
60 | 75 | $val = $space->deconvert( [ 1, 1, 1,], 'RGB');
|
61 |
| -is( ref $val, 'ARRAY', 'deconverted tuple of zeros'); |
| 76 | +is( ref $val, 'ARRAY', 'deconverted tuple of ones (white)'); |
| 77 | +is( int @$val, 3, 'right amount of values'); |
| 78 | +is( close_enough($val->[0], 1), 1, 'first value good'); |
| 79 | +is( close_enough($val->[1], 0.5), 1, 'second value good'); |
| 80 | +is( close_enough($val->[2], 0.5), 1, 'third value good'); |
| 81 | + |
| 82 | +$val = $space->convert( [ 1, 0.5, 0.5], 'RGB'); |
| 83 | +is( ref $val, 'ARRAY', 'converted tuple of zeros'); |
62 | 84 | is( int @$val, 3, 'right amount of values');
|
63 | 85 | is( close_enough( $val->[0] , 1), 1, 'first value good');
|
| 86 | +is( close_enough( $val->[1] , 1), 1, 'second value good'); |
| 87 | +is( close_enough( $val->[2] , 1), 1, 'third value good'); |
| 88 | + |
| 89 | +$val = $space->deconvert( [ 0.5, 0.5, 0.5], 'RGB'); |
| 90 | +is( ref $val, 'ARRAY', 'converted gray to RGB'); |
| 91 | +is( int @$val, 3, 'right amount of values'); |
| 92 | +is( close_enough( $val->[0] , .53389), 1, 'first value good'); |
| 93 | +is( close_enough( $val->[1] , .5), 1, 'second value good'); |
| 94 | +is( close_enough( $val->[2] , .5), 1, 'third value good'); |
| 95 | + |
| 96 | +$val = $space->denormalize( [0.53389, .5, .5] ); |
| 97 | +is( ref $val, 'ARRAY', 'denormalized deconverted gray'); |
| 98 | +is( int @$val, 3, 'right amount of values'); |
| 99 | +is( close_enough( $val->[0] , 53.389), 1, 'first value good'); |
64 | 100 | is( close_enough( $val->[1] , 0), 1, 'second value good');
|
65 |
| -is( $val->[2], 1, 'third value good'); |
66 |
| - |
67 |
| - |
68 |
| -exit 0; |
| 101 | +is( close_enough( $val->[2] , 0), 1, 'third value good'); |
69 | 102 |
|
70 |
| -my @xyz = $space->deconvert( [ 0.5, 0.5, 0.5], 'RGB'); |
71 |
| -is( int @xyz, 3, 'converted color grey has three XYZ values'); |
72 |
| -is( close_enough($xyz[0], 0.20344), 1, 'converted color grey has computed right X value'); |
73 |
| -is( close_enough($xyz[1], 0.21404), 1, 'converted color grey has computed right Y value'); |
74 |
| -is( close_enough($xyz[2], 0.23305), 1, 'converted color grey has computed right Z value'); |
75 |
| - |
76 |
| -@xyz = $space->deconvert( [ 1, 1, 1], 'RGB'); |
77 |
| -is( int @xyz, 3, 'converted color white has three XYZ values'); |
78 |
| -is( close_enough($xyz[0], 0.95047), 1, 'converted color white has computed right X value'); |
79 |
| -is( close_enough($xyz[1], 1), 1, 'converted color white has computed right Y value'); |
80 |
| -is( close_enough($xyz[2], 1.08883), 1, 'converted color white has computed right Z value'); |
81 |
| - |
82 |
| -@xyz = $space->deconvert( [ 1, 0, 0.5], 'RGB'); |
83 |
| -is( int @xyz, 3, 'converted color pink has three XYZ values'); |
84 |
| -is( close_enough($xyz[0], 0.45108), 1, 'converted color pink has computed right X value'); |
85 |
| -is( close_enough($xyz[1], 0.22821), 1, 'converted color pink has computed right Y value'); |
86 |
| -is( close_enough($xyz[2], 0.22274), 1, 'converted color pink has computed right Z value'); |
87 |
| - |
88 |
| -my @rgb = $space->convert( [0, 0, 0], 'RGB'); |
89 |
| -is( int @rgb, 3, 'converted back black with 3 values'); |
90 |
| -is( close_enough($rgb[0], 0), 1, 'right red value'); |
91 |
| -is( close_enough($rgb[1], 0), 1, 'right green value'); |
92 |
| -is( close_enough($rgb[2], 0), 1, 'right blue value'); |
93 |
| - |
94 |
| -@rgb = $space->convert( [0.20344, 0.21404, 0.23305], 'RGB'); |
95 |
| -is( int @rgb, 3, 'converted back gray with 3 values'); |
96 |
| -is( close_enough($rgb[0], 0.5), 1, 'right red value'); |
97 |
| -is( close_enough($rgb[1], 0.5), 1, 'right green value'); |
98 |
| -is( close_enough($rgb[2], 0.5), 1, 'right blue value'); |
99 |
| - |
100 |
| -@rgb = $space->convert( [0.95047, 1, 1.08883], 'RGB'); |
101 |
| -is( int @rgb, 3, 'converted back gray with 3 values'); |
102 |
| -is( close_enough($rgb[0], 1), 1, 'right red value'); |
103 |
| -is( close_enough($rgb[1], 1), 1, 'right green value'); |
104 |
| -is( close_enough($rgb[2], 1), 1, 'right blue value'); |
105 |
| - |
106 |
| -@rgb = $space->convert( [0.45108, 0.22821, 0.22274], 'RGB'); |
107 |
| -is( int @rgb, 3, 'converted back gray with 3 values'); |
108 |
| -is( close_enough($rgb[0], 1 ), 1, 'right red value'); |
109 |
| -is( close_enough($rgb[1], 0 ), 1, 'right green value'); |
110 |
| -is( close_enough($rgb[2], 0.5), 1, 'right blue value'); |
| 103 | +$val = $space->convert( [ 0.53389, .5, .5], 'RGB'); |
| 104 | +is( ref $val, 'ARRAY', 'converted back gray to RGB'); |
| 105 | +is( int @$val, 3, 'right amount of values'); |
| 106 | +is( close_enough( $val->[0] , .5), 1, 'first value good'); |
| 107 | +is( close_enough( $val->[1] , .5), 1, 'second value good'); |
| 108 | +is( close_enough( $val->[2] , .5), 1, 'third value good'); |
| 109 | + |
| 110 | + |
| 111 | +$val = $space->deconvert( [ 1, 0, 0.5], 'RGB'); |
| 112 | +is( ref $val, 'ARRAY', 'converted purple from RGB'); |
| 113 | +is( int @$val, 3, 'right amount of values'); |
| 114 | +is( close_enough( $val->[0] , .54878), 1, 'first value good'); |
| 115 | +is( close_enough( $val->[1] , .584499), 1, 'second value good'); |
| 116 | +is( close_enough( $val->[2] , .5109), 1, 'third value good'); |
| 117 | + |
| 118 | +$val = $space->convert( [ 0.54878, .584499, .5109], 'RGB'); |
| 119 | +is( ref $val, 'ARRAY', 'converted back gray to RGB'); |
| 120 | +is( int @$val, 3, 'right amount of values'); |
| 121 | +is( close_enough( $val->[0] , 1), 1, 'first value good'); |
| 122 | +is( close_enough( $val->[1] , 0), 1, 'second value good'); |
| 123 | +is( close_enough( $val->[2] , .5), 1, 'third value good'); |
| 124 | + |
| 125 | + |
| 126 | +$val = $space->deconvert( [ .1, 0.2, 0.9], 'RGB'); |
| 127 | +is( ref $val, 'ARRAY', 'converted BLUE from RGB'); |
| 128 | +is( int @$val, 3, 'right amount of values'); |
| 129 | +is( close_enough( $val->[0] , .34526), 1, 'first value good'); |
| 130 | +is( close_enough( $val->[1] , .557165), 1, 'second value good'); |
| 131 | +is( close_enough( $val->[2] , .2757375),1, 'third value good'); |
| 132 | + |
| 133 | +$val = $space->convert( [ 0.34526, .557165, .2757375], 'RGB'); |
| 134 | +is( ref $val, 'ARRAY', 'converted back BLUE to RGB'); |
| 135 | +is( int @$val, 3, 'right amount of values'); |
| 136 | +is( close_enough( $val->[0] , .1), 1, 'first value good'); |
| 137 | +is( close_enough( $val->[1] , .2), 1, 'second value good'); |
| 138 | +is( close_enough( $val->[2] , .9), 1, 'third value good'); |
111 | 139 |
|
112 | 140 | exit 0;
|
0 commit comments