blob: dd71f0f9398446a2c6346ecd3a86cf160efae3ac (
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
|
(.module:
[library
[lux #*
["_" test (#+ Test)]
[abstract
[monad (#+ do)]
["." predicate]
[\\specification
["$." equivalence]
["$." hash]
["$." order]
["$." enum]
["$." codec]]]
[control
["." try ("#\." functor)]
["." exception]]
[data
[collection
["." list]
["." set]]]
[math
["." random (#+ Random) ("#\." monad)]
[number
["n" nat]]]]]
[\\library
["." /]])
(def: .public random
(Random /.Day)
(random.either (random.either (random.either (random\in #/.Sunday)
(random\in #/.Monday))
(random.either (random\in #/.Tuesday)
(random\in #/.Wednesday)))
(random.either (random.either (random\in #/.Thursday)
(random\in #/.Friday))
(random\in #/.Saturday))))
(def: .public test
Test
(<| (_.covering /._)
(_.for [/.Day])
(do random.monad
[expected ..random
invalid (random.only (predicate.or (n.< (/.number #/.Sunday))
(n.> (/.number #/.Saturday)))
random.nat)]
($_ _.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
[not_a_day (random.ascii/upper 1)]
(_.cover [/.not_a_day_of_the_week]
(case (\ /.codec decode not_a_day)
(#try.Failure error)
(exception.match? /.not_a_day_of_the_week error)
(#try.Success _)
false)))
(_.cover [/.number /.by_number]
(|> expected
/.number
/.by_number
(try\map (\ /.equivalence = expected))
(try.else false)))
(_.cover [/.invalid_day]
(case (/.by_number invalid)
(#try.Failure error)
(exception.match? /.invalid_day error)
(#try.Success _)
false))
(_.cover [/.week]
(let [all (list.size /.week)
uniques (set.size (set.of_list /.hash /.week))]
(and (n.= (/.number #/.Saturday)
all)
(n.= all
uniques))))
))))
|