blob: 666ed5f039e0c6d1a3b4d645136d931711d7c184 (
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
|
(.require
[library
[lux (.except)
[abstract
[monad (.only do)]]
[control
["[0]" io]]
[math
["[0]" random]
[number
["n" nat]
["i" int]]]
[world
[time
["[0]" instant (.only Instant)]
["[0]" duration]]]
[test
["_" property (.only Test)]
["[0]" unit]]]]
[\\library
["[0]" / (.only)
[//
["[0]" atom (.only Atom)]
["[0]" async]]]])
(def .public test
Test
(<| (_.covering /._)
(do [! random.monad]
[dummy random.nat
expected random.nat
delay (of ! each (|>> (n.% 5) (n.+ 5))
random.nat)]
(all _.and
(_.coverage [/.parallelism]
(n.> 0 /.parallelism))
(in (do async.monad
[reference_time (async.future instant.now)
.let [box (atom.atom [reference_time dummy])]
_ (async.future
(/.schedule! delay (do io.monad
[execution_time instant.now]
(atom.write! [execution_time expected] box))))
_ (async.delay (n.* 2 delay))
[execution_time actual] (async.future (atom.read! box))]
(unit.coverage [/.schedule!]
(let [expected_delay!
(i.>= (.int delay)
(duration.millis (instant.span reference_time execution_time)))
correct_value!
(n.= expected actual)]
(and expected_delay!
correct_value!)))))
(_.for [/.Delay]
(`` (all _.and
(,, (with_template [<delay> <duration>]
[(_.coverage [<delay>]
(i.= (duration.millis <duration>)
(.int <delay>)))]
[/.milli_second duration.milli_second]
[/.second duration.second]
[/.minute duration.minute]
[/.hour duration.hour]
[/.day duration.day]
[/.week duration.week]
))
)))
))))
|