1 IN: inference.transforms.tests
2 USING: sequences inference.transforms tools.test math kernel
3 quotations inference accessors combinators words arrays
4 classes classes.tuple ;
6 : compose-n-quot ( word -- quot' ) <repetition> >quotation ;
7 : compose-n ( quot -- ) compose-n-quot call ;
8 \ compose-n [ compose-n-quot ] 2 define-transform
9 : compose-n-test ( a b c -- x ) 2 \ + compose-n ;
11 [ 6 ] [ 1 2 3 compose-n-test ] unit-test
13 [ 0 ] [ { } bitfield-quot call ] unit-test
15 [ 256 ] [ 1 { 8 } bitfield-quot call ] unit-test
17 [ 268 ] [ 3 1 { 8 2 } bitfield-quot call ] unit-test
19 [ 268 ] [ 1 { 8 { 3 2 } } bitfield-quot call ] unit-test
21 [ 512 ] [ 1 { { 1+ 8 } } bitfield-quot call ] unit-test
27 : cleave-test ( color -- r g b )
28 { [ r>> ] [ g>> ] [ b>> ] } cleave ;
30 { 1 3 } [ cleave-test ] must-infer-as
32 [ 1 2 3 ] [ 1 2 3 <color> cleave-test ] unit-test
34 [ 1 2 3 ] [ 1 2 3 <color> \ cleave-test word-def call ] unit-test
36 : 2cleave-test ( a b -- c d e ) { [ 2array ] [ + ] [ - ] } 2cleave ;
38 [ { 1 2 } 3 -1 ] [ 1 2 2cleave-test ] unit-test
40 [ { 1 2 } 3 -1 ] [ 1 2 \ 2cleave-test word-def call ] unit-test
42 : spread-test ( a b c -- d e f ) { [ sq ] [ neg ] [ recip ] } spread ;
44 [ 16 -3 1/6 ] [ 4 3 6 spread-test ] unit-test
46 [ 16 -3 1/6 ] [ 4 3 6 \ spread-test word-def call ] unit-test
48 [ fixnum instance? ] must-infer
50 : bad-new-test ( -- obj ) V{ } new ;
52 [ bad-new-test ] must-infer
54 [ bad-new-test ] [ T{ not-a-tuple-class f V{ } } = ] must-fail-with