1 USING: alien arrays definitions generic assocs hashtables io
\r
2 kernel math namespaces parser prettyprint sequences strings
\r
3 tools.test vectors words quotations classes classes.algebra
\r
4 classes.private classes.union classes.mixin classes.predicate
\r
5 vectors definitions source-files compiler.units growable
\r
6 random stack-checker effects kernel.private sbufs math.order
\r
7 classes.tuple accessors ;
\r
8 IN: classes.algebra.tests
\r
11 \ class-and must-infer
\r
12 \ class-or must-infer
\r
13 \ flatten-class must-infer
\r
14 \ flatten-builtin-class must-infer
\r
16 : class-and* ( cls1 cls2 cls3 -- ? ) [ class-and ] dip class= ;
\r
18 : class-or* ( cls1 cls2 cls3 -- ? ) [ class-or ] dip class= ;
\r
20 [ t ] [ object object object class-and* ] unit-test
\r
21 [ t ] [ fixnum object fixnum class-and* ] unit-test
\r
22 [ t ] [ object fixnum fixnum class-and* ] unit-test
\r
23 [ t ] [ fixnum fixnum fixnum class-and* ] unit-test
\r
24 [ t ] [ fixnum integer fixnum class-and* ] unit-test
\r
25 [ t ] [ integer fixnum fixnum class-and* ] unit-test
\r
27 [ t ] [ vector fixnum null class-and* ] unit-test
\r
28 [ t ] [ number object number class-and* ] unit-test
\r
29 [ t ] [ object number number class-and* ] unit-test
\r
30 [ t ] [ slice reversed null class-and* ] unit-test
\r
31 [ t ] [ \ f class-not \ f null class-and* ] unit-test
\r
32 [ t ] [ \ f class-not \ f object class-or* ] unit-test
\r
36 UNION: both first-one union-class ;
\r
38 [ t ] [ both tuple classes-intersect? ] unit-test
\r
39 [ t ] [ vector virtual-sequence null class-and* ] unit-test
\r
40 [ f ] [ vector virtual-sequence classes-intersect? ] unit-test
\r
42 [ t ] [ number vector class-or sequence classes-intersect? ] unit-test
\r
44 [ f ] [ number vector class-and sequence classes-intersect? ] unit-test
\r
46 [ t ] [ \ fixnum \ integer class<= ] unit-test
\r
47 [ t ] [ \ fixnum \ fixnum class<= ] unit-test
\r
48 [ f ] [ \ integer \ fixnum class<= ] unit-test
\r
49 [ t ] [ \ integer \ object class<= ] unit-test
\r
50 [ f ] [ \ integer \ null class<= ] unit-test
\r
51 [ t ] [ \ null \ object class<= ] unit-test
\r
53 [ t ] [ \ generic \ word class<= ] unit-test
\r
54 [ f ] [ \ word \ generic class<= ] unit-test
\r
56 [ f ] [ \ reversed \ slice class<= ] unit-test
\r
57 [ f ] [ \ slice \ reversed class<= ] unit-test
\r
59 PREDICATE: no-docs < word "documentation" word-prop not ;
\r
61 UNION: no-docs-union no-docs integer ;
\r
63 [ t ] [ no-docs no-docs-union class<= ] unit-test
\r
64 [ f ] [ no-docs-union no-docs class<= ] unit-test
\r
70 [ t ] [ \ c \ tuple class<= ] unit-test
\r
71 [ f ] [ \ tuple \ c class<= ] unit-test
\r
73 [ t ] [ \ tuple-class \ class class<= ] unit-test
\r
74 [ f ] [ \ class \ tuple-class class<= ] unit-test
\r
76 TUPLE: tuple-example ;
\r
78 [ t ] [ \ null \ tuple-example class<= ] unit-test
\r
79 [ f ] [ \ object \ tuple-example class<= ] unit-test
\r
80 [ f ] [ \ object \ tuple-example class<= ] unit-test
\r
81 [ t ] [ \ tuple-example \ tuple class<= ] unit-test
\r
82 [ f ] [ \ tuple \ tuple-example class<= ] unit-test
\r
92 [ f ] [ z1 x1 y1 class-and class<= ] unit-test
\r
94 [ t ] [ x1 y1 class-and a1 class<= ] unit-test
\r
96 [ f ] [ y1 z1 class-and x1 classes-intersect? ] unit-test
\r
98 [ f ] [ b1 c1 class-or a1 b1 class-or a1 c1 class-and class-and class<= ] unit-test
\r
100 [ t ] [ a1 b1 class-or a1 c1 class-or class-and a1 class<= ] unit-test
\r
102 [ f ] [ a1 c1 class-or b1 c1 class-or class-and a1 b1 class-or classes-intersect? ] unit-test
\r
104 [ f ] [ growable \ hi-tag classes-intersect? ] unit-test
\r
107 growable tuple sequence class-and class<=
\r
111 growable assoc class-and tuple class<=
\r
114 [ t ] [ object \ f \ f class-not class-or class<= ] unit-test
\r
116 [ t ] [ fixnum class-not integer class-and bignum class= ] unit-test
\r
118 [ f ] [ integer integer class-not classes-intersect? ] unit-test
\r
120 [ t ] [ array number class-not class<= ] unit-test
\r
122 [ f ] [ bignum number class-not class<= ] unit-test
\r
124 [ vector ] [ vector class-not class-not ] unit-test
\r
126 [ t ] [ fixnum fixnum bignum class-or class<= ] unit-test
\r
128 [ f ] [ fixnum class-not integer class-and array class<= ] unit-test
\r
130 [ f ] [ fixnum class-not integer class<= ] unit-test
\r
132 [ f ] [ number class-not array class<= ] unit-test
\r
134 [ f ] [ fixnum class-not array class<= ] unit-test
\r
136 [ t ] [ number class-not integer class-not class<= ] unit-test
\r
138 [ t ] [ vector array class-not class-and vector class= ] unit-test
\r
140 [ f ] [ fixnum class-not number class-and array classes-intersect? ] unit-test
\r
142 [ f ] [ fixnum class-not integer class<= ] unit-test
\r
144 [ t ] [ null class-not object class= ] unit-test
\r
146 [ t ] [ object class-not null class= ] unit-test
\r
148 [ f ] [ object class-not object class= ] unit-test
\r
150 [ f ] [ null class-not null class= ] unit-test
\r
154 fixnum fixnum class-not class-or
\r
158 ! Test method inlining
\r
159 [ f ] [ fixnum { } min-class ] unit-test
\r
163 [ integer string array reversed sbuf
\r
164 slice vector quotation ]
\r
165 sort-classes min-class
\r
170 [ fixnum integer object ]
\r
171 sort-classes min-class
\r
176 [ integer float object ]
\r
177 sort-classes min-class
\r
182 [ integer float object ]
\r
183 sort-classes min-class
\r
188 [ integer reversed slice ]
\r
189 sort-classes min-class
\r
192 [ f ] [ null { number fixnum null } min-class ] unit-test
\r
195 : random-class ( -- class ) classes random ;
\r
197 : random-op ( -- word )
\r
206 20 [ random-op ] [ ] replicate-as
\r
207 [ infer in>> [ random-class ] times ] keep
\r
213 : random-boolean ( -- ? )
\r
216 : boolean>class ( ? -- class )
\r
219 : random-boolean-op ( -- word )
\r
227 : class-xor ( cls1 cls2 -- cls3 )
\r
228 [ class-or ] 2keep class-and class-not class-and ;
\r
230 : boolean-op>class-op ( word -- word' )
\r
240 20 [ random-boolean-op ] [ ] replicate-as dup .
\r
241 [ infer in>> [ random-boolean ] replicate dup . ] keep
\r
243 [ [ [ ] each ] dip call ] 2keep
\r
245 [ [ boolean>class ] each ] dip [ boolean-op>class-op ] map call object class=
\r
254 [ { yyy xxx } ] [ { xxx yyy } sort-classes ] unit-test
\r
255 [ { yyy xxx } ] [ { yyy xxx } sort-classes ] unit-test
\r
257 [ { number ratio integer } ] [ { ratio number integer } sort-classes ] unit-test
\r
258 [ { sequence number ratio } ] [ { ratio number sequence } sort-classes ] unit-test
\r
269 [ t ] [ { xa xb xc xd xe xf xg xh } sort-classes dup sort-classes = ] unit-test
\r
271 INTERSECTION: generic-class generic class ;
\r
273 [ t ] [ generic-class generic class<= ] unit-test
\r
274 [ t ] [ generic-class \ class class<= ] unit-test
\r
278 [ t ] [ \ class generic class-and generic-class class<= ] unit-test
\r
279 [ t ] [ \ class generic class-and generic-class swap class<= ] unit-test
\r
282 [ t ] [ \ word generic-class classes-intersect? ] unit-test
\r
283 [ f ] [ number generic-class classes-intersect? ] unit-test
\r
285 [ H{ { word word } } ] [
\r
286 generic-class flatten-class
\r
289 [ \ + flatten-class ] must-fail
\r
291 INTERSECTION: empty-intersection ;
\r
293 [ t ] [ object empty-intersection class<= ] unit-test
\r
294 [ t ] [ empty-intersection object class<= ] unit-test
\r
295 [ t ] [ \ f class-not empty-intersection class<= ] unit-test
\r
296 [ f ] [ empty-intersection \ f class-not class<= ] unit-test
\r
297 [ t ] [ \ number empty-intersection class<= ] unit-test
\r
298 [ t ] [ empty-intersection class-not null class<= ] unit-test
\r
299 [ t ] [ null empty-intersection class-not class<= ] unit-test
\r
301 [ t ] [ \ f class-not \ f class-or empty-intersection class<= ] unit-test
\r
302 [ t ] [ empty-intersection \ f class-not \ f class-or class<= ] unit-test
\r
304 [ t ] [ object \ f class-not \ f class-or class<= ] unit-test
\r
306 [ ] [ object flatten-builtin-class drop ] unit-test
\r
312 [ sa ] [ sa { sa sb sc } min-class ] unit-test
\r
314 [ +lt+ ] [ integer sequence class<=> ] unit-test
\r
315 [ +lt+ ] [ sequence object class<=> ] unit-test
\r
316 [ +gt+ ] [ object sequence class<=> ] unit-test
\r
317 [ +eq+ ] [ integer integer class<=> ] unit-test
\r