blob: 701828389c7e309421e080b3404c034587b8ce33 (
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
|
(.module:
[library
[lux #*
["_" test (#+ Test)]
[abstract
[equivalence (#+ Equivalence)]
[monad (#+ do)]]
[control
[pipe (#+ case>)]]
[data
["." text ("#\." equivalence)
["%" format (#+ format)]]]
[macro
["." template]]
[math
["." random]
[number
["n" nat]
["i" int]
["f" frac]]]
["." type ("#\." equivalence)]]]
[\\library
["." /]])
(/.import: java/lang/Object)
(/.import: java/lang/String)
(/.import: java/lang/Exception
["#::."
(new [java/lang/String])])
(/.import: (java/lang/Class a)
["#::."
(getName [] java/lang/String)])
(/.class: #final (TestClass A) []
... Fields
(#private increase java/lang/Long)
(#private counter java/lang/Long)
... Methods
(#public [] (new {increase java/lang/Long} {counter java/lang/Long}) []
(exec
(:= ::increase increase)
(:= ::counter counter)
[]))
(#public (currentC self) java/lang/Long
::counter)
(#public (upC self) void
(:= ::counter (i.+ ::increase ::counter)))
(#public (downC self) void
(:= ::counter (i.- ::increase ::counter))))
(/.import: (test/lux/ffi/TestClass a)
["#::."
(new [java/lang/Long java/lang/Long])
(currentC [] java/lang/Long)
(upC [] void)
(downC [] void)])
(/.interface: TestInterface
([] current [] java/lang/Long #throws [java/lang/Exception])
([] up [] test/lux/ffi/TestInterface #throws [java/lang/Exception])
([] down [] test/lux/ffi/TestInterface #throws [java/lang/Exception]))
(/.import: test/lux/ffi/TestInterface
["#::."
(current [] java/lang/Long)
(up [] java/lang/Long)
(down [] java/lang/Long)])
(def: (test_object increase counter)
(-> Int Int test/lux/ffi/TestInterface)
(/.object [] [test/lux/ffi/TestInterface]
[]
(test/lux/ffi/TestInterface
[] (current self)
java/lang/Long
counter)
(test/lux/ffi/TestInterface
[] (up self)
test/lux/ffi/TestInterface
(test_object increase (i.+ increase counter)))
(test/lux/ffi/TestInterface
[] (down self)
test/lux/ffi/TestInterface
(test_object increase (i.- increase counter)))))
(def: conversions
Test
(do {! random.monad}
[long random.int
int (\ ! map (|>> /.long_to_int) random.int)
char (\ ! map (|>> /.long_to_int /.int_to_char) random.int)
double (|> random.frac
(random.only (|>> f.not_a_number? not)))
float (|> random.frac
(random.only (|>> f.not_a_number? not))
(\ ! map (|>> /.double_to_float)))]
(`` ($_ _.and
(~~ (template [<=> <sample> <to> <from>]
[(_.cover [<to> <from>]
(or (|> <sample> <to> <from> (<=> <sample>))
(let [capped (|> <sample> <to> <from>)]
(|> capped <to> <from> (<=> capped)))))]
[i.= long /.long_to_byte /.byte_to_long]
[i.= long /.long_to_short /.short_to_long]
[i.= long /.long_to_int /.int_to_long]
[i.= long /.long_to_float /.float_to_long]
[i.= long /.long_to_double /.double_to_long]
[f.= double /.double_to_float /.float_to_double]
[f.= double /.double_to_int /.int_to_double]
))
(~~ (template [<to> <from>]
[(_.cover [<to>]
(or (|> int <to> <from> (i.= (/.int_to_long int)))
(let [capped (|> int <to> <from>)]
(|> capped /.long_to_int <to> <from> (i.= capped)))))]
[/.int_to_byte /.byte_to_long]
[/.int_to_short /.short_to_long]
[/.int_to_char /.char_to_long]
))
(~~ (template [<sample> <to> <from>]
[(_.cover [<to> <from>]
(or (|> <sample> <to> <from> /.float_to_double (f.= (/.float_to_double <sample>)))
(let [capped (|> <sample> <to> <from>)]
(|> capped <to> <from> /.float_to_double (f.= (/.float_to_double capped))))))]
[float /.float_to_int /.int_to_float]
))
(~~ (template [<to> <from>]
[(_.cover [<to>]
(or (|> char <to> <from> (i.= (|> char /.char_to_int /.int_to_long)))
(let [capped (|> char <to> <from>)]
(|> capped /.long_to_int /.int_to_char <to> <from> (i.= capped)))))]
[/.char_to_byte /.byte_to_long]
[/.char_to_short /.short_to_long]
))
(_.cover [/.char_to_long]
(with_expansions [<to> /.int_to_char
<from> /.char_to_long]
(`` (or (|> int <to> <from> (i.= (/.int_to_long int)))
(let [capped (|> int <to> <from>)]
(|> capped /.long_to_int <to> <from> (i.= capped)))))))
(_.cover [/.char_to_int]
(with_expansions [<to> /.int_to_char
<from> /.char_to_int]
(`` (or (|> int <to> <from> /.int_to_long (i.= (/.int_to_long int)))
(let [capped (|> int <to> <from>)]
(|> capped <to> <from> /.int_to_long (i.= (/.int_to_long capped))))))))
))))
(def: arrays
Test
(do {! random.monad}
[size (|> random.nat (\ ! map (|>> (n.% 100) (n.max 1))))
idx (|> random.nat (\ ! map (n.% size)))
value random.int]
($_ _.and
(_.cover [/.array /.length]
(n.= size (/.length (/.array java/lang/Long size))))
(_.cover [/.write! /.read!]
(|> (/.array java/lang/Long size)
(/.write! idx value)
(/.read! idx)
(i.= value)))
)))
(def: null
Test
(do random.monad
[sample (random.ascii 1)]
($_ _.and
(_.cover [/.null /.null?]
(and (/.null? (/.null))
(not (/.null? sample))))
(_.cover [/.???]
(and (|> (: (Maybe java/lang/Object) (/.??? (/.null)))
(case> #.None #1
_ #0))
(|> (: (Maybe java/lang/Object) (/.??? sample))
(case> (#.Some _) #1
_ #0))))
(_.cover [/.!!!]
(and (/.null? (/.!!! (/.??? (/.null))))
(not (/.null? (/.!!! (/.??? sample))))))
)))
(def: miscellaneous
Test
(do random.monad
[sample (random.ascii 1)
counter random.int
increase random.int]
($_ _.and
(_.cover [/.check]
(and (case (/.check java/lang/String sample) (#.Some _) true #.None false)
(case (/.check java/lang/Long sample) (#.Some _) false #.None true)
(case (/.check java/lang/Object sample) (#.Some _) true #.None false)
(case (/.check java/lang/Object (/.null)) (#.Some _) false #.None true)))
(_.cover [/.synchronized]
(/.synchronized sample #1))
(_.cover [/.class_for /.import:]
(|> (/.class_for java/lang/Class)
java/lang/Class::getName
(text\= "java.lang.Class")))
(_.cover [/.class: /.do_to]
(|> (/.do_to (test/lux/ffi/TestClass::new increase counter)
(test/lux/ffi/TestClass::upC)
(test/lux/ffi/TestClass::upC)
(test/lux/ffi/TestClass::downC))
test/lux/ffi/TestClass::currentC
(i.= (i.+ increase counter))))
(_.cover [/.interface: /.object]
(|> (..test_object increase counter)
test/lux/ffi/TestInterface::up
test/lux/ffi/TestInterface::up
test/lux/ffi/TestInterface::down
test/lux/ffi/TestInterface::current
(i.= (i.+ increase counter))))
(_.cover [/.type]
(and (type\= (primitive "java.lang.Char")
(/.type java/lang/Char))
(type\= (primitive "java.util.List" [(primitive "java.lang.Byte")])
(/.type (java/util/List java/lang/Byte)))))
)))
(def: .public test
(<| (_.covering /._)
($_ _.and
..conversions
..arrays
..null
..miscellaneous
)))
|