factor/library/test/random.factor

44 lines
761 B
Factor
Raw Normal View History

2004-07-16 02:26:21 -04:00
IN: scratchpad
USE: kernel
USE: lists
USE: logic
2004-08-26 22:21:17 -04:00
USE: math
2004-07-16 02:26:21 -04:00
USE: namespaces
USE: random
USE: stack
2004-07-16 02:26:21 -04:00
USE: test
[ t ]
[ [ 1 2 3 ] random-element number? ]
unit-test
2004-07-16 02:26:21 -04:00
[
[ 10 | t ]
[ 20 | f ]
[ 30 | "monkey" ]
[ 24 | 1/2 ]
[ 13 | { "Hello" "Banana" } ]
2004-07-16 02:26:21 -04:00
] "random-pairs" set
"random-pairs" get [ cdr ] map "random-values" set
2004-07-16 02:26:21 -04:00
[ f ]
[
"random-pairs" get
random-element* "random-values" get contains? not
] unit-test
: check-random-int ( min max -- )
2dup random-int -rot between? assert ;
2004-07-16 02:26:21 -04:00
[ ] [ 100 [ -12 674 check-random-int ] times ] unit-test
: check-random-subset ( expected pairs -- )
random-subset* [ over contains? ] all? nip ;
[ t ] [
"random-values" get
"random-pairs" get
check-random-subset
] unit-test