factor/library/test/hashtables.factor

49 lines
1.1 KiB
Factor
Raw Normal View History

2004-07-16 02:26:21 -04:00
IN: scratchpad
USE: hashtables
USE: kernel
USE: lists
2004-08-26 22:21:17 -04:00
USE: math
2004-07-16 02:26:21 -04:00
USE: namespaces
USE: test
2004-08-04 03:12:55 -04:00
USE: vectors
2004-07-16 02:26:21 -04:00
16 <hashtable> "testhash" set
2004-08-04 03:12:55 -04:00
: silly-key/value dup dup * swap ;
2004-07-16 02:26:21 -04:00
1000 [ silly-key/value "testhash" get set-hash ] times*
[ f ]
2004-08-04 03:12:55 -04:00
[ 1000 count [ silly-key/value "testhash" get hash = not ] subset ]
unit-test
2004-07-16 02:26:21 -04:00
[ t ]
2004-08-04 03:12:55 -04:00
[ "testhash" get hashtable? ]
unit-test
2004-07-16 02:26:21 -04:00
[ f ]
2004-08-04 03:12:55 -04:00
[ [ 1 2 | 3 ] hashtable? ]
unit-test
! Test some hashcodes.
[ t ] [ [ 1 2 3 ] hashcode [ 1 2 3 ] hashcode = ] unit-test
[ t ] [ [ f | t ] hashcode [ f | t ] hashcode = ] unit-test
[ t ] [ [ 1 [ 2 3 ] 4 ] hashcode [ 1 [ 2 3 ] 4 ] hashcode = ] unit-test
[ t ] [ 12 hashcode 12 hashcode = ] unit-test
[ t ] [ 12 >bignum hashcode 12 hashcode = ] unit-test
[ t ] [ 12.0 hashcode 12 >bignum hashcode = ] unit-test
2004-12-16 18:36:26 -05:00
! Test various odd keys to see if they work.
16 <hashtable> "testhash" set
t #{ 2 3 } "testhash" get set-hash
f 100 fac "testhash" get set-hash
{ } { [ { } ] } "testhash" get set-hash
[ t ] [ #{ 2 3 } "testhash" get hash ] unit-test
[ f ] [ 100 fac "testhash" get hash* cdr ] unit-test
[ { } ] [ { [ { } ] } vector-clone "testhash" get hash* cdr ] unit-test