]> gitweb.factorcode.org Git - factor.git/blobdiff - core/hashtables/hashtables-tests.factor
use reject instead of [ ... not ] filter.
[factor.git] / core / hashtables / hashtables-tests.factor
index 0e6deb77465488387704519adfb632a08bd4e48d..5a6ba05e9e52708a8d4a03a062785962bccef30f 100644 (file)
@@ -1,16 +1,14 @@
+USING: accessors assocs continuations hashtables io kernel make
+math namespaces prettyprint sequences sequences.private
+tools.test vectors ;
 IN: hashtables.tests
-USING: kernel math namespaces make tools.test vectors sequences
-sequences.private hashtables io prettyprint assocs
-continuations ;
-
-[ f ] [ "hi" V{ 1 2 3 } at ] unit-test
 
 [ H{ } ] [ { } [ dup ] H{ } map>assoc ] unit-test
 
-[ ] [ 1000 [ dup sq ] H{ } map>assoc "testhash" set ] unit-test
+[ ] [ 1000 iota [ dup sq ] H{ } map>assoc "testhash" set ] unit-test
 
 [ V{ } ]
-[ 1000 [ dup sq swap "testhash" get at = not ] filter ]
+[ 1000 iota [ dup sq swap "testhash" get at = ] reject ]
 unit-test
 
 [ t ]
@@ -21,6 +19,12 @@ unit-test
 [ { 1 { 2 3 } } hashtable? ]
 unit-test
 
+{ t } [
+    "value" "key"
+    [ associate ] [ H{ } clone [ set-at ] keep ] 2bi
+    [ = ] [ [ array>> length ] bi@ = ] 2bi and
+] unit-test
+
 ! Test some hashcodes.
 
 [ t ] [ [ 1 2 3 ] hashcode [ 1 2 3 ] hashcode = ] unit-test
@@ -118,7 +122,7 @@ H{ } clone "counting" set
 
 ! Resource leak...
 H{ } "x" set
-100 [ drop "x" get clear-assoc ] each
+100 [ drop "x" get clear-assoc ] each-integer
 
 ! Crash discovered by erg
 [ t ] [ 0.75 <hashtable> dup clone = ] unit-test
@@ -155,11 +159,6 @@ H{ } "x" set
     ] { } make
 ] unit-test
 
-[ { "one" "two" 3 } ] [
-    { 1 2 3 } clone dup
-    H{ { 1 "one" } { 2 "two" } } substitute-here
-] unit-test
-
 [ { "one" "two" 3 } ] [
     { 1 2 3 } H{ { 1 "one" } { 2 "two" } } substitute
 ] unit-test
@@ -176,3 +175,6 @@ H{ } "x" set
 [ 1 ] [ "h" get assoc-size ] unit-test
 
 [ 1 ] [ 2 "h" get at ] unit-test
+
+! Random test case
+[ "A" ] [ 100 iota [ dup ] H{ } map>assoc 32 over delete-at "A" 32 pick set-at 32 of ] unit-test