X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=tests%2Fautomated%2Fhash-table-tests.el;h=1c8af88c7ef4af54566d5e1b20567baf2b1411c0;hb=02f4d2761a98c5cb9d5b423d2361160a5d8c9ee4;hp=d68e3992a6f9a1bef9f5ff5d1c87083025a4c5e9;hpb=976b002b16336930724ae22476014583ad022e7d;p=chise%2Fxemacs-chise.git.1 diff --git a/tests/automated/hash-table-tests.el b/tests/automated/hash-table-tests.el index d68e399..1c8af88 100644 --- a/tests/automated/hash-table-tests.el +++ b/tests/automated/hash-table-tests.el @@ -37,30 +37,41 @@ (require 'test-harness)))) ;; Test all combinations of make-hash-table keywords -(dolist (type '(non-weak weak key-weak value-weak)) - (dolist (test '(eq eql equal)) - (dolist (size '(0 1 100)) - (dolist (rehash-size '(1.1 9.9)) - (dolist (rehash-threshold '(0.2 .9)) +(dolist (test '(eq eql equal)) + (dolist (size '(0 1 100)) + (dolist (rehash-size '(1.1 9.9)) + (dolist (rehash-threshold '(0.2 .9)) + (dolist (weakness '(nil key value key-or-value key-and-value)) (dolist (data '(() (1 2) (1 2 3 4))) - (let ((ht (make-hash-table :test test - :type type - :size size - :rehash-size rehash-size - :rehash-threshold rehash-threshold))) + (let ((ht (make-hash-table + :test test + :size size + :rehash-size rehash-size + :rehash-threshold rehash-threshold + :weakness weakness))) (Assert (equal ht (car (let ((print-readably t)) (read-from-string (prin1-to-string ht)))))) (Assert (eq test (hash-table-test ht))) - (Assert (eq type (hash-table-type ht))) (Assert (<= size (hash-table-size ht))) (Assert (eql rehash-size (hash-table-rehash-size ht))) - (Assert (eql rehash-threshold (hash-table-rehash-threshold ht)))))))))) + (Assert (eql rehash-threshold (hash-table-rehash-threshold ht))) + (Assert (eq weakness (hash-table-weakness ht)))))))))) -(loop for (fun type) in '((make-hashtable non-weak) - (make-weak-hashtable weak) - (make-key-weak-hashtable key-weak) - (make-value-weak-hashtable value-weak)) - do (Assert (eq type (hash-table-type (funcall fun 10))))) +(loop for (fun weakness) in '((make-hashtable nil) + (make-weak-hashtable key-and-value) + (make-key-weak-hashtable key) + (make-value-weak-hashtable value)) + do (Assert (eq weakness (hash-table-weakness (funcall fun 10))))) + +(loop for (type weakness) in '((non-weak nil) + (weak key-and-value) + (key-weak key) + (value-weak value)) + do (Assert (equal (make-hash-table :type type) + (make-hash-table :weakness weakness)))) + +(Assert (not (equal (make-hash-table :weakness nil) + (make-hash-table :weakness t)))) (let ((ht (make-hash-table :size 20 :rehash-threshold .75 :test 'eq)) (size 80)) @@ -69,6 +80,7 @@ (Assert (eq 'eq (hash-table-test ht))) (Assert (eq 'non-weak (hash-table-type ht))) (Assert (eq 'non-weak (hashtable-type ht))) + (Assert (eq 'nil (hash-table-weakness ht))) (dotimes (j size) (puthash j (- j) ht) (Assert (eq (gethash j ht) (- j))) @@ -152,13 +164,13 @@ (dotimes (j iterations) (puthash (+ one 0.0) t ht) (puthash (+ two 0.0) t ht) - (puthash (concat "1" "2") t ht) - (puthash (concat "3" "4") t ht)) + (puthash (cons 1 2) t ht) + (puthash (cons 3 4) t ht)) (Assert (eq (hashtable-test-function ht) 'eq)) (Assert (eq (hash-table-test ht) 'eq)) (Assert (= (* iterations 4) (hash-table-count ht))) (Assert (eq nil (gethash 1.0 ht))) - (Assert (eq nil (gethash "12" ht))) + (Assert (eq nil (gethash '(1 . 2) ht))) (check-copy ht) ) @@ -166,13 +178,13 @@ (dotimes (j iterations) (puthash (+ one 0.0) t ht) (puthash (+ two 0.0) t ht) - (puthash (concat "1" "2") t ht) - (puthash (concat "3" "4") t ht)) + (puthash (cons 1 2) t ht) + (puthash (cons 3 4) t ht)) (Assert (eq (hashtable-test-function ht) 'eql)) (Assert (eq (hash-table-test ht) 'eql)) (Assert (= (+ 2 (* 2 iterations)) (hash-table-count ht))) (Assert (eq t (gethash 1.0 ht))) - (Assert (eq nil (gethash "12" ht))) + (Assert (eq nil (gethash '(1 . 2) ht))) (check-copy ht) ) @@ -180,26 +192,26 @@ (dotimes (j iterations) (puthash (+ one 0.0) t ht) (puthash (+ two 0.0) t ht) - (puthash (concat "1" "2") t ht) - (puthash (concat "3" "4") t ht)) + (puthash (cons 1 2) t ht) + (puthash (cons 3 4) t ht)) (Assert (eq (hashtable-test-function ht) 'equal)) (Assert (eq (hash-table-test ht) 'equal)) (Assert (= 4 (hash-table-count ht))) (Assert (eq t (gethash 1.0 ht))) - (Assert (eq t (gethash "12" ht))) + (Assert (eq t (gethash '(1 . 2) ht))) (check-copy ht) ) )) ;; Test that weak hash-tables are properly handled -(loop for (type expected-count expected-k-sum expected-v-sum) in - '((non-weak 6 38 25) - (weak 3 6 9) - (key-weak 4 38 9) - (value-weak 4 6 25)) +(loop for (weakness expected-count expected-k-sum expected-v-sum) in + '((nil 6 38 25) + (t 3 6 9) + (key 4 38 9) + (value 4 6 25)) do - (let* ((ht (make-hash-table :type type)) + (let* ((ht (make-hash-table :weakness weakness)) (my-obj (cons ht ht))) (garbage-collect) (puthash my-obj 1 ht) @@ -238,9 +250,9 @@ (Assert (= v-sum k-sum)))) ;;; Test reading and printing of hash-table objects -(let ((h1 #s(hashtable type weak rehash-size 3.0 rehash-threshold .2 test eq data (1 2 3 4))) - (h2 #s(hash-table type weak rehash-size 3.0 rehash-threshold .2 test eq data (1 2 3 4))) - (h3 (make-hash-table :type 'weak :rehash-size 3.0 :rehash-threshold .2 :test 'eq))) +(let ((h1 #s(hashtable weakness t rehash-size 3.0 rehash-threshold .2 test eq data (1 2 3 4))) + (h2 #s(hash-table weakness t rehash-size 3.0 rehash-threshold .2 test eq data (1 2 3 4))) + (h3 (make-hash-table :weakness t :rehash-size 3.0 :rehash-threshold .2 :test 'eq))) (Assert (equal h1 h2)) (Assert (not (equal h1 h3))) (puthash 1 2 h3) @@ -267,3 +279,7 @@ (clrhash h2) (Assert (equal h1 h2)) ) + +;;; Test sxhash +(Assert (= (sxhash "foo") (sxhash "foo"))) +(Assert (= (sxhash '(1 2 3)) (sxhash '(1 2 3))))