Move delete-random to sequences.lib

Add some unit tests
release
Doug Coleman 2007-11-05 01:50:19 -06:00
parent 6c8808dd8d
commit 3e40ab714e
2 changed files with 9 additions and 1 deletions

View File

@ -33,3 +33,9 @@ math.functions tools.test ;
[ { 1 -1 5 2 4 } [ < ] monotonic-split [ >array ] map ] unit-test
[ { { 1 1 1 1 } { 2 2 } { 3 } { 4 } { 5 } { 6 6 6 } } ]
[ { 1 1 1 1 2 2 3 4 5 6 6 6 } [ = ] monotonic-split [ >array ] map ] unit-test
[ f ] [ { } singleton? ] unit-test
[ t ] [ { "asdf" } singleton? ] unit-test
[ f ] [ { "asdf" "bsdf" } singleton? ] unit-test
[ 2 ] [ V{ 10 20 30 } [ delete-random drop ] keep length ] unit-test
[ V{ } [ delete-random drop ] keep length ] unit-test-fails

View File

@ -1,5 +1,5 @@
USING: combinators.lib kernel sequences math namespaces
sequences.private shuffle ;
random sequences.private shuffle ;
IN: sequences.lib
@ -61,3 +61,5 @@ IN: sequences.lib
: singleton? ( seq -- ? )
length 1 = ;
: delete-random ( seq -- value )
[ length random ] keep [ nth ] 2keep delete-nth ;