File: 24hsl-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,504 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::HSL;

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

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

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

is( $black->dst_hsl( $red   ), NEAR_SQRT1d25_OVER_2, 'black->dst_hsl red' );
is( $black->dst_hsl( $green ), NEAR_SQRT1d25_OVER_2, 'black->dst_hsl green' );
is( $black->dst_hsl( $blue  ), NEAR_SQRT1d25_OVER_2, 'black->dst_hsl blue' );

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

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

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

is( $black->dst_hsl_cheap( $red   ), 1.25, 'black->dst_hsl_cheap red' );
is( $black->dst_hsl_cheap( $green ), 1.25, 'black->dst_hsl_cheap green' );
is( $black->dst_hsl_cheap( $blue  ), 1.25, 'black->dst_hsl_cheap blue' );

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

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

done_testing;