blob: f00b572abeeb9eafb23148c7217c955680bc2ada (
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
|
(.module:
[lux #*
[control
[monad (#+ do Monad)]]
[data
["&" lazy]]
[math
["r" random]]]
lux/test)
(context: "Lazy."
(<| (times 100)
(do @
[left r.nat
right r.nat
#let [lazy (&.freeze (n/* left right))
expected (n/* left right)]]
($_ seq
(test "Lazying does not alter the expected value."
(n/= expected
(&.thaw lazy)))
(test "Lazy values only evaluate once."
(and (not (is? expected
(&.thaw lazy)))
(is? (&.thaw lazy)
(&.thaw lazy))))
))))
(context: "Functor, Apply, Monad."
(<| (times 100)
(do @
[sample r.nat]
($_ seq
(test "Functor map."
(|> (&.freeze sample)
(:: &.functor map inc)
&.thaw
(n/= (inc sample))))
(test "Monad."
(|> (do &.monad
[f (wrap inc)
a (wrap sample)]
(wrap (f a)))
&.thaw
(n/= (inc sample))))
(test "Apply apply."
(let [(^open "&/.") &.monad
(^open "&/.") &.apply]
(|> (&/apply (&/wrap inc) (&/wrap sample))
&.thaw
(n/= (inc sample)))))
))))
|