blob: 751d0f3f7b4576ffe0fba58a9870d5db961fe771 (
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
98
99
100
|
(.require
[library
[lux (.except)
["_" test (.only Test)]
[abstract
[monad (.only do)]
["[0]" predicate]
[\\specification
["$[0]" equivalence]
["$[0]" hash]
["$[0]" order]
["$[0]" enum]
["$[0]" codec]]]
[control
["[0]" try (.use "[1]#[0]" functor)]
["[0]" exception]]
[data
[collection
["[0]" set]
["[0]" list (.use "[1]#[0]" functor mix)]]]
[math
["[0]" random (.only Random)]
[number
["n" nat]]]]]
[\\library
["[0]" / (.only)
[//
["[0]" duration]]]])
(def .public random
(Random /.Month)
(let [december (/.number {/.#December})]
(|> random.nat
(at random.monad each (|>> (n.% december) ++))
(random.one (|>> /.by_number try.maybe)))))
(def .public test
Test
(<| (_.covering /._)
(_.for [/.Month])
(all _.and
(_.for [/.equivalence]
($equivalence.spec /.equivalence ..random))
(_.for [/.hash]
($hash.spec /.hash ..random))
(_.for [/.order]
($order.spec /.order ..random))
(_.for [/.enum]
($enum.spec /.enum ..random))
(_.for [/.codec]
($codec.spec /.equivalence /.codec ..random))
(do random.monad
[expected ..random
invalid (random.only (predicate.or (n.< (/.number {/.#January}))
(n.> (/.number {/.#December})))
random.nat)]
(all _.and
(_.coverage [/.number /.by_number]
(|> expected
/.number
/.by_number
(try#each (at /.equivalence = expected))
(try.else false)))
(_.coverage [/.invalid_month]
(case (/.by_number invalid)
{try.#Failure error}
(exception.match? /.invalid_month error)
{try.#Success _}
false))
(_.coverage [/.year]
(let [all (list.size /.year)
uniques (set.size (set.of_list /.hash /.year))]
(and (n.= (/.number {/.#December})
all)
(n.= all
uniques))))
(_.coverage [/.days]
(let [expected (.nat (duration.ticks duration.day duration.normal_year))]
(|> /.year
(list#each /.days)
(list#mix n.+ 0)
(n.= expected))))
(_.coverage [/.leap_year_days]
(let [expected (.nat (duration.ticks duration.day duration.leap_year))]
(|> /.year
(list#each /.leap_year_days)
(list#mix n.+ 0)
(n.= expected))))
(do random.monad
[not_a_month (random.upper_case 1)]
(_.coverage [/.not_a_month_of_the_year]
(case (at /.codec decoded not_a_month)
{try.#Failure error}
(exception.match? /.not_a_month_of_the_year error)
{try.#Success _}
false)))
)))))
|