blob: cb2be3918a964e87b3e8d6059cd0aae1fd33c9bd (
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
(.using
[library
[lux (.except)
["_" test (.only Test)]
[abstract
[monad (.only do)]
[\\specification
["$[0]" equivalence]
["$[0]" order]
["$[0]" codec]]]
[control
["[0]" try]
["[0]" exception]]
[data
["[0]" bit (.open: "[1]#[0]" equivalence)]
[text
["%" \\format (.only format)]]]
[math
["[0]" random (.only Random)]
[number
["n" nat]
["i" int]]]]]
[\\library
["[0]" / (.only)
["/[1]" // (.only)
["[1][0]" duration]
["[1][0]" instant]
["[1][0]" date]]]])
(def: .public random
(Random /.Year)
(random.one (|>> /.year try.maybe) random.int))
(def: .public test
Test
(<| (_.covering /._)
(_.for [/.Year])
(all _.and
(_.for [/.equivalence]
($equivalence.spec /.equivalence ..random))
(_.for [/.order]
($order.spec /.order ..random))
(_.for [/.codec /.parser]
($codec.spec /.equivalence /.codec ..random))
(do random.monad
[expected random.int]
(all _.and
(_.coverage [/.year]
(bit#= (i.= +0 expected)
(case (/.year expected)
{try.#Success _}
false
{try.#Failure _}
true)))
(_.coverage [/.value]
(case (/.year expected)
{try.#Success year}
(i.= expected (/.value year))
{try.#Failure _}
(i.= +0 expected)))
))
(_.coverage [/.there_is_no_year_0]
(case (/.year +0)
{try.#Success _}
false
{try.#Failure error}
(exception.match? /.there_is_no_year_0 error)))
(_.coverage [/.days]
(n.= (.nat (//duration.ticks //duration.day //duration.normal_year))
/.days))
(_.coverage [/.epoch]
(at /.equivalence =
(//date.year (//instant.date //instant.epoch))
/.epoch))
(_.for [/.Period]
(_.coverage [/.leap /.century /.era]
(n.= /.leap (n./ /.century /.era))))
(let [leap (try.trusted (/.year (.int /.leap)))
century (try.trusted (/.year (.int /.century)))
era (try.trusted (/.year (.int /.era)))]
(all _.and
(_.coverage [/.leap?]
(and (/.leap? leap)
(not (/.leap? century))
(/.leap? era)))
(_.coverage [/.leaps]
(and (i.= +1 (/.leaps leap))
(i.= (.int (n./ /.leap /.century))
(/.leaps century))
(i.= (++ (i.* +4 (-- (/.leaps century))))
(/.leaps era))))
))
)))
|