11module Test.Main where
22
33import Prelude
4- import Color (Color , ColorSpace (..), rgb' , toHexString , toRGBA , toHSLA , saturate , lighten , white , black , graytone , mix , rgb , distance , textColor , contrast , luminance , brightness , fromInt , toGray , desaturate , darken , complementary , rotateHue , rgba , cssStringRGBA , hsla , cssStringHSLA , hsl , fromHexString , lch , toLCh , lab , toLab , xyz , toXYZ )
4+
5+ import Color (Color , ColorSpace (..), rgb' , toHexString , toRGBA , toHSLA , toHSVA , saturate , lighten , white , black , graytone , mix , rgb , distance , textColor , contrast , luminance , brightness , fromInt , toGray , desaturate , darken , complementary , rotateHue , rgba , cssStringRGBA , hsla , cssStringHSLA , hsl , hsva , fromHexString , lch , toLCh , lab , toLab , xyz , toXYZ )
56import Color.Blending (BlendMode (..), blend )
67import Color.Scale (grayscale , sample , colors , uniformScale , colorStop , colorScale )
78import Color.Scheme.X11 (orangered , seagreen , yellow , red , blue , magenta , hotpink , purple , pink , darkslateblue , aquamarine , cyan , green , lime )
@@ -24,20 +25,20 @@ import Test.Unit.Main (runTest)
2425almostEqual :: forall e . Color -> Color -> Aff e Unit
2526almostEqual expected actual =
2627 if almostEqual' expected actual then success
27- else failure $ " \n expected: " <> show expected <>
28- " \n got: " <> show actual
29-
30- where
31- abs n = if n < 0 then 0 - n else n
32- aE n1 n2 = abs (n1 - n2) <= 1
33- almostEqual' col1 col2 =
34- aE c1.r c2.r &&
35- aE c1.g c2.g &&
36- aE c1.b c2.b
37-
38- where
39- c1 = toRGBA col1
40- c2 = toRGBA col2
28+ else failure $ " \n expected: " <> show' expected <>
29+ " \n got: " <> show' actual
30+ where
31+ show' c = case toHSLA c of
32+ {h, s, l, a} -> cssStringRGBA c <> " " <> cssStringHSLA c
33+ abs n = if n < 0 then 0 - n else n
34+ aE n1 n2 = abs (n1 - n2) <= 1
35+ almostEqual' col1 col2 =
36+ aE c1.r c2.r &&
37+ aE c1.g c2.g &&
38+ aE c1.b c2.b
39+ where
40+ c1 = toRGBA col1
41+ c2 = toRGBA col2
4142
4243main :: forall e . Eff (console :: CONSOLE , testOutput :: TESTOUTPUT , avar :: AVAR | e ) Unit
4344main = runTest do
@@ -123,6 +124,27 @@ main = runTest do
123124 hue <- 0 .. 360
124125 pure $ xyzRoundtrip (toNumber hue) 0.2 0.8
125126
127+ test " hsv / toHSV (HSV -> HSL -> HSV, HSL -> HSV -> HSL)" do
128+ let
129+ hsvRoundtrip h' s' l_v' a' = do
130+ almostEqual colorIn1 colorOut1
131+ almostEqual colorIn2 colorOut2
132+ where
133+ colorIn1 = hsla h' s' l_v' a'
134+ colorIn2 = hsva h' s' l_v' a'
135+ colorOut1 = case toHSVA colorIn1 of { h, s, v, a } -> hsva h s v a
136+ colorOut2 = case toHSVA colorIn2 of { h, s, v, a } -> hsva h s v a
137+ sequence_ do
138+ hue <- 0 .. 3
139+ saturation <- 0 .. 5
140+ lightness <- 0 .. 5
141+ [ hsvRoundtrip 90.0 (toNumber saturation / 5.0 ) 1.0 1.0
142+ , hsvRoundtrip 90.0 1.0 (toNumber lightness / 5.0 ) 1.0
143+ , hsvRoundtrip 90.0 (toNumber saturation / 5.0 ) 0.0 1.0
144+ , hsvRoundtrip 90.0 0.0 (toNumber lightness / 5.0 ) 1.0
145+ , hsvRoundtrip (toNumber (hue * 90 )) (toNumber saturation / 5.0 ) (toNumber lightness / 5.0 ) 1.0
146+ ]
147+
126148 test " lab / toLab (Lab -> HSL -> Lab)" do
127149 let labRoundtrip h' s' l' =
128150 case toLab col of
0 commit comments