blob: 7d40750a5c6b96082dae452f5d7eca5b6409c322 (
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
|
(.module:
[lux #*
["%" data/text/format (#+ format)]
["_" test (#+ Test)]
[abstract
[monad (#+ do)]
{[0 #spec]
[/
["$." equivalence]
["$." order]
["$." monoid]
["$." codec]]}]
[data
[number
["n" nat]
["i" int]]]
[math
["." random (#+ Random)]]]
{1
["." / (#+ Duration)]})
(def: #export duration
(Random Duration)
(:: random.monad map /.from-millis random.int))
(def: #export test
Test
(<| (_.context (%.name (name-of /._)))
($_ _.and
($equivalence.spec /.equivalence ..duration)
($order.spec /.order ..duration)
($monoid.spec /.equivalence /.monoid ..duration)
($codec.spec /.equivalence /.codec ..duration)
(do random.monad
[millis random.int]
(_.test "Can convert from/to milliseconds."
(|> millis /.from-millis /.to-millis (i.= millis))))
(do {! random.monad}
[sample (|> duration (:: ! map (/.frame /.day)))
frame duration
factor (|> random.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)))))
)))
|