aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/control/io.lux
blob: a45fd28a97963e68a4578bb90c0e26292f698dc3 (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
(.module:
  [lux #*
   ["_" test (#+ Test)]
   [abstract
    [monad (#+ do)]
    [\spec
     ["$." functor (#+ Injection Comparison)]
     ["$." apply]
     ["$." monad]]]
   [math
    ["." random]
    [number
     ["n" nat]]]]
  [\\
   ["." / (#+ IO)
    [//
     ["." function]]]])

(def: injection
  (Injection IO)
  (|>> /.io))

(def: comparison
  (Comparison IO)
  (function (_ == left right)
    (== (/.run left) (/.run right))))

(def: #export test
  Test
  (<| (_.covering /._)
      (_.for [/.IO])
      (do random.monad
        [sample random.nat
         exit-code random.int]
        ($_ _.and
            (_.for [/.functor]
                   ($functor.spec ..injection ..comparison /.functor))
            (_.for [/.apply]
                   ($apply.spec ..injection ..comparison /.apply))
            (_.for [/.monad]
                   ($monad.spec ..injection ..comparison /.monad))

            (_.cover [/.run /.io]
                     (n.= sample
                          (/.run (/.io sample))))
            ))))