]> gitweb.factorcode.org Git - factor.git/blob - extra/cursors/cursors-tests.factor
Update some copyright headers to follow the current convention
[factor.git] / extra / cursors / cursors-tests.factor
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 ;
5 IN: cursors.tests
6
7 { { 1 2 3 4 } } [
8     [ T{ linear-cursor f 1 1 } T{ linear-cursor f 5 1 } [ value>> , ] -each ]
9     { } make
10 ] unit-test
11
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
14 ] unit-test
15
16 { T{ linear-cursor f 5 1 } } [
17     T{ linear-cursor f 1 1 } T{ linear-cursor f 5 1 } [ value>> 6 = ] -find
18 ] unit-test
19
20 { { 1 3 } } [
21     [ T{ linear-cursor f 1 2 } T{ linear-cursor f 5 2 } [ value>> , ] -each ]
22     { } make
23 ] unit-test
24
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
28
29 { { "roses: lutefisk" "tulips: lox" } }
30 [
31     [
32         H{ { "roses" "lutefisk" } { "tulips" "lox" } }
33         [ ": " glue , ] assoc-each
34     ] { } make natural-sort
35 ] unit-test
36
37 { { "roses: lutefisk" "tulips: lox" } }
38 [
39     H{ { "roses" "lutefisk" } { "tulips" "lox" } }
40     [ ": " glue ] { } assoc>map natural-sort
41 ] unit-test
42
43 : compile-test-each ( xs -- )
44     [ , ] each ;
45
46 : compile-test-map ( xs -- ys )
47     [ 2 * ] map ;
48
49 : compile-test-assoc-each ( xs -- )
50     [ ": " glue , ] assoc-each ;
51
52 : compile-test-assoc>map ( xs -- ys )
53     [ ": " glue ] { } assoc>map ;
54
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
57
58 { { "roses: lutefisk" "tulips: lox" } }
59 [
60     [ H{ { "roses" "lutefisk" } { "tulips" "lox" } } compile-test-assoc-each ]
61     { } make natural-sort
62 ] unit-test
63
64 { { "roses: lutefisk" "tulips: lox" } }
65 [
66     H{ { "roses" "lutefisk" } { "tulips" "lox" } } compile-test-assoc>map
67     natural-sort
68 ] unit-test