aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/data/color/cmyk.lux
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/source/test/lux/data/color/cmyk.lux')
-rw-r--r--stdlib/source/test/lux/data/color/cmyk.lux90
1 files changed, 90 insertions, 0 deletions
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))))
+ ))
+ )))