aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/data/color/cmyk.lux
blob: 2eda4d6a8e469758b49ed5d4c94128a1963d56e6 (plain)
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
(.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) (.use "[1]#[0]" functor)]
    [number
     ["f" frac]]]
   [test
    ["_" property (.only Test)]]]]
 [\\library
  ["[0]" / (.only)
   [//
    ["[0]" rgb]]]]
 [//
  ["[0]T" rgb]])

(def .public value
  (Random /.Value)
  (random#each /.value 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

         possible_value random.frac
         .let [delta +0.000000001]])
      (all _.and
           (_.for [/.Value]
                  (all _.and
                       (_.coverage [/.value?]
                         (and (/.value? expected_value)
                              (not (/.value? (f.+ delta /.most)))
                              (not (/.value? (f.- delta /.least)))))
                       (_.coverage [/.value]
                         (if (/.value? possible_value)
                           (|> possible_value
                               /.value
                               (f.= possible_value))
                           (or (f.= /.least (/.value possible_value))
                               (f.= /.most (/.value possible_value)))))
                       (_.coverage [/.least]
                         (and (f.< /.most
                                   /.least)
                              (/.value? /.least)
                              (/.value? (f.+ delta /.least))
                              (not (/.value? (f.- delta /.least)))))
                       (_.coverage [/.most]
                         (and (f.> /.least
                                   /.most)
                              (/.value? /.most)
                              (/.value? (f.- delta /.most))
                              (not (/.value? (f.+ delta /.most)))))
                       ))
           (_.for [/.CMYK
                   /.#cyan /.#magenta /.#yellow /.#key]
                  (all _.and
                       (_.for [/.equivalence]
                              (equivalenceS.spec /.equivalence ..random))

                       (_.coverage [/.cmyk /.rgb]
                         (and (|> expected_rgb
                                  /.cmyk
                                  /.rgb
                                  (of rgb.equivalence = expected_rgb))
                              (|> expected_cmyk
                                  /.rgb
                                  /.cmyk
                                  (of /.equivalence = expected_cmyk))))
                       ))
           )))