USING: accessors arrays ascii io io.streams.string kernel make math math.vectors random sequences sequences.extras strings tools.test vectors vocabs ; { V{ { 0 104 } { 2 108 } { 3 108 } } } [ "hello" [ even? ] find-all ] unit-test { { "a" "b" "c" "d" "ab" "bc" "cd" "abc" "bcd" "abcd" } } [ "abcd" all-subseqs ] unit-test { { "a" "ab" "abc" "abcd" "b" "bc" "bcd" "c" "cd" "d" } } [ [ "abcd" [ , ] each-subseq ] { } make ] unit-test { B{ 115 } } [ 1 2 "asdf" B{ } subseq-as ] unit-test { "" } [ "abc" "def" longest-subseq ] unit-test { "abcd" } [ "abcd" "abcde" longest-subseq ] unit-test { "foo" } [ "foo" "foobar" longest-subseq ] unit-test { "foo" } [ "foobar" "foo" longest-subseq ] unit-test { "" "" } [ "" "" CHAR: ? pad-longest ] unit-test { "abc" "def" } [ "abc" "def" CHAR: ? pad-longest ] unit-test { " " "abc" } [ "" "abc" CHAR: \s pad-longest ] unit-test { "abc" " " } [ "abc" "" CHAR: \s pad-longest ] unit-test { "abc..." "foobar" } [ "abc" "foobar" CHAR: . pad-longest ] unit-test { { "ABC" "ABC" "ABC" "ABC" "ABC-" "-ABC-" "-ABC--" "--ABC--" } } [ "ABC" 8 [ CHAR: - pad-center ] with map ] unit-test { { 0 1 0 1 } } [ { 0 0 0 0 } { 1 3 } over [ 1 + ] change-nths ] unit-test { V{ f t f } } [ { 1 2 3 } [ even? ] selector* [ each ] dip ] unit-test { { 1 3 5 } } [ { 1 2 3 4 5 6 } [ nip even? ] filter-index ] unit-test { V{ 1 3 5 } } [ { 1 2 3 4 5 6 } [ nip even? ] V{ } filter-index-as ] unit-test { { 1 3 5 } } [ { 1 2 3 4 5 6 } even-indices ] unit-test { { 2 4 6 } } [ { 1 2 3 4 5 6 } odd-indices ] unit-test { "a b c d e" } [ "a b \t \n \r c d \n e " [ ascii:blank? ] " " compact ] unit-test { " a b c d e " } [ " a b c d e " [ ascii:blank? ] " " collapse ] unit-test { { "hello," " " "world!" " " " " } } [ "hello, world! " [ ascii:blank? ] slice-when [ >string ] map ] unit-test { t } [ "abc" sequence>slice slice? ] unit-test { "abc" } [ "abc" sequence>slice >string ] unit-test { t } [ "abcdef" [ 0 3 rot ] [ 2 4 rot ] bi slices-overlap? ] unit-test { t } [ "abcdef" [ 0 3 rot ] [ 1 2 rot ] bi slices-overlap? ] unit-test { f } [ "abcdef" [ 0 3 rot ] [ 3 6 rot ] bi slices-overlap? ] unit-test { t } [ "abcdef" [ 0 3 rot ] [ 2 4 rot ] bi slices-touch? ] unit-test { t } [ "abcdef" [ 0 3 rot ] [ 1 2 rot ] bi slices-touch? ] unit-test { t } [ "abcdef" [ 0 3 rot ] [ 3 6 rot ] bi slices-touch? ] unit-test { f } [ "abcdef" [ 0 3 rot ] [ 4 6 rot ] bi slices-touch? ] unit-test { "abcdef" } [ "abcdef" [ 0 3 rot ] [ 3 6 rot ] bi merge-slices >string ] unit-test { "abcdef" } [ "abcdef" [ 3 6 rot ] [ 0 3 rot ] bi merge-slices >string ] unit-test { "abc" } [ "abcdef" [ 0 3 rot ] [ 0 3 rot ] bi merge-slices >string ] unit-test { "hello" "hello" } [ "hello" dup 0 rotate ] unit-test { "hello" "llohe" } [ "hello" dup 2 rotate ] unit-test { "hello" "lohel" } [ "hello" dup 13 rotate ] unit-test { "hello" "ohell" } [ "hello" dup -1 rotate ] unit-test { "hello" "lohel" } [ "hello" dup -12 rotate ] unit-test { "hello" } [ "hello" dup 0 rotate! ] unit-test { "llohe" } [ "hello" dup 2 rotate! ] unit-test { "lohel" } [ "hello" dup 13 rotate! ] unit-test { "ohell" } [ "hello" dup -1 rotate! ] unit-test { "lohel" } [ "hello" dup -12 rotate! ] unit-test { { } } [ { } [ ] map-concat ] unit-test { V{ 0 0 1 0 1 2 } } [ 4 [ ] map-concat ] unit-test { "abc" } [ "abc" [ 1string ] map-concat ] unit-test { "abc" } [ { 97 98 99 } [ 1string ] map-concat ] unit-test { { 97 98 99 } } [ "abc" [ 1string ] { } map-concat-as ] unit-test { "baz" { "foobaz" "barbaz" } } [ "baz" { { "foo" } { "bar" } } [ [ over append ] map ] map-concat ] unit-test { { } } [ { } [ ] [ even? ] map-filter ] unit-test { "bcde" } [ "abcd" [ 1 + ] [ drop t ] map-filter ] unit-test { { 0 4 16 36 64 } } [ 10 [ sq ] [ even? ] { } map-filter-as ] unit-test { V{ 0 4 16 36 64 } } [ 10 [ even? ] [ sq ] filter-map ] unit-test { { 2 6 10 14 18 } } [ 10 [ odd? ] [ 2 * ] { } filter-map-as ] unit-test { 8 } [ 3 dup [ 1 + * ] 2map-sum ] unit-test { 4 } [ "hello" "jello" [ = ] 2count ] unit-test { { } } [ { } round-robin ] unit-test { "ADEBFC" } [ { "ABC" "D" "EF" } round-robin >string ] unit-test { { } } [ "ABC" [ ] { } trim-as ] unit-test { "ABC" } [ { 32 65 66 67 32 } [ ascii:blank? ] "" trim-as ] unit-test { t } [ "ABC" dup [ ascii:blank? ] ?trim [ identity-hashcode ] same? ] unit-test { "ABC" } [ " ABC " [ ascii:blank? ] ?trim ] unit-test { t } [ "ABC" dup [ ascii:blank? ] ?trim-head [ identity-hashcode ] same? ] unit-test { t } [ "ABC" dup [ ascii:blank? ] ?trim-tail [ identity-hashcode ] same? ] unit-test { "ABC " } [ " ABC " [ ascii:blank? ] ?trim-head ] unit-test { " ABC" } [ " ABC " [ ascii:blank? ] ?trim-tail ] unit-test { "" } [ "" "" "" unsurround ] unit-test { "" } [ " " " " " " unsurround ] unit-test { "foo.com" } [ "http://foo.com" "http://" "/" unsurround ] unit-test { t } [ { 1 3 5 7 } [ even? ] none? ] unit-test { f } [ { 1 2 3 4 } [ even? ] none? ] unit-test { t } [ { } [ even? ] none? ] unit-test { f } [ { 1 2 3 4 } [ even? ] one? ] unit-test { t } [ { 1 2 3 } [ even? ] one? ] unit-test { f } [ { } [ even? ] one? ] unit-test { { { 5 8 0 } { 6 9 1 } { 7 10 2 } } } [ { 5 6 7 } { 8 9 10 } [ 3array ] 2map-index ] unit-test { { } } [ { } >array ] unit-test { { 0 2 } } [ 4 >array ] unit-test { { 0 2 4 } } [ 5 >array ] unit-test { "bbddff" } [ "abcdef" [ 1 + ] map! seq>> ] unit-test { { } } [ { } >array ] unit-test { { 1 3 } } [ 5 >array ] unit-test { { 1 3 5 } } [ 6 >array ] unit-test { "acceeg" } [ "abcdef" [ 1 + ] map! seq>> ] unit-test { 1 } [ { 1 7 3 7 6 3 7 } arg-max ] unit-test { 2 } [ { 0 1 99 } arg-max ] unit-test { 0 } [ { 1 7 3 7 6 3 7 } arg-min ] unit-test { V{ 0 4 } } [ { 5 3 2 10 5 } [ 5 = ] arg-where ] unit-test { { 2 1 0 4 3 } } [ { 5 3 2 10 5 } arg-sort ] unit-test { t } [ { 1 2 3 4 5 } 1 first= ] unit-test { t } [ { 1 2 3 4 5 } 2 second= ] unit-test { t } [ { 1 2 3 4 5 } 3 third= ] unit-test { t } [ { 1 2 3 4 5 } 4 fourth= ] unit-test { t } [ { 1 2 3 4 5 } 5 last= ] unit-test { t } [ 4 { 1 2 3 4 5 } 5 nth= ] unit-test { t } [ { 1 2 3 4 5 } [ 1 = ] first? ] unit-test { t } [ { 1 2 3 4 5 } [ 2 = ] second? ] unit-test { t } [ { 1 2 3 4 5 } [ 3 = ] third? ] unit-test { t } [ { 1 2 3 4 5 } [ 4 = ] fourth? ] unit-test { t } [ { 1 2 3 4 5 } [ 5 = ] last? ] unit-test { t } [ 4 { 1 2 3 4 5 } [ 5 = ] nth? ] unit-test { { 97 115 100 102 } } [ "asdf" [ [ read1 ] loop>array ] with-string-reader ] unit-test { V{ 97 115 100 102 } } [ "asdf" [ [ read1 ] V{ } loop>sequence ] with-string-reader ] unit-test { "" } [ { } "" reverse-as ] unit-test { "ABC" } [ { 67 66 65 } "" reverse-as ] unit-test { V{ 1 } } [ 1 0 V{ } [ insert-nth! ] keep ] unit-test { V{ 1 2 3 4 } } [ 2 1 V{ 1 3 4 } [ insert-nth! ] keep ] unit-test { "abc" } [ B{ 97 98 99 100 101 102 103 } 3 "" head-as ] unit-test { "abcd" } [ B{ 97 98 99 100 101 102 103 } 3 "" head*-as ] unit-test { "defg" } [ B{ 97 98 99 100 101 102 103 } 3 "" tail-as ] unit-test { "efg" } [ B{ 97 98 99 100 101 102 103 } 3 "" tail*-as ] unit-test { { 1 0 0 1 0 0 0 1 0 0 } } [ 1 { 0 3 7 } 10 0 [ set-nths ] keep ] unit-test { { 1 0 0 1 0 0 0 1 0 0 } } [ 1 { 0 3 7 } 10 0 [ set-nths-unsafe ] keep ] unit-test { t 3 3 } [ 10 [ [ odd? ] [ 1 > ] bi* and ] map-find-index ] unit-test { f f f } [ 10 [ [ odd? ] [ 9 > ] bi* and ] map-find-index ] unit-test { "abcdef" } [ f f "abcdef" subseq* ] unit-test { "abcdef" } [ 0 f "abcdef" subseq* ] unit-test { "ab" } [ f 2 "abcdef" subseq* ] unit-test { "cdef" } [ 2 f "abcdef" subseq* ] unit-test { "cd" } [ -4 -2 "abcdef" subseq* ] unit-test { "foo" "" } [ "foo" [ ascii:blank? ] cut-when ] unit-test { "foo" " " } [ "foo " [ ascii:blank? ] cut-when ] unit-test { "" " foo" } [ " foo" [ ascii:blank? ] cut-when ] unit-test { "foo" " bar" } [ "foo bar" [ ascii:blank? ] cut-when ] unit-test { { 4 0 3 1 2 } } [ { 0 4 1 3 2 } 5 [ nth* ] curry map ] unit-test { 1 "beef" } [ { "chicken" "beef" "moose" } [ length ] infimum-by* ] unit-test { 0 "chicken" } [ { "chicken" "beef" "moose" } [ length ] supremum-by* ] unit-test { 2 "moose" } [ { "chicken" "beef" "moose" } [ first ] supremum-by* ] unit-test { f } [ f ?supremum ] unit-test { f } [ { } ?supremum ] unit-test { f } [ { f } ?supremum ] unit-test { 3 } [ { 1 f 3 2 } ?supremum ] unit-test { 3 } [ { 1 3 2 } ?supremum ] unit-test { f } [ f ?infimum ] unit-test { f } [ { } ?infimum ] unit-test { f } [ { f } ?infimum ] unit-test { 1 } [ { 1 f 3 2 } ?infimum ] unit-test { 1 } [ { 1 3 2 } ?infimum ] unit-test { 3/10 } [ 10 [ 3 < ] count* ] unit-test { { 0 } } [ "ABABA" "ABA" start-all ] unit-test { { 0 2 } } [ "ABABA" "ABA" start-all* ] unit-test { { 0 3 } } [ "ABAABA" "ABA" start-all ] unit-test { 1 } [ "ABABA" "ABA" count-subseq ] unit-test { 2 } [ "ABABA" "ABA" count-subseq* ] unit-test { 120000 } [ { 10 20 30 40 50 60 } 1 [ * ] 3 reduce-from ] unit-test { { 0 1 2 3 } } [ 8 [ 4 < ] take-while >array ] unit-test { { } } [ { 15 16 } [ 4 < ] take-while >array ] unit-test { { 0 1 2 } } [ 3 [ 4 < ] take-while >array ] unit-test { { 4 5 6 7 } } [ 8 [ 4 < ] drop-while >array ] unit-test { { 15 16 } } [ { 15 16 } [ 4 < ] drop-while >array ] unit-test { { } } [ 3 [ 4 < ] drop-while >array ] unit-test { { } } [ { } ", " interleaved ] unit-test { { 1 } } [ { 1 } ", " interleaved ] unit-test { { 1 ", " 2 } } [ { 1 2 } ", " interleaved ] unit-test { "" } [ "" CHAR: _ interleaved ] unit-test { "a" } [ "a" CHAR: _ interleaved ] unit-test { "a_b" } [ "ab" CHAR: _ interleaved ] unit-test { "a_b_c" } [ "abc" CHAR: _ interleaved ] unit-test { "a_b_c_d" } [ "abcd" CHAR: _ interleaved ] unit-test { 0 } [ { 1 2 3 4 } [ 5 > ] count-head ] unit-test { 2 } [ { 1 2 3 4 } [ 3 < ] count-head ] unit-test { 4 } [ { 1 2 3 4 } [ 5 < ] count-head ] unit-test { 0 } [ { 1 2 3 4 } [ 5 > ] count-tail ] unit-test { 2 } [ { 1 2 3 4 } [ 2 > ] count-tail ] unit-test { 4 } [ { 1 2 3 4 } [ 5 < ] count-tail ] unit-test { SBUF" aco" SBUF" ftr" } [ SBUF" factor" dup [ even? ] extract! ] unit-test { 25 5 1 } [ { 4 5 6 } [ sq ] [ 20 > ] find-pred ] unit-test { f f f } [ { 4 5 6 } [ sq ] [ 200 > ] find-pred ] unit-test { -1/0. } [ { } max-subarray-sum ] unit-test { -2 } [ { -3 -2 } max-subarray-sum ] unit-test { 7 } [ { 1 2 3 -4 5 } max-subarray-sum ] unit-test { 6 } [ { 1 2 3 -4 1 1 } max-subarray-sum ] unit-test { { 9 7 5 } } [ -1 -6 -2 10 >array ] unit-test { { 9 7 } } [ -1 -5 -2 10 >array ] unit-test { { 9 7 } } [ -1 -4 -2 10 >array ] unit-test { { 9 } } [ -1 -3 -2 10 >array ] unit-test { { } } [ -4 10 -2 10 >array ] unit-test { { 6 8 } } [ -4 15 2 10 >array ] unit-test { { 1 3 } } [ 1 4 2 10 >array ] unit-test { { 1 3 } } [ 1 5 2 10 >array ] unit-test { { 1 3 5 } } [ 1 6 2 10 >array ] unit-test { { 102 306 1530 } } [ { 2 3 5 } [ swap [ * ] [ 100 + ] if* ] map-with-previous ] unit-test { { } } [ { } [ nip ] map-with-previous ] unit-test { { -1 2 -3 4 -5 } } [ { 1 2 3 4 5 } [ odd? ] [ neg ] map-if ] unit-test { { { 100 0 } { 200 1 } { 300 2 } { 400 3 } } } [ { 100 200 300 400 } >array ] unit-test