diff options
Diffstat (limited to 'stdlib/source/test/lux/data/color.lux')
-rw-r--r-- | stdlib/source/test/lux/data/color.lux | 45 |
1 files changed, 23 insertions, 22 deletions
diff --git a/stdlib/source/test/lux/data/color.lux b/stdlib/source/test/lux/data/color.lux index ee3bdffb1..79e771ce9 100644 --- a/stdlib/source/test/lux/data/color.lux +++ b/stdlib/source/test/lux/data/color.lux @@ -9,7 +9,8 @@ [data ["%" text/format (#+ format)] [number - ["." frac]]] + ["." int] + ["f" frac]]] ["." math ["r" random (#+ Random)]]] {1 @@ -22,7 +23,7 @@ (def: scale (-> Nat Frac) - (|>> .int int-to-frac)) + (|>> .int int.frac)) (def: square (-> Frac Frac) (math.pow +2.0)) @@ -30,10 +31,10 @@ (-> Color Color Frac) (let [[fr fg fb] (/.to-rgb from) [tr tg tb] (/.to-rgb to)] - (math.pow +0.5 ($_ f/+ - (|> (scale tr) (f/- (scale fr)) square) - (|> (scale tg) (f/- (scale fg)) square) - (|> (scale tb) (f/- (scale fb)) square))))) + (math.pow +0.5 ($_ f.+ + (|> (scale tr) (f.- (scale fr)) square) + (|> (scale tg) (f.- (scale fg)) square) + (|> (scale tb) (f.- (scale fb)) square))))) (def: error-margin Frac +1.8) @@ -56,32 +57,32 @@ (do r.monad [any ..color colorful (|> color - (r.filter (function (_ color) (|> (distance color black) (f/>= +100.0)))) - (r.filter (function (_ color) (|> (distance color white) (f/>= +100.0))))) + (r.filter (function (_ color) (|> (distance color black) (f.>= +100.0)))) + (r.filter (function (_ color) (|> (distance color white) (f.>= +100.0))))) mediocre (|> color (r.filter (|>> saturation ((function (_ saturation) - (and (f/>= +0.25 saturation) - (f/<= +0.75 saturation))))))) - ratio (|> r.safe-frac (r.filter (f/>= +0.5)))] + (and (f.>= +0.25 saturation) + (f.<= +0.75 saturation))))))) + ratio (|> r.safe-frac (r.filter (f.>= +0.5)))] ($_ _.and ($equivalence.spec /.equivalence ..color) (_.test "Can convert to/from HSL." (|> any /.to-hsl /.from-hsl (distance any) - (f/<= error-margin))) + (f.<= error-margin))) (_.test "Can convert to/from HSB." (|> any /.to-hsb /.from-hsb (distance any) - (f/<= error-margin))) + (f.<= error-margin))) (_.test "Can convert to/from CMYK." (|> any /.to-cmyk /.from-cmyk (distance any) - (f/<= error-margin))) + (f.<= error-margin))) (_.test "Can interpolate between 2 colors." - (and (f/<= (distance colorful black) + (and (f.<= (distance colorful black) (distance (/.darker ratio colorful) black)) - (f/<= (distance colorful white) + (f.<= (distance colorful white) (distance (/.brighter ratio colorful) white)))) (_.test "Can calculate complement." (let [~any (/.complement any) @@ -89,17 +90,17 @@ (and (not (/@= any ~any)) (/@= any (/.complement ~any))))) (_.test "Can saturate color." - (f/> (saturation mediocre) + (f.> (saturation mediocre) (saturation (/.saturate ratio mediocre)))) (_.test "Can de-saturate color." - (f/< (saturation mediocre) + (f.< (saturation mediocre) (saturation (/.de-saturate ratio mediocre)))) (_.test "Can gray-scale color." (let [gray'ed (/.gray-scale mediocre)] - (and (f/= +0.0 + (and (f.= +0.0 (saturation gray'ed)) (|> (luminance gray'ed) - (f/- (luminance mediocre)) - frac.abs - (f/<= error-margin))))) + (f.- (luminance mediocre)) + f.abs + (f.<= error-margin))))) )))) |