diff options
Diffstat (limited to 'stdlib/source/test/lux/data')
| -rw-r--r-- | stdlib/source/test/lux/data/color.lux | 10 | ||||
| -rw-r--r-- | stdlib/source/test/lux/data/color/cmyk.lux | 90 | 
2 files changed, 94 insertions, 6 deletions
| diff --git a/stdlib/source/test/lux/data/color.lux b/stdlib/source/test/lux/data/color.lux index e53d5d0b7..7434e8c15 100644 --- a/stdlib/source/test/lux/data/color.lux +++ b/stdlib/source/test/lux/data/color.lux @@ -24,6 +24,7 @@     ["[0]" rgb]]]   ["[0]" /    ["[1][0]" rgb] +  ["[1][0]" cmyk]    ["[1][0]" named]    ["[1][0]" terminal]]) @@ -86,18 +87,14 @@           (|> expected /.hsb /.of_hsb               (distance/3 expected)               (f.<= ..rgb_error_margin))) -       (_.coverage [/.CMYK /.cmyk /.of_cmyk] -         (|> expected /.cmyk /.of_cmyk -             (distance/3 expected) -             (f.<= ..rgb_error_margin)))         ))  (def transformation    Test    (do random.monad      [colorful (|> ..random -                  (random.only (function (_ color) (|> (distance/3 color /.black) (f.>= +100.0)))) -                  (random.only (function (_ color) (|> (distance/3 color /.white) (f.>= +100.0))))) +                  (random.only (function (_ color) (and (|> (distance/3 color /.black) (f.>= +100.0)) +                                                        (|> (distance/3 color /.white) (f.>= +100.0))))))       mediocre (|> ..random                    (random.only (|>> saturation                                      ((function (_ saturation) @@ -217,6 +214,7 @@                           ))               /rgb.test +             /cmyk.test               /named.test               /terminal.test               )))) diff --git a/stdlib/source/test/lux/data/color/cmyk.lux b/stdlib/source/test/lux/data/color/cmyk.lux new file mode 100644 index 000000000..4a9736762 --- /dev/null +++ b/stdlib/source/test/lux/data/color/cmyk.lux @@ -0,0 +1,90 @@ +(.require + [library +  [lux (.except) +   [abstract +    [monad (.only do)] +    [\\specification +     ["[0]S" equivalence]]] +   [control +    ["[0]" try (.use "[1]#[0]" functor)] +    ["[0]" exception]] +   [math +    ["[0]" random (.only Random)] +    [number +     ["f" frac]]] +   [test +    ["_" property (.only Test)]]]] + [\\library +  ["[0]" / (.only) +   [// +    ["[0]" rgb]]]] + [// +  ["[0]T" rgb]]) + +(def .public value +  (Random /.Value) +  (random.one (|>> /.value try.maybe) +              random.safe_frac)) + +(def .public random +  (Random /.CMYK) +  (do random.monad +    [cyan ..value +     magenta ..value +     yellow ..value +     key ..value] +    (in [/.#cyan cyan +         /.#magenta magenta +         /.#yellow yellow +         /.#key key]))) + +(def .public test +  Test +  (<| (_.covering /._) +      (do [! random.monad] +        [expected_value ..value +         expected_rgb rgbT.random +         expected_cmyk ..random]) +      (all _.and +           (_.for [/.Value] +                  (all _.and +                       (_.coverage [/.number /.value] +                         (|> expected_value +                             /.number +                             /.value +                             (try#each (|>> /.number +                                            (f.= (/.number expected_value)))) +                             (try.else false))) +                       (_.coverage [/.least] +                         (when (/.value (f.+ +0.001 (/.number /.least))) +                           {try.#Failure _} false +                           {try.#Success _} true)) +                       (_.coverage [/.most] +                         (when (/.value (f.- +0.001 (/.number /.most))) +                           {try.#Failure _} false +                           {try.#Success _} true)) +                       (_.coverage [/.invalid] +                         (and (when (/.value (f.- +0.001 (/.number /.least))) +                                {try.#Failure it} (exception.match? /.invalid it) +                                {try.#Success _} false) +                              (when (/.value (f.+ +0.001 (/.number /.most))) +                                {try.#Failure it} (exception.match? /.invalid it) +                                {try.#Success _} false))) +                       )) +           (_.for [/.CMYK +                   /.#cyan /.#magenta /.#yellow /.#key] +                  (all _.and +                       (_.for [/.equivalence] +                              (equivalenceS.spec /.equivalence ..random)) + +                       (_.coverage [/.cmyk /.rgb] +                         (and (|> expected_rgb +                                  /.cmyk +                                  /.rgb +                                  (at rgb.equivalence = expected_rgb)) +                              (|> expected_cmyk +                                  /.rgb +                                  /.cmyk +                                  (at /.equivalence = expected_cmyk)))) +                       )) +           ))) | 
