1 IN: persistent.hashtables.tests
2 USING: persistent.hashtables persistent.assocs hashtables assocs
3 tools.test kernel namespaces random math.ranges sequences fry ;
5 [ t ] [ PH{ } assoc-empty? ] unit-test
7 [ PH{ { "A" "B" } } ] [ PH{ } "B" "A" rot new-at ] unit-test
9 [ "B" ] [ "A" PH{ { "A" "B" } } at ] unit-test
11 [ f ] [ "X" PH{ { "A" "B" } } at ] unit-test
13 ! We have to define these first so that they're compiled before
14 ! the below hashtables are parsed...
19 M: hash-0-a hashcode* 2drop 0 ;
23 M: hash-0-b hashcode* 2drop 0 ;
29 "a" T{ hash-0-a } rot new-at
30 "b" T{ hash-0-b } rot new-at
39 ] [ "ph" get >hashtable ] unit-test
45 ] [ "ph" get T{ hash-0-a } swap pluck-at >hashtable ] unit-test
51 ] [ "ph" get T{ hash-0-b } swap pluck-at >hashtable ] unit-test
58 ] [ "ph" get "X" swap pluck-at >hashtable ] unit-test
67 [ H{ { "A" "B" } { "C" "D" } } ] [
71 [ H{ { "C" "D" } } ] [
72 "ph" get "A" swap pluck-at >hashtable
75 [ H{ { "A" "B" } { "C" "D" } { "E" "F" } } ] [
76 "ph" get "F" "E" rot new-at >hashtable
79 [ H{ { "C" "D" } { "E" "F" } } ] [
80 "ph" get "F" "E" rot new-at "A" swap pluck-at >hashtable
83 : random-string ( -- str )
84 1000000 random ; ! [ CHAR: a CHAR: z [a,b] random ] "" replicate-as ;
86 : random-assocs ( -- hash phash )
87 [ random-string ] replicate
88 [ H{ } clone [ '[ swap _ set-at ] each-index ] keep ]
89 [ PH{ } clone swap [ spin new-at ] each-index ]
92 : ok? ( assoc1 assoc2 -- ? )
93 [ assoc= ] [ [ assoc-size ] bi@ = ] 2bi and ;
95 : test-persistent-hashtables-1 ( n -- )
98 [ t ] [ 10 test-persistent-hashtables-1 ] unit-test
99 [ t ] [ 20 test-persistent-hashtables-1 ] unit-test
100 [ t ] [ 30 test-persistent-hashtables-1 ] unit-test
101 [ t ] [ 50 test-persistent-hashtables-1 ] unit-test
102 [ t ] [ 100 test-persistent-hashtables-1 ] unit-test
103 [ t ] [ 500 test-persistent-hashtables-1 ] unit-test
104 [ t ] [ 1000 test-persistent-hashtables-1 ] unit-test
105 [ t ] [ 5000 test-persistent-hashtables-1 ] unit-test
106 [ t ] [ 10000 test-persistent-hashtables-1 ] unit-test
107 [ t ] [ 50000 test-persistent-hashtables-1 ] unit-test
109 : test-persistent-hashtables-2 ( n -- )
112 [ nip over delete-at ] [ swap pluck-at nip ] 3bi
116 [ t ] [ 6000 test-persistent-hashtables-2 ] unit-test