aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/abstract/monad.lux
blob: 786156f93cb4b6bf2e1eca09fd1c39dcdf664ce8 (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
(.module:
  [library
   [lux "*"
    ["_" test {"+" [Test]}]
    [data
     ["[0]" identity {"+" [Identity]}]
     [collection
      ["[0]" list ("[1]\[0]" functor mix)]]]
    [math
     ["[0]" random]
     [number
      ["n" nat]]]]]
  [\\library
   ["[0]" / {"+" [Monad do]}]])

(def: .public test
  Test
  (do random.monad
    [mono random.nat
     poly (random.list 10 random.nat)]
    (<| (_.covering /._)
        ($_ _.and
            (_.cover [/.do]
                     (n.= (++ mono)
                          (: (Identity Nat)
                             (/.do identity.monad
                               [sample (in mono)]
                               (in (++ sample))))))
            (_.cover [/.then]
                     (n.= (++ mono)
                          (: (Identity Nat)
                             (/.then identity.monad
                                     (|>> ++ (\ identity.monad in))
                                     (\ identity.monad in mono)))))
            (_.cover [/.all]
                     (\ (list.equivalence n.equivalence) =
                        (list\each ++ poly)
                        (|> poly
                            (list\each (|>> ++ (\ identity.monad in)))
                            (: (List (Identity Nat)))
                            (/.all identity.monad)
                            (: (Identity (List Nat))))))
            (_.cover [/.each]
                     (\ (list.equivalence n.equivalence) =
                        (list\each ++ poly)
                        (|> poly
                            (/.each identity.monad (|>> ++ (\ identity.monad in)))
                            (: (Identity (List Nat))))))
            (_.cover [/.only]
                     (\ (list.equivalence n.equivalence) =
                        (list.only n.even? poly)
                        (|> poly
                            (/.only identity.monad (|>> n.even? (\ identity.monad in)))
                            (: (Identity (List Nat))))))
            (_.cover [/.mix]
                     (n.= (list\mix n.+ 0 poly)
                          (|> poly
                              (/.mix identity.monad
                                     (function (_ part whole)
                                       (\ identity.monad in
                                          (n.+ part whole)))
                                     0)
                              (: (Identity Nat)))))
            ))))