Skip to content

Commit 7c408ed

Browse files
committed
fixed NCol tests
1 parent 7a4f381 commit 7c408ed

File tree

2 files changed

+52
-94
lines changed

2 files changed

+52
-94
lines changed

lib/Graphics/Toolkit/Color/Space/Instance/NCol.pm

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ my $hsl_def = Graphics::Toolkit::Color::Space->new( name => 'NCol',
1111
axis => [qw/hue whiteness blackness/],
1212
type => [qw/angular linear linear/],
1313
range => [600, 100, 100], precision => 0,
14-
value_form => ['[RYGCBM]\d{2}','\d{2}','\d{2}'],
14+
value_form => ['[RYGCBM]\d{1,2}','\d{1,2}','\d{1,2}'],
1515
suffix => ['', '%', '%'],
1616
);
1717

@@ -24,13 +24,13 @@ my %pos = (map { $letter[$_] => $_ } 0 .. $#letter);
2424
sub pre_value {
2525
my $val = shift;
2626
my $hue = $pos{ substr($val->[0], 0, 1) } * 100 + substr($val->[0], 1);
27-
[$hue, $val->[1], $val->[2]];
27+
return [$hue, $val->[1], $val->[2]];
2828
}
2929
sub post_value {
3030
my $val = shift;
3131
my $h = int($val->[0] / 100);
32-
my $hue = $letter[ $h ] . sprintf "%02u", $val->[0] - $h;
33-
[$hue, $val->[1], $val->[2]];
32+
my $hue = $letter[ $h ] . sprintf( "%02u", ($val->[0] - $h*100));
33+
return [$hue, $val->[1], $val->[2]];
3434
}
3535

3636
sub from_rgb {
@@ -72,4 +72,3 @@ sub to_rgb {
7272
}
7373

7474
$hsl_def;
75-

t/17_ncol_space.t

Lines changed: 48 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
use v5.12;
44
use warnings;
5-
use Test::More tests => 40;
5+
use Test::More tests => 70;
66

77
BEGIN { unshift @INC, 'lib', '../lib'}
88
my $module = 'Graphics::Toolkit::Color::Space::Instance::NCol';
@@ -15,82 +15,59 @@ is( ref $def, 'Graphics::Toolkit::Color::Space', 'got tight return value by load
1515
is( $def->name, 'NCol', 'color space has right name');
1616
is( $def->axis, 3, 'color space has 3 axis');
1717
is( $def->is_value_tuple([0,0,0]), 1, 'value tuple has 3 elements');
18-
19-
exit 0;
20-
is( $def->is_partial_hash({whiteness => 1, blackness => 0}), 1, 'found hash with some keys');
18+
is( $def->is_partial_hash({whiteness => 1, blackness => 0}), 1, 'found hash with some axis name');
19+
is( $def->is_partial_hash({what => 1, blackness => 0}), 0, 'found hash with a bad axis name');
2120
is( $def->can_convert('rgb'), 1, 'do only convert from and to rgb');
2221
is( $def->can_convert('yiq'), 0, 'can not convert to itself');
23-
is( $def->format([0,0,0], 'css_string'), 'ncol(0, 0%, 0%)', 'can format css string');
24-
my $val = $def->deformat(['NCol', 1, 0, -0.1]);
25-
is( ref $val, 'ARRAY', 'deformated named array into tuple (ARRAY)');
26-
is( int @$val, 3, 'deformated value triplet (vector)');
27-
is( $val->[0], 1, 'first value good');
28-
is( $val->[1], 0, 'second value good');
29-
is( $val->[2], -0.1, 'third value good');
30-
31-
ok( !$def->check([0, -0.5959, -0.5227]), 'check YIO values works on lower bound values');
32-
ok( !$def->check([1, 0.5959, 0.5227]), 'check YIO values works on upper bound values');
33-
warning_like {$def->check([0,0])} {carped => qr/needs 3 values/}, "check YIQ got too few values";
34-
warning_like {$def->check([0, 0, 0, 0])} {carped => qr/needs 3 values/}, "check YIQ got too many values";
35-
36-
is( $def->check([0,0,0]), undef, 'checked neutral values');
37-
warning_like {$def->check([-0.1, 0, 0])} {carped => qr/luminance value is below/}, "luminance value is too small";
38-
warning_like {$def->check([ 1.1, 0,0])} {carped => qr/luminance value is above/}, "luminance value is too big";
39-
warning_like {$def->check([0, -0.6, 0])} {carped => qr/in-phase value is below/}, "whiteness value is too small";
40-
warning_like {$def->check([0, 0.6,0])} {carped => qr/in-phase value is above/}, "whiteness value is too big";
41-
warning_like {$def->check([0,0, -0.53 ])} {carped => qr/quadrature value is below/},"quadrature value is too small";
42-
warning_like {$def->check([0,0, 0.53])} {carped => qr/quadrature value is above/}, "quadrature value is too big";
43-
44-
45-
46-
my @yiq = $def->deconvert( [ 0.5, 0.5, 0.5], 'RGB');
47-
is( int @yiq, 3, 'converted color grey has three YIQ values');
48-
is( $yiq[0], 0.5, 'converted color grey has computed right luminance value');
49-
is( $yiq[1], 0.5, 'converted color grey has computed right in-phase');
50-
is( $yiq[2], 0.5, 'converted color grey has computed right quadrature');
51-
52-
my @rgb = $def->convert( [0.5, 0.5, 0.5], 'RGB');
53-
is( int @rgb, 3, 'converted back color grey has three rgb values');
54-
is( $rgb[0], 0.5, 'converted back color grey has right red value');
55-
is( $rgb[1], 0.5, 'converted back color grey has right green value');
56-
is( $rgb[2], 0.5, 'converted back color grey has right blue value');
57-
58-
@yiq = $def->deconvert( [0.1, 0, 1], 'RGB');
59-
is( int @yiq, 3, 'converted blue has three YIQ values');
60-
is( close_enough( $yiq[0], 0.1439 ) , 1 , 'converted nice blue has right Y value');
61-
is( close_enough( $yiq[1], 0.280407787), 1 , 'converted nice blue has right I value');
62-
is( close_enough( $yiq[2], 0.817916587), 1 , 'converted nice blue has right Q value');
63-
64-
65-
@rgb = $def->convert( [0.1439, 0.280407787, 0.817916587], 'RGB');
66-
is( int @rgb, 3, 'converted back nice blue');
67-
is( close_enough($rgb[0], 0.1), 1, 'right red value');
68-
is( close_enough($rgb[1], 0 ), 1, 'right green value');
69-
is( close_enough($rgb[2], 1, ), 1, 'right blue value');
70-
71-
exit 0;
7222

73-
__END__
74-
is( not($@), 1, 'could load the module');
75-
is( ref $def, 'Graphics::Toolkit::Color::Space', 'got tight return value by loading module');
76-
is( $def->name, 'HWB', 'color space has right name');
77-
is( $def->axis, 3, 'color space has 3 axis');
7823
is( ref $def->in_range([0, 0, 0]), 'ARRAY', 'check HWB values works on lower bound values');
79-
is( ref $def->in_range([360,100,100]), 'ARRAY', 'check HWB values works on upper bound values');
24+
is( ref $def->in_range([600,100,100]), 'ARRAY', 'check HWB values works on upper bound values');
8025
is( ref $def->in_range([0,0]), '', "HWB got too few values");
8126
is( ref $def->in_range([0, 0, 0, 0]), '', "HWB got too many values");
8227
is( ref $def->in_range([-1, 0, 0]), '', "hue value is too small");
8328
is( ref $def->in_range([1.1, 0, 0]), '', "hue is not integer");
84-
is( ref $def->in_range([361, 0, 0]), '', "hue value is too big");
29+
is( ref $def->in_range([601, 0, 0]), '', "hue value is too big");
8530
is( ref $def->in_range([0, -1, 0]), '', "whiteness value is too small");
8631
is( ref $def->in_range([0, 1.1, 0]), '', "whiteness value is not integer");
8732
is( ref $def->in_range([0, 101, 0]), '', "whiteness value is too big");
8833
is( ref $def->in_range([0, 0, -1 ] ), '', "blackness value is too small");
8934
is( ref $def->in_range([0, 0, 1.1] ), '', "blackness value is not integer");
9035
is( ref $def->in_range([0, 0, 101] ), '', "blackness value is too big");
9136

92-
my $val = $def->round([1,22.5, 11.111111]);
93-
is( ref $val, 'ARRAY', 'rounded value tuple int tuple');
37+
38+
is( $def->format([0,0,0], 'css_string'), 'ncol(R00, 0%, 0%)', 'can format css string');
39+
is( $def->format([212,34,56], 'css_string'), 'ncol(G12, 34%, 56%)', 'can format css string');
40+
41+
my $val = $def->deformat('ncol(R00, 0%, 0%)');
42+
is( ref $val, 'ARRAY', 'deformated CSS string into tuple (ARRAY)');
43+
is( int @$val, 3, 'deformated value triplet (tuple)');
44+
is( $val->[0], 0, 'first value good');
45+
is( $val->[1], 0, 'second value good');
46+
is( $val->[2], 0, 'third value good');
47+
$val = $def->deformat('ncol(G12, 34%, 56%)');
48+
is( ref $val, 'ARRAY', 'deformated CSS string into tuple (ARRAY)');
49+
is( int @$val, 3, 'deformated value triplet (tuple)');
50+
is( $val->[0], 212, 'first value good');
51+
is( $val->[1], 34, 'second value good');
52+
is( $val->[2], 56, 'third value good');
53+
$val = $def->deformat('ncol(G12, 34%, 56.1%)');
54+
is( ref $val, '', 'can not deformat with CSS string with ill formatted values');
55+
$val = $def->deformat(['NCol', 'B20', '31%', '15']);
56+
is( ref $val, 'ARRAY', 'deformated named ARRAY into tuple (ARRAY)');
57+
is( int @$val, 3, 'deformated into value triplet (tuple)');
58+
is( $val->[0], 420, 'first value good');
59+
is( $val->[1], 31, 'second value good');
60+
is( $val->[2], 15, 'third value good');
61+
62+
$val = $def->clamp([700,1.1,-2]);
63+
is( ref $val, 'ARRAY', 'clampd value tuple into tuple');
64+
is( int @$val, 3, 'right amount of values');
65+
is( $val->[0], 100, 'first value rotated in');
66+
is( $val->[1], 1, 'second value rounded');
67+
is( $val->[2], 0, 'third value clamped up');
68+
69+
$val = $def->round([1,22.5, 11.111111]);
70+
is( ref $val, 'ARRAY', 'rounded value tuple into tuple');
9471
is( int @$val, 3, 'right amount of values');
9572
is( $val->[0], 1, 'first value kept');
9673
is( $val->[1], 23, 'second value rounded up');
@@ -109,43 +86,25 @@ is( $rgb->[1], 0.5, 'converted back color grey has right green value');
10986
is( $rgb->[2], 0.5, 'converted back color grey has right blue value');
11087

11188
$hwb = $def->deconvert( [210/255, 20/255, 70/255], 'RGB');
112-
is( int @$hwb, 3, 'converted nice magents has three hwb values');
113-
is( close_enough( $hwb->[0], 0.95555), 1, 'converted nice magenta has computed right hue value');
89+
is( int @$hwb, 3, 'converted nice magents has three hwb values');
90+
is( close_enough( $hwb->[0], 0.95555), 1, 'converted nice magenta has computed right hue value');
11491
is( close_enough( $hwb->[1], 0.08, ), 1, 'converted nice magenta has computed right whiteness');
11592
is( close_enough( $hwb->[2], 0.18, ), 1, 'converted nice magenta has computed right blackness');
11693

11794
$rgb = $def->convert( [0.95555, 0.08, 0.18], 'RGB');
118-
is( int @$rgb, 3, 'converted back nice magenta');
95+
is( int @$rgb, 3, 'converted back nice magenta');
11996
is( close_enough( $rgb->[0], 210/255), 1, 'right red value');
12097
is( close_enough( $rgb->[1], 20/255) , 1, 'right green value');
12198
is( close_enough( $rgb->[2], 70/255) , 1, 'right blue value');
12299

123100
$rgb = $def->convert( [0.83333, 0, 1], 'RGB'); # should become black despite color value
124-
is( int @$rgb, 3, 'converted black');
125-
is( $rgb->[0], 0, 'right red value');
126-
is( $rgb->[1], 0, 'right green value');
127-
is( $rgb->[2], 0, 'right blue value');
101+
is( int @$rgb, 3, 'converted black');
102+
is( $rgb->[0], 0, 'right red value');
103+
is( $rgb->[1], 0, 'right green value');
104+
is( $rgb->[2], 0, 'right blue value');
128105

129-
$val = $def->form->remove_suffix([qw/360 100% 100%/]);
130-
is( ref $val, 'ARRAY', 'value tuple without suffixes is a tuple');
131-
is( int @$val, 3, 'right amount of values');
132-
is( $val->[0], 360, 'first value is right');
133-
is( $val->[1], 100, 'second value right');
134-
is( $val->[2], 100, 'third value right');
135106

136-
$val = $def->deformat('hwb(240, 88%, 22%)');
137-
is( ref $val, 'ARRAY', 'deformated CSS string into value tuple');
138-
is( int @$val, 3, 'right amount of values');
139-
is( $val->[0], 240, 'first value is right');
140-
is( $val->[1], 88, 'second value right');
141-
is( $val->[2], 22, 'third value right');
107+
exit 0;
142108

143-
$val = $def->deformat('hwb(240, 88, 22)');
144-
is( ref $val, 'ARRAY', 'deformated CSS string without suffix into value tuple');
145-
is( int @$val, 3, 'right amount of values');
146-
is( $val->[0], 240, 'first value is right');
147-
is( $val->[1], 88, 'second value right');
148-
is( $val->[2], 22, 'third value right');
109+
__END__
149110
150-
is( $def->format([240, 88, 22], 'css_string'), 'hwb(240, 88%, 22%)', 'converted tuple into css string');
151-
is( $def->format([240, 88, 22], 'css_string', ''), 'hwb(240, 88, 22)', 'converted tuple into css string without suffixes');

0 commit comments

Comments
 (0)