blob: ceabc66f1c73324cb335f8691a6f977bc7c5c3ee (
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
|
(.using
[library
[lux "*"
["_" test {"+" Test}]
[abstract
[monad {"+" do}]
[\\specification
["$[0]" equivalence]
["$[0]" order]
["$[0]" enum]
["$[0]" codec]]]
[control
["[0]" try ("[1]#[0]" functor)]
["[0]" exception]
[parser
["<[0]>" text]]]
[data
[text
["%" format {"+" format}]]]
[math
["[0]" random {"+" Random}]
[number
["n" nat]
["i" int]]]]]
[\\library
["[0]" /]])
(def: .public test
Test
(<| (_.covering /._)
(_.for [/.Date])
($_ _.and
(_.for [/.equivalence]
($equivalence.spec /.equivalence random.date))
(_.for [/.order]
($order.spec /.order random.date))
(_.for [/.enum]
($enum.spec /.enum random.date))
(_.for [/.codec]
($codec.spec /.equivalence /.codec random.date))
(do random.monad
[expected random.date]
(_.cover [/.date /.year /.month /.day_of_month]
(|> (/.date (/.year expected)
(/.month expected)
(/.day_of_month expected))
(try#each (# /.equivalence = expected))
(try.else false))))
(do random.monad
[expected random.date]
(_.cover [/.invalid_day]
(case (/.date (/.year expected)
(/.month expected)
(n.+ 31 (/.day_of_month expected)))
{try.#Failure error}
(exception.match? /.invalid_day error)
{try.#Success _}
false)))
(do random.monad
[expected random.date]
(_.cover [/.days /.of_days]
(|> expected
/.days
/.of_days
(# /.equivalence = expected))))
(_.cover [/.epoch]
(|> /.epoch
/.days
(i.= +0)))
(do random.monad
[expected random.date]
(_.cover [/.parser]
(|> (# /.codec encoded expected)
(<text>.result /.parser)
(try#each (# /.equivalence = expected))
(try.else false))))
(do [! random.monad]
[year (# ! each (|>> (n.% 10,000) ++)
random.nat)
month (# ! each (|>> (n.% 10) (n.+ 13))
random.nat)
day (# ! each (|>> (n.% 10) (n.+ 10))
random.nat)
.let [input (format (%.nat year)
"-" (%.nat month)
"-" (%.nat day))]]
(_.cover [/.invalid_month]
(case (<text>.result /.parser input)
{try.#Failure error}
(exception.match? /.invalid_month error)
{try.#Success _}
false)))
)))
|