1 USING: arrays kernel math namespaces sequences kernel.private
2 sequences.private strings sbufs tools.test vectors
3 generic vocabs.loader ;
6 [ V{ 1 2 3 4 } ] [ 1 5 dup <slice> >vector ] unit-test
7 [ 3 ] [ 1 4 dup <slice> length ] unit-test
8 [ 2 ] [ 1 3 { 1 2 3 4 } <slice> length ] unit-test
9 [ V{ 2 3 } ] [ 1 3 { 1 2 3 4 } <slice> >vector ] unit-test
10 [ V{ 4 5 } ] [ { 1 2 3 4 5 } 2 tail-slice* >vector ] unit-test
11 [ V{ 3 4 } ] [ 2 4 1 10 dup <slice> subseq >vector ] unit-test
12 [ V{ 3 4 } ] [ 0 2 2 4 1 10 dup <slice> <slice> subseq >vector ] unit-test
13 [ "cba" ] [ "abcdef" 3 head-slice reverse ] unit-test
15 [ 5040 ] [ [ 1 2 3 4 5 6 7 ] 1 [ * ] reduce ] unit-test
17 [ 5040 [ 1 1 2 6 24 120 720 ] ]
18 [ [ 1 2 3 4 5 6 7 ] 1 [ * ] accumulate ] unit-test
20 [ f f ] [ [ ] [ ] find ] unit-test
21 [ 0 1 ] [ [ 1 ] [ ] find ] unit-test
22 [ 1 "world" ] [ [ "hello" "world" ] [ "world" = ] find ] unit-test
23 [ 2 3 ] [ [ 1 2 3 ] [ 2 > ] find ] unit-test
24 [ f f ] [ [ 1 2 3 ] [ 10 > ] find ] unit-test
27 [ "hello world" "aeiou" [ member? ] curry find ] unit-test
30 [ 3 "hello world" "aeiou" [ member? ] curry find-from ] unit-test
32 [ f ] [ 3 [ ] member? ] unit-test
33 [ f ] [ 3 [ 1 2 ] member? ] unit-test
34 [ t ] [ 1 [ 1 2 ] member? ] unit-test
35 [ t ] [ 2 [ 1 2 ] member? ] unit-test
38 [ [ "hello" "world" ] [ second ] keep memq? ] unit-test
40 [ 4 ] [ CHAR: x "tuvwxyz" >vector index ] unit-test
42 [ f ] [ CHAR: x 5 "tuvwxyz" >vector index-from ] unit-test
44 [ f ] [ CHAR: a 0 "tuvwxyz" >vector index-from ] unit-test
46 [ f ] [ [ "Hello" { } 0.75 ] [ string? ] all? ] unit-test
47 [ t ] [ [ ] [ ] all? ] unit-test
48 [ t ] [ [ "hi" t 0.5 ] [ ] all? ] unit-test
50 [ [ 1 2 3 ] ] [ [ 1 4 2 5 3 6 ] [ 4 < ] filter ] unit-test
51 [ { 4 2 6 } ] [ { 1 4 2 5 3 6 } [ 2 mod 0 = ] filter ] unit-test
53 [ [ 3 ] ] [ [ 1 2 3 ] 2 [ swap < ] curry filter ] unit-test
55 [ "hello world how are you" ]
56 [ { "hello" "world" "how" "are" "you" } " " join ]
59 [ "" ] [ { } "" join ] unit-test
61 [ { } ] [ { } flip ] unit-test
63 [ { "b" "e" } ] [ 1 { { "a" "b" "c" } { "d" "e" "f" } } flip nth ] unit-test
65 [ { { 1 4 } { 2 5 } { 3 6 } } ]
66 [ { { 1 2 3 } { 4 5 6 } } flip ] unit-test
68 [ f ] [ [ { } { } "Hello" ] all-equal? ] unit-test
69 [ f ] [ [ { 2 } { } { } ] all-equal? ] unit-test
70 [ t ] [ [ ] all-equal? ] unit-test
71 [ t ] [ [ 1234 ] all-equal? ] unit-test
72 [ f ] [ [ 1.0 1 1 ] all-equal? ] unit-test
73 [ t ] [ { 1 2 3 4 } [ < ] monotonic? ] unit-test
74 [ f ] [ { 1 2 3 4 } [ > ] monotonic? ] unit-test
75 [ [ 2 3 4 ] ] [ [ 1 2 3 ] 1 [ + ] curry map ] unit-test
77 [ 1 ] [ 0 [ 1 2 ] nth ] unit-test
78 [ 2 ] [ 1 [ 1 2 ] nth ] unit-test
80 [ [ ] ] [ [ ] [ ] append ] unit-test
81 [ [ 1 ] ] [ [ 1 ] [ ] append ] unit-test
82 [ [ 2 ] ] [ [ ] [ 2 ] append ] unit-test
83 [ [ 1 2 3 4 ] ] [ [ 1 2 3 ] [ 4 ] append ] unit-test
84 [ [ 1 2 3 4 ] ] [ [ 1 2 3 ] { 4 } append ] unit-test
86 [ "a" -1 append ] must-fail
87 [ -1 "a" append ] must-fail
89 [ [ ] ] [ 1 [ ] remove ] unit-test
90 [ [ ] ] [ 1 [ 1 ] remove ] unit-test
91 [ [ 3 1 1 ] ] [ 2 [ 3 2 1 2 1 ] remove ] unit-test
93 [ [ ] ] [ [ ] reverse ] unit-test
94 [ [ 1 ] ] [ [ 1 ] reverse ] unit-test
95 [ [ 3 2 1 ] ] [ [ 1 2 3 ] reverse ] unit-test
97 [ f ] [ f 0 head ] unit-test
98 [ [ ] ] [ [ 1 ] 0 head ] unit-test
99 [ [ 1 2 3 ] ] [ [ 1 2 3 4 ] 3 head ] unit-test
100 [ [ ] ] [ [ 1 2 3 ] 3 tail ] unit-test
101 [ [ 3 ] ] [ [ 1 2 3 ] 2 tail ] unit-test
103 [ "blah" ] [ "blahxx" 2 head* ] unit-test
105 [ "xx" ] [ "blahxx" 2 tail* ] unit-test
107 [ t ] [ "xxfoo" 2 head-slice "xxbar" 2 head-slice = ] unit-test
108 [ t ] [ "xxfoo" 2 head-slice "xxbar" 2 head-slice [ hashcode ] bi@ = ] unit-test
110 [ t ] [ "xxfoo" 2 head-slice SBUF" barxx" 2 tail-slice* = ] unit-test
111 [ t ] [ "xxfoo" 2 head-slice SBUF" barxx" 2 tail-slice* [ hashcode ] bi@ = ] unit-test
113 [ t ] [ [ 1 2 3 ] [ 1 2 3 ] sequence= ] unit-test
114 [ t ] [ [ 1 2 3 ] { 1 2 3 } sequence= ] unit-test
115 [ t ] [ { 1 2 3 } [ 1 2 3 ] sequence= ] unit-test
116 [ f ] [ [ ] [ 1 2 3 ] sequence= ] unit-test
118 [ { 1 3 2 4 } ] [ { 1 2 3 4 } clone 1 2 pick exchange ] unit-test
120 [ { "" "a" "aa" "aaa" } ]
121 [ 4 [ CHAR: a <string> ] map ]
124 [ V{ } ] [ "f" V{ } clone [ delete ] keep ] unit-test
125 [ V{ } ] [ "f" V{ "f" } clone [ delete ] keep ] unit-test
126 [ V{ } ] [ "f" V{ "f" "f" } clone [ delete ] keep ] unit-test
127 [ V{ "x" } ] [ "f" V{ "f" "x" "f" } clone [ delete ] keep ] unit-test
128 [ V{ "y" "x" } ] [ "f" V{ "y" "f" "x" "f" } clone [ delete ] keep ] unit-test
130 [ V{ 0 1 4 5 } ] [ 6 >vector 2 4 pick delete-slice ] unit-test
132 [ 6 >vector 2 8 pick delete-slice ] must-fail
134 [ V{ } ] [ 6 >vector 0 6 pick delete-slice ] unit-test
136 [ V{ 1 2 "a" "b" 5 6 7 } ] [
137 { "a" "b" } 2 4 V{ 1 2 3 4 5 6 7 } clone
138 [ replace-slice ] keep
141 [ V{ 1 2 "a" "b" 6 7 } ] [
142 { "a" "b" } 2 5 V{ 1 2 3 4 5 6 7 } clone
143 [ replace-slice ] keep
146 [ V{ 1 2 "a" "b" 4 5 6 7 } ] [
147 { "a" "b" } 2 3 V{ 1 2 3 4 5 6 7 } clone
148 [ replace-slice ] keep
151 [ V{ 1 2 3 4 5 6 7 "a" "b" } ] [
152 { "a" "b" } 7 7 V{ 1 2 3 4 5 6 7 } clone
153 [ replace-slice ] keep
157 { "a" } 0 2 V{ 1 2 3 } clone [ replace-slice ] keep
160 [ { 1 4 9 } ] [ { 1 2 3 } clone dup [ sq ] change-each ] unit-test
162 [ 5 ] [ 1 >bignum { 1 5 7 } nth-unsafe ] unit-test
163 [ 5 ] [ 1 >bignum { 1 5 7 } nth-unsafe ] unit-test
164 [ 5 ] [ 1 >bignum "\u000001\u000005\u000007" nth-unsafe ] unit-test
166 [ SBUF" before&after" ] [
167 "&" 6 11 SBUF" before and after" [ replace-slice ] keep
170 [ 3 "a" ] [ { "a" "b" "c" "a" "d" } [ "a" = ] find-last ] unit-test
172 [ f f ] [ 100 { 1 2 3 } [ 1 = ] find-from ] unit-test
173 [ f f ] [ 100 { 1 2 3 } [ 1 = ] find-last-from ] unit-test
174 [ f f ] [ -1 { 1 2 3 } [ 1 = ] find-from ] unit-test
176 [ 0 ] [ { "a" "b" "c" } { "A" "B" "C" } mismatch ] unit-test
178 [ 1 ] [ { "a" "b" "c" } { "a" "B" "C" } mismatch ] unit-test
180 [ f ] [ { "a" "b" "c" } { "a" "b" "c" } mismatch ] unit-test
182 [ V{ } V{ } ] [ { "a" "b" } { "a" "b" } drop-prefix [ >vector ] bi@ ] unit-test
184 [ V{ "C" } V{ "c" } ] [ { "a" "b" "C" } { "a" "b" "c" } drop-prefix [ >vector ] bi@ ] unit-test
186 [ -1 1 "abc" <slice> ] must-fail
188 [ V{ "a" "b" } V{ } ] [ { "X" "a" "b" } { "X" } drop-prefix [ >vector ] bi@ ] unit-test
190 [ 1 4 9 16 16 V{ f 1 4 9 16 } ] [
191 V{ } clone "cache-test" set
192 1 "cache-test" get [ sq ] cache-nth
193 2 "cache-test" get [ sq ] cache-nth
194 3 "cache-test" get [ sq ] cache-nth
195 4 "cache-test" get [ sq ] cache-nth
196 4 "cache-test" get [ "wrong" ] cache-nth
200 [ 1 ] [ 0.5 { 1 2 3 } nth ] unit-test
203 [ "ihbye" ] [ "hi" <reversed> "bye" append ] unit-test
205 [ t ] [ "hi" <reversed> SBUF" hi" <reversed> = ] unit-test
207 [ t ] [ "hi" <reversed> SBUF" hi" <reversed> = ] unit-test
209 [ t ] [ "hi" <reversed> SBUF" hi" <reversed> [ hashcode ] bi@ = ] unit-test
211 [ -10 "hi" "bye" copy ] must-fail
212 [ 10 "hi" "bye" copy ] must-fail
215 3 V{ 1 2 3 4 5 6 } clone [ delete-nth ] keep
218 ! erg's random tester found this one
219 [ SBUF" 12341234" ] [
220 9 <sbuf> dup "1234" swap push-all dup dup swap push-all
223 [ f ] [ f V{ } like f V{ } like eq? ] unit-test
225 [ V{ f f f } ] [ 3 V{ } new-sequence ] unit-test
226 [ SBUF" \0\0\0" ] [ 3 SBUF" " new-sequence ] unit-test
228 [ 0 ] [ f length ] unit-test
229 [ f first ] must-fail
230 [ 3 ] [ 3 10 nth ] unit-test
231 [ 3 ] [ 3 10 nth-unsafe ] unit-test
232 [ -3 10 nth ] must-fail
233 [ 11 10 nth ] must-fail
235 [ -1./0. 0 delete-nth ] must-fail
236 [ "" ] [ "" [ CHAR: \s = ] trim ] unit-test
237 [ "" ] [ "" [ CHAR: \s = ] left-trim ] unit-test
238 [ "" ] [ "" [ CHAR: \s = ] right-trim ] unit-test
239 [ "" ] [ " " [ CHAR: \s = ] left-trim ] unit-test
240 [ "" ] [ " " [ CHAR: \s = ] right-trim ] unit-test
241 [ "asdf" ] [ " asdf " [ CHAR: \s = ] trim ] unit-test
242 [ "asdf " ] [ " asdf " [ CHAR: \s = ] left-trim ] unit-test
243 [ " asdf" ] [ " asdf " [ CHAR: \s = ] right-trim ] unit-test
245 [ 328350 ] [ 100 [ sq ] sigma ] unit-test
247 [ 50 ] [ 100 [ even? ] count ] unit-test
248 [ 50 ] [ 100 [ odd? ] count ] unit-test
250 [ { "b" "d" } ] [ { "a" "b" "c" "d" } { 1 3 } nths ] unit-test
251 [ { "a" "b" "c" "d" } ] [ { "a" "b" "c" "d" } { 0 1 2 3 } nths ] unit-test
252 [ { "d" "c" "b" "a" } ] [ { "a" "b" "c" "d" } { 3 2 1 0 } nths ] unit-test
253 [ { "d" "a" "b" "c" } ] [ { "a" "b" "c" "d" } { 3 0 1 2 } nths ] unit-test
255 TUPLE: bogus-hashcode ;
257 M: bogus-hashcode hashcode* 2drop 0 >bignum ;
259 [ 0 ] [ { T{ bogus-hashcode } } hashcode ] unit-test