Skip to content

Commit 0821194

Browse files
committed
added test dummy for ncol space
1 parent d03aa96 commit 0821194

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

t/23_ncol_space.t

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/usr/bin/perl
2+
3+
use v5.12;
4+
use warnings;
5+
use Test::More tests => 40;
6+
7+
BEGIN { unshift @INC, 'lib', '../lib'}
8+
my $module = 'Graphics::Toolkit::Color::Space::Instance::YIQ';
9+
10+
my $def = eval "require $module";
11+
use Graphics::Toolkit::Color::Space::Util ':all';
12+
13+
is( not($@), 1, 'could load the module');
14+
is( ref $def, 'Graphics::Toolkit::Color::Space', 'got tight return value by loading module');
15+
is( $def->name, 'YIQ', 'color space has right name');
16+
is( $def->dimensions, 3, 'color space has 3 dimensions');
17+
is( $def->is_array([0,0,0]), 1, 'vector has 3 elements');
18+
is( $def->is_partial_hash({i => 1, quadrature => 0}), 1, 'found hash with some keys');
19+
is( $def->can_convert('rgb'), 1, 'do only convert from and to rgb');
20+
is( $def->can_convert('yiq'), 0, 'can not convert to itself');
21+
is( $def->format([0,0,0], 'css_string'), 'yiq(0,0,0)', 'can format css string');
22+
my @val = $def->deformat(['YIQ', 1, 0, -0.1]);
23+
is( int @val, 3, 'deformated value triplet (vector)');
24+
is( $val[0], 1, 'first value good');
25+
is( $val[1], 0, 'second value good');
26+
is( $val[2], -0.1, 'third value good');
27+
28+
ok( !$def->check([0, -0.5959, -0.5227]), 'check YIO values works on lower bound values');
29+
ok( !$def->check([1, 0.5959, 0.5227]), 'check YIO values works on upper bound values');
30+
warning_like {$def->check([0,0])} {carped => qr/needs 3 values/}, "check YIQ got too few values";
31+
warning_like {$def->check([0, 0, 0, 0])} {carped => qr/needs 3 values/}, "check YIQ got too many values";
32+
33+
is( $def->check([0,0,0]), undef, 'checked neutral values');
34+
warning_like {$def->check([-0.1, 0, 0])} {carped => qr/luminance value is below/}, "luminance value is too small";
35+
warning_like {$def->check([ 1.1, 0,0])} {carped => qr/luminance value is above/}, "luminance value is too big";
36+
warning_like {$def->check([0, -0.6, 0])} {carped => qr/in-phase value is below/}, "whiteness value is too small";
37+
warning_like {$def->check([0, 0.6,0])} {carped => qr/in-phase value is above/}, "whiteness value is too big";
38+
warning_like {$def->check([0,0, -0.53 ])} {carped => qr/quadrature value is below/},"quadrature value is too small";
39+
warning_like {$def->check([0,0, 0.53])} {carped => qr/quadrature value is above/}, "quadrature value is too big";
40+
41+
42+
43+
my @yiq = $def->deconvert( [ 0.5, 0.5, 0.5], 'RGB');
44+
is( int @yiq, 3, 'converted color grey has three YIQ values');
45+
is( $yiq[0], 0.5, 'converted color grey has computed right luminance value');
46+
is( $yiq[1], 0.5, 'converted color grey has computed right in-phase');
47+
is( $yiq[2], 0.5, 'converted color grey has computed right quadrature');
48+
49+
my @rgb = $def->convert( [0.5, 0.5, 0.5], 'RGB');
50+
is( int @rgb, 3, 'converted back color grey has three rgb values');
51+
is( $rgb[0], 0.5, 'converted back color grey has right red value');
52+
is( $rgb[1], 0.5, 'converted back color grey has right green value');
53+
is( $rgb[2], 0.5, 'converted back color grey has right blue value');
54+
55+
@yiq = $def->deconvert( [0.1, 0, 1], 'RGB');
56+
is( int @yiq, 3, 'converted blue has three YIQ values');
57+
is( close_enough( $yiq[0], 0.1439 ) , 1 , 'converted nice blue has right Y value');
58+
is( close_enough( $yiq[1], 0.280407787), 1 , 'converted nice blue has right I value');
59+
is( close_enough( $yiq[2], 0.817916587), 1 , 'converted nice blue has right Q value');
60+
61+
62+
@rgb = $def->convert( [0.1439, 0.280407787, 0.817916587], 'RGB');
63+
is( int @rgb, 3, 'converted back nice blue');
64+
is( close_enough($rgb[0], 0.1), 1, 'right red value');
65+
is( close_enough($rgb[1], 0 ), 1, 'right green value');
66+
is( close_enough($rgb[2], 1, ), 1, 'right blue value');
67+
68+
exit 0;

0 commit comments

Comments
 (0)