1 ! Copyright (C) 2009 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors arrays combinators.smart kernel math
5 IN: combinators.smart.tests
8 10 [ 1 - ] [ 1 + ] bi ;
10 [ [ test-bi ] output>array ] must-infer
11 [ { 9 11 } ] [ [ test-bi ] output>array ] unit-test
13 [ { 9 11 } [ + ] input<sequence ] must-infer
14 [ 20 ] [ { 9 11 } [ + ] input<sequence ] unit-test
16 [ 6 ] [ [ 1 2 3 ] [ + ] reduce-outputs ] unit-test
18 [ [ 1 2 3 ] [ + ] reduce-outputs ] must-infer
20 [ 6 ] [ [ 1 2 3 ] sum-outputs ] unit-test
24 [ "a" "b" ] "" append-outputs-as
29 [ ] "" append-outputs-as
39 [ { 1 } { 2 } { 3 } ] B{ } append-outputs-as
43 : nested-smart-combo-test ( -- array )
44 [ [ 1 2 ] output>array [ 3 4 ] output>array ] output>array ;
46 \ nested-smart-combo-test def>> must-infer
48 [ { { 1 2 } { 3 4 } } ] [ nested-smart-combo-test ] unit-test
50 [ 14 ] [ [ 1 2 3 ] [ sq ] [ + ] map-reduce-outputs ] unit-test
52 { 2 3 } [ [ + ] preserving ] must-infer-as
54 { 2 0 } [ [ + ] nullary ] must-infer-as
56 { 2 2 } [ [ [ + ] nullary ] preserving ] must-infer-as
58 : smart-if-test ( a b -- b )
59 [ < ] [ swap - ] [ - ] smart-if ;
61 [ 7 ] [ 10 3 smart-if-test ] unit-test
62 [ 16 ] [ 25 41 smart-if-test ] unit-test
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