1 ! Copyright (C) 2010 Joe Groff.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors cursors kernel make math sequences sorting tools.test ;
4 FROM: cursors => each map assoc-each assoc>map ;
8 [ T{ linear-cursor f 1 1 } T{ linear-cursor f 5 1 } [ value>> , ] -each ]
12 { T{ linear-cursor f 3 1 } } [
13 T{ linear-cursor f 1 1 } T{ linear-cursor f 5 1 } [ value>> 3 mod zero? ] -find
16 { T{ linear-cursor f 5 1 } } [
17 T{ linear-cursor f 1 1 } T{ linear-cursor f 5 1 } [ value>> 6 = ] -find
21 [ T{ linear-cursor f 1 2 } T{ linear-cursor f 5 2 } [ value>> , ] -each ]
25 { B{ 1 2 3 4 5 } } [ [ { 1 2 3 4 5 } [ , ] each ] B{ } make ] unit-test
26 { B{ } } [ [ { } [ , ] each ] B{ } make ] unit-test
27 { { 2 4 6 8 10 } } [ { 1 2 3 4 5 } [ 2 * ] map ] unit-test
29 { { "roses: lutefisk" "tulips: lox" } }
32 H{ { "roses" "lutefisk" } { "tulips" "lox" } }
33 [ ": " glue , ] assoc-each
34 ] { } make natural-sort
37 { { "roses: lutefisk" "tulips: lox" } }
39 H{ { "roses" "lutefisk" } { "tulips" "lox" } }
40 [ ": " glue ] { } assoc>map natural-sort
43 : compile-test-each ( xs -- )
46 : compile-test-map ( xs -- ys )
49 : compile-test-assoc-each ( xs -- )
50 [ ": " glue , ] assoc-each ;
52 : compile-test-assoc>map ( xs -- ys )
53 [ ": " glue ] { } assoc>map ;
55 { B{ 1 2 3 4 5 } } [ [ { 1 2 3 4 5 } compile-test-each ] B{ } make ] unit-test
56 { { 2 4 6 8 10 } } [ { 1 2 3 4 5 } compile-test-map ] unit-test
58 { { "roses: lutefisk" "tulips: lox" } }
60 [ H{ { "roses" "lutefisk" } { "tulips" "lox" } } compile-test-assoc-each ]
64 { { "roses: lutefisk" "tulips: lox" } }
66 H{ { "roses" "lutefisk" } { "tulips" "lox" } } compile-test-assoc>map