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

(def: .public test
  Test
  (do random.monad
    [left random.nat
     right random.nat]
    (<| (_.covering /._)
        ($_ _.and
            (_.cover [/.composite]
                     (let [expected (n.+ left right)]
                       (case (# (/.composite maybe.monad maybe.apply list.apply) on
                                {.#Some (list right)}
                                {.#Some (list (n.+ left))})
                         (^ {.#Some (list actual)})
                         (n.= expected actual)

                         _
                         false)))
            ))))