blob: 6d59672ca3ece8fd40158e485ea489df337b0bc0 (
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)]]
[control
["." io]]
[data
[number
["n" nat]
["i" int]]]
[time
["." instant (#+ Instant)]
["." duration]]
[math
["." random]]]
{1
["." /
[//
["." atom (#+ Atom)]
["." promise]]]})
(def: #export test
Test
(<| (_.covering /._)
(do {! random.monad}
[dummy random.nat
expected random.nat
delay (|> random.nat (:: ! map (n.% 100)))]
($_ _.and
(_.cover [/.parallelism]
(n.> 0 /.parallelism))
(wrap (do promise.monad
[reference-time (promise.future instant.now)
#let [box (atom.atom [reference-time dummy])]
_ (promise.future
(/.schedule delay (do io.monad
[execution-time instant.now]
(atom.write [execution-time expected] box))))
_ (promise.wait delay)
[execution-time actual] (promise.future (atom.read box))]
(_.claim [/.schedule]
(and (i.>= (.int delay)
(duration.to-millis (instant.span reference-time execution-time)))
(n.= expected actual)))))
))))
|