blob: e980121b782361ed29e439b2d4319603187844d2 (
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
|
(.using
[library
[lux "*"
["_" test {"+" Test}]
[abstract
[monad {"+" do}]
[\\specification
["$[0]" equivalence]
["$[0]" hash]
["$[0]" monoid]
["$[0]" functor]
["$[0]" apply]
["$[0]" monad]]]
[control
["[0]" io ("[1]#[0]" monad)]
["[0]" pipe]]
[data
["[0]" text]
[collection
["[0]" list]]]
[math
["[0]" random {"+" Random}]
[number
["n" nat]]]]]
[\\library
["[0]" / ("[1]#[0]" monoid monad)]])
(def: .public test
Test
(<| (_.covering /._)
(_.for [.Maybe])
(all _.and
(_.for [/.equivalence]
($equivalence.spec (/.equivalence n.equivalence) (random.maybe random.nat)))
(_.for [/.hash]
(|> random.nat
(# random.monad each (|>> {.#Some}))
($hash.spec (/.hash n.hash))))
(_.for [/.monoid]
($monoid.spec (/.equivalence n.equivalence) /.monoid (random.maybe random.nat)))
(_.for [/.functor]
($functor.spec /#in /.equivalence /.functor))
(_.for [/.apply]
($apply.spec /#in /.equivalence /.apply))
(_.for [/.monad]
($monad.spec /#in /.equivalence /.monad))
(do random.monad
[left random.nat
right random.nat
.let [expected (n.+ left right)]]
(let [lifted (/.lifted io.monad)]
(_.coverage [/.with /.lifted]
(|> (io.run! (do (/.with io.monad)
[a (lifted (io#in left))
b (in right)]
(in (n.+ a b))))
(pipe.case
{.#Some actual}
(n.= expected actual)
_
false)))))
(do random.monad
[default random.nat
value random.nat]
(_.coverage [/.else]
(and (same? default (/.else default
(is (Maybe Nat)
{.#None})))
(same? value (/.else default
{.#Some value})))))
(do random.monad
[value random.nat]
(_.coverage [/.trusted]
(same? value (/.trusted {.#Some value}))))
(do random.monad
[value random.nat]
(_.coverage [/.list]
(# (list.equivalence n.equivalence) =
(list value)
(/.list {.#Some value}))))
(do random.monad
[expected random.nat
.let [(open "/#[0]") (/.equivalence n.equivalence)]]
(_.coverage [/.when]
(and (/#= {.#Some expected} (/.when true {.#Some expected}))
(/#= {.#None} (/.when false {.#Some expected})))))
)))
|