blob: 8827b719fe055d136e1428cbf0133b71533f501d (
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
(.require
[library
[lux (.except)
["_" test (.only Test)]
[abstract
[monad (.only do)]
[order (.only Order)]
[\\specification
["$[0]" equivalence]]]
[data
["[0]" bit (.use "[1]#[0]" equivalence)]
[collection
["[0]" list]]]
[math
["[0]" random (.only Random) (.use "[1]#[0]" monad)]
[number
["n" nat]]]]]
[\\library
["[0]" / (.only Set)
["[0]" //]]])
(def size
(random.Random Nat)
(at random.monad each (n.% 100) random.nat))
(def .public (random size order gen_value)
(All (_ a) (-> Nat (Order a) (Random a) (Random (Set a))))
(case size
0
(random#in (/.empty order))
_
(do random.monad
[partial (random (-- size) order gen_value)
value (random.only (|>> (/.member? partial) not)
gen_value)]
(in (/.has value partial)))))
(def .public test
Test
(<| (_.covering /._)
(_.for [/.Set])
(do [! random.monad]
[sizeL ..size
sizeR ..size
usetL (random.set n.hash sizeL random.nat)
non_memberL (random.only (|>> (//.member? usetL) not)
random.nat)
.let [listL (//.list usetL)]
listR (|> (random.set n.hash sizeR random.nat) (at ! each //.list))
.let [(open "/#[0]") /.equivalence
setL (/.of_list n.order listL)
setR (/.of_list n.order listR)
empty (/.empty n.order)]]
(`` (all _.and
(_.for [/.equivalence]
($equivalence.spec /.equivalence (..random sizeL n.order random.nat)))
(_.coverage [/.size]
(n.= sizeL (/.size setL)))
(_.coverage [/.empty?]
(bit#= (n.= 0 (/.size setL))
(/.empty? setL)))
(_.coverage [/.empty]
(/.empty? (/.empty n.order)))
(_.coverage [/.list]
(at (list.equivalence n.equivalence) =
(/.list (/.of_list n.order listL))
(list.sorted (at n.order <) listL)))
(_.coverage [/.of_list]
(|> setL
/.list (/.of_list n.order)
(/#= setL)))
(~~ (with_template [<coverage> <comparison>]
[(_.coverage [<coverage>]
(case (<coverage> setL)
{.#Some value}
(|> setL /.list (list.every? (<comparison> value)))
{.#None}
(/.empty? setL)))]
[/.min n.>=]
[/.max n.<=]
))
(_.coverage [/.member?]
(let [members_are_identified!
(list.every? (/.member? setL) (/.list setL))
non_members_are_not_identified!
(not (/.member? setL non_memberL))]
(and members_are_identified!
non_members_are_not_identified!)))
(_.coverage [/.has]
(let [setL+ (/.has non_memberL setL)]
(and (not (/.member? setL non_memberL))
(/.member? setL+ non_memberL)
(n.= (++ (/.size setL))
(/.size setL+)))))
(_.coverage [/.lacks]
(|> setL
(/.has non_memberL)
(/.lacks non_memberL)
(at /.equivalence = setL)))
(_.coverage [/.sub?]
(let [self!
(/.sub? setL setL)
empty!
(/.sub? setL empty)]
(and self!
empty!)))
(_.coverage [/.super?]
(let [self!
(/.super? setL setL)
empty!
(/.super? empty setL)
symmetry!
(bit#= (/.super? setL setR)
(/.sub? setR setL))]
(and self!
empty!
symmetry!)))
(~~ (with_template [<coverage> <relation> <empty?>]
[(_.coverage [<coverage>]
(let [self!
(at /.equivalence =
setL
(<coverage> setL setL))
super!
(and (<relation> (<coverage> setL setR) setL)
(<relation> (<coverage> setL setR) setR))
empty!
(at /.equivalence =
(if <empty?> empty setL)
(<coverage> setL empty))
idempotence!
(at /.equivalence =
(<coverage> setL (<coverage> setL setR))
(<coverage> setR (<coverage> setL setR)))]
(and self!
super!
empty!
idempotence!)))]
[/.union /.sub? false]
[/.intersection /.super? true]
))
(_.coverage [/.difference]
(let [self!
(|> setL
(/.difference setL)
(at /.equivalence = empty))
empty!
(|> setL
(/.difference empty)
(at /.equivalence = setL))
difference!
(not (list.any? (/.member? (/.difference setL setR))
(/.list setL)))
idempotence!
(at /.equivalence =
(/.difference setL setR)
(/.difference setL (/.difference setL setR)))]
(and self!
empty!
difference!
idempotence!)))
)))))
|