File: 23hsv-dst.t

package info (click to toggle)
libconvert-color-perl 0.18-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 276 kB
  • sloc: perl: 1,760; makefile: 2
file content (43 lines) | stat: -rw-r--r-- 1,466 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/perl

use v5.14;
use warnings;

use Test2::V0;
use Test2::Tools::Compare;

use Convert::Color::HSV;

use constant {
   NEAR_1_OVER_SQRT2 => Test2::Tools::Compare::float( 1/sqrt(2), tolerance => 1e-6 ),
   NEAR_1_OVER_2     => Test2::Tools::Compare::float( 1/2,       tolerance => 1e-6 ),
};

my $black = Convert::Color::HSV->new(   0, 1, 0 );
my $white = Convert::Color::HSV->new(   0, 0, 1 );
my $red   = Convert::Color::HSV->new(   0, 1, 1 );
my $green = Convert::Color::HSV->new( 120, 1, 1 );
my $cyan  = Convert::Color::HSV->new( 180, 1, 1 );
my $blue  = Convert::Color::HSV->new( 240, 1, 1 );

is( $black->dst_hsv( $black ), 0, 'black->dst_hsv black' );

is( $black->dst_hsv( $red   ), NEAR_1_OVER_SQRT2, 'black->dst_hsv red' );
is( $black->dst_hsv( $green ), NEAR_1_OVER_SQRT2, 'black->dst_hsv green' );
is( $black->dst_hsv( $blue  ), NEAR_1_OVER_SQRT2, 'black->dst_hsv blue' );

is( $black->dst_hsv( $white ), NEAR_1_OVER_2, 'black->dst_hsv white' );

is( $red->dst_hsv( $cyan ), 1, 'red->dst_hsv cyan' );

is( $black->dst_hsv_cheap( $black ), 0, 'black->dst_hsv_cheap black' );

is( $black->dst_hsv_cheap( $red   ), 2, 'black->dst_hsv_cheap red' );
is( $black->dst_hsv_cheap( $green ), 2, 'black->dst_hsv_cheap green' );
is( $black->dst_hsv_cheap( $blue  ), 2, 'black->dst_hsv_cheap blue' );

is( $black->dst_hsv_cheap( $white ), 1, 'black->dst_hsv_cheap white' );

is( $red->dst_hsv_cheap( $cyan ), 4, 'red->dst_hsv_cheap cyan' );

done_testing;