factor/library/test/dataflow.factor

99 lines
2.3 KiB
Factor
Raw Normal View History

IN: scratchpad
USE: inference
USE: lists
USE: math
USE: test
2004-11-29 23:14:12 -05:00
USE: hashtables
USE: kernel
USE: vectors
USE: namespaces
2004-11-30 23:56:01 -05:00
USE: prettyprint
2004-12-02 22:44:36 -05:00
USE: words
USE: kernel
USE: generic
2004-11-29 23:14:12 -05:00
: dataflow-contains-op? ( object list -- ? )
#! Check if some dataflow node contains a given operation.
[ dupd node-op swap hash = ] some? nip ;
: dataflow-contains-param? ( object list -- ? )
#! Check if some dataflow node contains a given operation.
2004-12-04 23:45:41 -05:00
[
dupd [
node-op get #label = [
node-param get dataflow-contains-param?
] [
node-param get =
] ifte
] bind
] some? nip ;
2004-11-29 23:14:12 -05:00
[ t ] [
\ + [ 2 2 + ] dataflow dataflow-contains-param? >boolean
] unit-test
: inline-test
car car ; inline
[ t ] [
\ car [ inline-test ] dataflow dataflow-contains-param? >boolean
] unit-test
[ t ] [
#ifte [ [ drop ] [ + ] ifte ] dataflow dataflow-contains-op? >boolean
2004-11-29 23:14:12 -05:00
] unit-test
: dataflow-consume-d-len ( object -- n )
2004-12-02 22:44:36 -05:00
[ node-consume-d get length ] bind ;
2004-11-29 23:14:12 -05:00
: dataflow-produce-d-len ( object -- n )
2004-12-02 22:44:36 -05:00
[ node-produce-d get length ] bind ;
2004-11-29 23:14:12 -05:00
[ t ] [ [ drop ] dataflow car dataflow-consume-d-len 1 = ] unit-test
[ t ] [ [ 2 ] dataflow car dataflow-produce-d-len 1 = ] unit-test
: dataflow-ifte-node-consume-d ( list -- node )
#ifte swap dataflow-contains-op? car [ node-consume-d get ] bind ;
2004-11-29 23:14:12 -05:00
[ t ] [
[ 2 [ swap ] [ nip "hi" ] ifte ] dataflow
2004-12-02 22:44:36 -05:00
dataflow-ifte-node-consume-d length 1 =
2004-11-29 23:14:12 -05:00
] unit-test
2004-11-30 23:56:01 -05:00
[ t ] [
[ { [ drop ] [ undefined-method ] [ drop ] [ undefined-method ] } generic ] dataflow
2004-12-13 16:28:28 -05:00
#dispatch swap dataflow-contains-op? car [
2004-11-30 23:56:01 -05:00
node-param get [
2004-12-10 18:38:40 -05:00
[ [ node-param get \ undefined-method = ] bind ] some?
2004-11-30 23:56:01 -05:00
] some?
] bind >boolean
] unit-test
2004-12-02 22:44:36 -05:00
SYMBOL: #test
#test f "foobar" set-word-property
[ 6 ] [
{{
[ node-op | #test ]
[ node-param | 5 ]
2004-12-03 22:12:58 -05:00
}} "foobar" [ [ node-param get ] bind succ ] apply-dataflow
2004-12-02 22:44:36 -05:00
] unit-test
2004-12-03 22:12:58 -05:00
#test [ [ node-param get ] bind sq ] "foobar" set-word-property
2004-12-02 22:44:36 -05:00
[ 25 ] [
{{
[ node-op | #test ]
[ node-param | 5 ]
2004-12-03 22:12:58 -05:00
}} "foobar" [ [ node-param get ] bind succ ] apply-dataflow
2004-12-02 22:44:36 -05:00
] unit-test
2004-12-04 23:45:41 -05:00
! Somebody (cough) got the order of ifte nodes wrong.
[ t ] [
#ifte [ [ 1 ] [ 2 ] ifte ] dataflow dataflow-contains-op? car
[ node-param get ] bind car car [ node-param get ] bind 1 =
] unit-test