1 ! (c)2009 Joe Groff bsd license
2 USING: tools.test generalizations kernel math arrays sequences
3 sequences.generalizations ascii fry math.parser io io.streams.string ;
4 IN: sequences.generalizations.tests
6 { 1 2 3 4 } [ { 1 2 3 4 } 4 firstn ] unit-test
7 { { 1 2 3 4 } } [ 1 2 3 4 { f f f f } [ 4 set-firstn ] keep ] unit-test
8 [ 1 2 3 4 { f f f } [ 4 set-firstn ] keep ] must-fail
9 { } [ { } 0 firstn ] unit-test
10 { "a" } [ { "a" } 1 firstn ] unit-test
12 { [ 1 2 ] } [ 1 2 2 [ ] nsequence ] unit-test
14 { { 1 2 3 4 } } [ { 1 } { 2 } { 3 } { 4 } 4 nappend ] unit-test
15 { V{ 1 2 3 4 } } [ { 1 } { 2 } { 3 } { 4 } 4 V{ } nappend-as ] unit-test
17 [ 4 nappend ] must-infer
18 [ 4 { } nappend-as ] must-infer
20 : neach-test ( a b c d -- )
21 [ 4 nappend print ] 4 neach ;
22 : nmap-test ( a b c d -- e )
23 [ 4 nappend ] 4 nmap ;
24 : nmap-as-test ( a b c d -- e )
25 [ 4 nappend ] [ ] 4 nmap-as ;
26 : mnmap-3-test ( a b c d -- e f g )
27 [ append ] 4 3 mnmap ;
28 : mnmap-2-test ( a b c d -- e f )
29 [ [ append ] 2bi@ ] 4 2 mnmap ;
30 : mnmap-as-test ( a b c d -- e f )
31 [ [ append ] 2bi@ ] { } [ ] 4 2 mnmap-as ;
32 : mnmap-1-test ( a b c d -- e )
33 [ 4 nappend ] 4 1 mnmap ;
34 : mnmap-0-test ( a b c d -- )
35 [ 4 nappend print ] 4 0 mnmap ;
36 : nproduce-as-test ( n -- a b )
38 [ [ 2 - ] [ ] [ 1 - ] tri ] { } B{ } 2 nproduce-as
40 : nproduce-test ( n -- a b )
42 [ [ 2 - ] [ ] [ 1 - ] tri ] 2 nproduce
54 [ neach-test ] with-string-writer
57 { { "A1a!" "B2b@" "C3c#" "D4d$" } }
66 { [ "A1a!" "B2b@" "C3c#" "D4d$" ] }
78 { "a!" "b@" "c#" "d$" }
88 { "A1" "B2" "C3" "D4" }
89 { "a!" "b@" "c#" "d$" }
99 { "A1" "B2" "C3" "D4" }
100 [ "a!" "b@" "c#" "d$" ]
109 { { "A1a!" "B2b@" "C3c#" "D4d$" } }
127 [ mnmap-0-test ] with-string-writer
130 { { 10 8 6 4 2 } B{ 9 7 5 3 1 } }
131 [ 10 nproduce-as-test ] unit-test
133 { { 10 8 6 4 2 } { 9 7 5 3 1 } }
134 [ 10 nproduce-test ] unit-test
137 { 1 2 3 } { 4 5 6 } { 7 8 9 } [ + + ] [ + ] 3 nmap-reduce
141 { 1 3 5 } { 2 4 6 } { 4 8 12 } [ + + odd? ] 3 nall?
145 { 2 4 5 } { 4 6 7 } { 6 8 9 }
146 [ [ odd? ] tri@ and and ] 3 nany?
150 { 1 2 3 } { 4 5 6 } { 7 8 9 }
151 [ [ odd? ] tri@ and and ] 3 nany?