blob: ba0e35cf1d3fd39a4c4924a8bc79159ce1b28766 (
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
|
(.module:
[lux #*
data/text/format
["_" test (#+ Test)]
[control
[monad (#+ do)]
{[0 #test]
[/
["$." equivalence]
["$." order]
["$." monoid]
["$." codec]]}]
[data
["E" error]]
[math
["r" random (#+ Random)]]]
{1
["." / (#+ Duration)]})
(def: #export duration
(Random Duration)
(|> r.int (:: r.monad map /.from-millis)))
(def: #export test
Test
($_ _.and
($equivalence.spec /.equivalence ..duration)
($order.spec /.order ..duration)
($monoid.spec /.equivalence /.monoid ..duration)
## TODO; Uncomment ASAP
## ($codec.spec /.equivalence /.codec ..duration)
(do r.monad
[millis r.int]
(_.test "Can convert from/to milliseconds."
(|> millis /.from-millis /.to-millis (i/= millis))))
(do r.monad
[sample (|> duration (:: @ map (/.frame /.day)))
frame duration
factor (|> r.nat (:: @ map (|>> (n/% 10) (n/max 1))))
#let [(^open "/@.") /.order]]
($_ _.and
(_.test "Can scale a duration."
(|> sample (/.scale-up factor) (/.query sample) (i/= (.int factor))))
(_.test "Scaling a duration by one does not change it."
(|> sample (/.scale-up 1) (/@= sample)))
(_.test "Merging a duration with it's opposite yields an empty duration."
(|> sample (/.merge (/.inverse sample)) (/@= /.empty)))))
))
|