]> gitweb.factorcode.org Git - factor.git/blob - basis/combinators/smart/smart-tests.factor
Merge branch 'master' into s3
[factor.git] / basis / combinators / smart / smart-tests.factor
1 ! Copyright (C) 2009 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors arrays combinators.smart kernel math
4 tools.test ;
5 IN: combinators.smart.tests
6
7 : test-bi ( -- 9 11 )
8     10 [ 1 - ] [ 1 + ] bi ;
9
10 [ [ test-bi ] output>array ] must-infer
11 [ { 9 11 } ] [ [ test-bi ] output>array ] unit-test
12
13 [ { 9 11 } [ + ] input<sequence ] must-infer
14 [ 20 ] [ { 9 11 } [ + ] input<sequence ] unit-test
15
16 [ 6 ] [ [ 1 2 3 ] [ + ] reduce-outputs ] unit-test
17
18 [ [ 1 2 3 ] [ + ] reduce-outputs ] must-infer
19
20 [ 6 ] [ [ 1 2 3 ] sum-outputs ] unit-test
21
22 [ "ab" ]
23 [
24     [ "a" "b" ] "" append-outputs-as
25 ] unit-test
26
27 [ "" ]
28 [
29     [ ] "" append-outputs-as
30 ] unit-test
31
32 [ { } ]
33 [
34     [ ] append-outputs
35 ] unit-test
36
37 [ B{ 1 2 3 } ]
38 [
39     [ { 1 } { 2 } { 3 } ] B{ } append-outputs-as
40 ] unit-test
41
42 ! Test nesting
43 : nested-smart-combo-test ( -- array )
44     [ [ 1 2 ] output>array [ 3 4 ] output>array ] output>array ;
45
46 \ nested-smart-combo-test def>> must-infer
47
48 [ { { 1 2 } { 3 4 } } ] [ nested-smart-combo-test ] unit-test
49
50 [ 14 ] [ [ 1 2 3 ] [ sq ] [ + ] map-reduce-outputs ] unit-test
51
52 { 2 3 } [ [ + ] preserving ] must-infer-as
53
54 { 2 0 } [ [ + ] nullary ] must-infer-as
55
56 { 2 2 } [ [ [ + ] nullary ] preserving ] must-infer-as
57
58 : smart-if-test ( a b -- b )
59     [ < ] [ swap - ] [ - ] smart-if ;
60
61 [ 7 ] [ 10 3 smart-if-test ] unit-test
62 [ 16 ] [ 25 41 smart-if-test ] unit-test
63
64 [ { 1 2 } { 3 4 } { 5 6 } ] [ 1 2 3 4 5 6 [ 2array ] 3 smart-apply ] unit-test
65 [ { 1 2 3 } { 4 5 6 } ] [ 1 2 3 4 5 6 [ 3array ] 2 smart-apply ] unit-test
66
67 [ 4 ] [ 2 [ even? ] [ 2 + ] smart-when ] unit-test
68 [ 3 ] [ 3 [ even? ] [ 2 + ] smart-when ] unit-test
69 [ 4 ] [ 2 [ odd? ] [ 2 + ] smart-unless ] unit-test
70 [ 3 ] [ 3 [ odd? ] [ 2 + ] smart-unless ] unit-test
71
72 [ 4 ] [ 2 [ even? ] [ 2 + ] smart-when* ] unit-test
73 [ ] [ 3 [ even? ] [ 2 + ] smart-when* ] unit-test
74 [ 3 ] [ 2 [ odd? ] [ 3 ] smart-unless* ] unit-test
75 [ 3 ] [ 3 [ odd? ] [ 5 ] smart-unless* ] unit-test
76
77 [ -1 ] [ 1 2 [ + odd? ] [ - ] smart-when* ] unit-test
78 [ ] [ 2 2 [ + odd? ] [ ] smart-unless* ] unit-test