aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/abstract/functor.lux
blob: 541c8897102db0d15558905729da885932d3a0f9 (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
(.using
 [library
  [lux "*"
   ["_" test {"+" Test}]
   [abstract
    [monad {"+" do}]]
   [control
    ["[0]" maybe]]
   [data
    [collection
     ["[0]" list]]]
   [math
    ["[0]" random]
    [number
     ["n" nat]]]]]
 [\\library
  ["[0]" / {"+" Functor}]])

(def: .public test
  Test
  (do random.monad
    [left random.nat
     right random.nat
     shift random.nat]
    (<| (_.covering /._)
        ($_ _.and
            (_.cover [/.Or /.sum]
                     (and (case (# (/.sum maybe.functor list.functor) each
                                   (n.+ shift)
                                   {.#Left {.#Some left}})
                            {.#Left {.#Some actual}}
                            (n.= (n.+ shift left) actual)

                            _
                            false)
                          (case (# (/.sum maybe.functor list.functor) each
                                   (n.+ shift)
                                   {.#Right (list right)})
                            (pattern {.#Right (list actual)})
                            (n.= (n.+ shift right) actual)

                            _
                            false)))
            (_.cover [/.And /.product]
                     (case (# (/.product maybe.functor list.functor) each
                              (n.+ shift)
                              [{.#Some left} (list right)])
                       (pattern [{.#Some actualL} (list actualR)])
                       (and (n.= (n.+ shift left) actualL)
                            (n.= (n.+ shift right) actualR))

                       _
                       false))
            (_.cover [/.Then /.composite]
                     (case (# (/.composite maybe.functor list.functor) each
                              (n.+ shift)
                              {.#Some (list left)})
                       (pattern {.#Some (list actual)})
                       (n.= (n.+ shift left) actual)

                       _
                       false))
            ))))