Mercurial > hg > xemacs-beta
annotate tests/automated/hash-table-tests.el @ 5633:49c36ed998b6
No longer use the obsolete function names, hash-table-tests.el
tests/ChangeLog addition:
2011-12-30 Aidan Kehoe <kehoea@parhasard.net>
* automated/hash-table-tests.el:
No longer use the obsolete function names in the tests, now
they've been removed from cl.el.
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Fri, 30 Dec 2011 16:39:14 +0000 |
parents | 071b810ceb18 |
children |
rev | line source |
---|---|
428 | 1 ;; Copyright (C) 1998 Free Software Foundation, Inc. |
2 | |
3 ;; Author: Martin Buchholz <martin@xemacs.org> | |
4 ;; Maintainer: Martin Buchholz <martin@xemacs.org> | |
5 ;; Created: 1998 | |
6 ;; Keywords: tests, database | |
7 | |
8 ;; This file is part of XEmacs. | |
9 | |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5191
diff
changeset
|
10 ;; XEmacs is free software: you can redistribute it and/or modify it |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5191
diff
changeset
|
11 ;; under the terms of the GNU General Public License as published by the |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5191
diff
changeset
|
12 ;; Free Software Foundation, either version 3 of the License, or (at your |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5191
diff
changeset
|
13 ;; option) any later version. |
428 | 14 |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5191
diff
changeset
|
15 ;; XEmacs is distributed in the hope that it will be useful, but WITHOUT |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5191
diff
changeset
|
16 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5191
diff
changeset
|
17 ;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5191
diff
changeset
|
18 ;; for more details. |
428 | 19 |
20 ;; You should have received a copy of the GNU General Public License | |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5191
diff
changeset
|
21 ;; along with XEmacs. If not, see <http://www.gnu.org/licenses/>. |
428 | 22 |
23 ;;; Synched up with: Not in FSF. | |
24 | |
25 ;;; Commentary: | |
26 | |
27 ;;; Test hash tables implementation | |
28 ;;; See test-harness.el | |
29 | |
30 (condition-case err | |
31 (require 'test-harness) | |
32 (file-error | |
33 (when (and (boundp 'load-file-name) (stringp load-file-name)) | |
34 (push (file-name-directory load-file-name) load-path) | |
35 (require 'test-harness)))) | |
36 | |
37 ;; Test all combinations of make-hash-table keywords | |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
38 (dolist (test '(eq eql equal equalp)) |
428 | 39 (dolist (size '(0 1 100)) |
40 (dolist (rehash-size '(1.1 9.9)) | |
41 (dolist (rehash-threshold '(0.2 .9)) | |
442 | 42 (dolist (weakness '(nil key value key-or-value key-and-value)) |
428 | 43 (dolist (data '(() (1 2) (1 2 3 4))) |
44 (let ((ht (make-hash-table | |
45 :test test | |
46 :size size | |
47 :rehash-size rehash-size | |
48 :rehash-threshold rehash-threshold | |
49 :weakness weakness))) | |
5136
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
4855
diff
changeset
|
50 (Assert (equal ht (car (let ((print-readably t)) |
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
4855
diff
changeset
|
51 (read-from-string (prin1-to-string ht)))))) |
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
4855
diff
changeset
|
52 (Assert (eq test (hash-table-test ht))) |
428 | 53 (Assert (<= size (hash-table-size ht))) |
5136
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
4855
diff
changeset
|
54 (Assert (eql rehash-size (hash-table-rehash-size ht))) |
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
4855
diff
changeset
|
55 (Assert (eql rehash-threshold (hash-table-rehash-threshold ht))) |
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
4855
diff
changeset
|
56 (Assert (eq weakness (hash-table-weakness ht)))))))))) |
428 | 57 |
58 (loop for (type weakness) in '((non-weak nil) | |
442 | 59 (weak key-and-value) |
428 | 60 (key-weak key) |
61 (value-weak value)) | |
5136
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
4855
diff
changeset
|
62 do (Assert (equal (make-hash-table :type type) |
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
4855
diff
changeset
|
63 (make-hash-table :weakness weakness)))) |
428 | 64 |
65 (Assert (not (equal (make-hash-table :weakness nil) | |
66 (make-hash-table :weakness t)))) | |
67 | |
68 (let ((ht (make-hash-table :size 20 :rehash-threshold .75 :test 'eq)) | |
69 (size 80)) | |
70 (Assert (hash-table-p ht)) | |
5136
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
4855
diff
changeset
|
71 (Assert (eq 'eq (hash-table-test ht))) |
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
4855
diff
changeset
|
72 (Assert (eq 'non-weak (hash-table-type ht))) |
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
4855
diff
changeset
|
73 (Assert (eq 'nil (hash-table-weakness ht))) |
428 | 74 (dotimes (j size) |
75 (puthash j (- j) ht) | |
5136
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
4855
diff
changeset
|
76 (Assert (eq (gethash j ht) (- j))) |
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
4855
diff
changeset
|
77 (Assert (= (hash-table-count ht) (1+ j))) |
428 | 78 (puthash j j ht) |
5136
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
4855
diff
changeset
|
79 (Assert (eq (gethash j ht 'foo) j)) |
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
4855
diff
changeset
|
80 (Assert (= (hash-table-count ht) (1+ j))) |
428 | 81 (setf (gethash j ht) (- j)) |
5136
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
4855
diff
changeset
|
82 (Assert (eq (gethash j ht) (- j))) |
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
4855
diff
changeset
|
83 (Assert (= (hash-table-count ht) (1+ j)))) |
428 | 84 |
85 (clrhash ht) | |
5136
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
4855
diff
changeset
|
86 (Assert (= 0 (hash-table-count ht))) |
428 | 87 |
88 (dotimes (j size) | |
89 (puthash j (- j) ht) | |
5136
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
4855
diff
changeset
|
90 (Assert (eq (gethash j ht) (- j))) |
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
4855
diff
changeset
|
91 (Assert (= (hash-table-count ht) (1+ j)))) |
428 | 92 |
93 (let ((k-sum 0) (v-sum 0)) | |
94 (maphash #'(lambda (k v) (incf k-sum k) (incf v-sum v)) ht) | |
5136
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
4855
diff
changeset
|
95 (Assert (= k-sum (/ (* size (- size 1)) 2))) |
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
4855
diff
changeset
|
96 (Assert (= v-sum (- k-sum)))) |
428 | 97 |
98 (let ((count size)) | |
99 (dotimes (j size) | |
100 (remhash j ht) | |
5136
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
4855
diff
changeset
|
101 (Assert (eq (gethash j ht) nil)) |
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
4855
diff
changeset
|
102 (Assert (eq (gethash j ht 'foo) 'foo)) |
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
4855
diff
changeset
|
103 (Assert (= (hash-table-count ht) (decf count)))))) |
428 | 104 |
105 (let ((ht (make-hash-table :size 30 :rehash-threshold .25 :test 'equal)) | |
106 (size 70)) | |
107 (Assert (hash-table-p ht)) | |
108 (Assert (>= (hash-table-size ht) (/ 30 .25))) | |
5136
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
4855
diff
changeset
|
109 (Assert (eql .25 (hash-table-rehash-threshold ht))) |
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
4855
diff
changeset
|
110 (Assert (eq 'equal (hash-table-test ht))) |
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
4855
diff
changeset
|
111 (Assert (eq 'non-weak (hash-table-type ht))) |
428 | 112 (dotimes (j size) |
113 (puthash (int-to-string j) (- j) ht) | |
5136
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
4855
diff
changeset
|
114 (Assert (eq (gethash (int-to-string j) ht) (- j))) |
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
4855
diff
changeset
|
115 (Assert (= (hash-table-count ht) (1+ j))) |
428 | 116 (puthash (int-to-string j) j ht) |
5136
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
4855
diff
changeset
|
117 (Assert (eq (gethash (int-to-string j) ht 'foo) j)) |
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
4855
diff
changeset
|
118 (Assert (= (hash-table-count ht) (1+ j)))) |
428 | 119 |
120 (clrhash ht) | |
5136
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
4855
diff
changeset
|
121 (Assert (= 0 (hash-table-count ht))) |
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
4855
diff
changeset
|
122 (Assert (equal ht (copy-hash-table ht))) |
428 | 123 |
124 (dotimes (j size) | |
125 (setf (gethash (int-to-string j) ht) (- j)) | |
5136
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
4855
diff
changeset
|
126 (Assert (eq (gethash (int-to-string j) ht) (- j))) |
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
4855
diff
changeset
|
127 (Assert (= (hash-table-count ht) (1+ j)))) |
428 | 128 |
129 (let ((count size)) | |
130 (dotimes (j size) | |
131 (remhash (int-to-string j) ht) | |
5136
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
4855
diff
changeset
|
132 (Assert (eq (gethash (int-to-string j) ht) nil)) |
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
4855
diff
changeset
|
133 (Assert (eq (gethash (int-to-string j) ht 'foo) 'foo)) |
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
4855
diff
changeset
|
134 (Assert (= (hash-table-count ht) (decf count)))))) |
428 | 135 |
136 (let ((iterations 5) (one 1.0) (two 2.0)) | |
5576
071b810ceb18
Declare labels as line where appropriate; use #'labels, not #'flet, tests.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5402
diff
changeset
|
137 (labels ((check-copy |
071b810ceb18
Declare labels as line where appropriate; use #'labels, not #'flet, tests.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5402
diff
changeset
|
138 (ht) |
071b810ceb18
Declare labels as line where appropriate; use #'labels, not #'flet, tests.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5402
diff
changeset
|
139 (let ((copy-of-ht (copy-hash-table ht))) |
071b810ceb18
Declare labels as line where appropriate; use #'labels, not #'flet, tests.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5402
diff
changeset
|
140 (Assert (equal ht copy-of-ht)) |
071b810ceb18
Declare labels as line where appropriate; use #'labels, not #'flet, tests.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5402
diff
changeset
|
141 (Assert (not (eq ht copy-of-ht))) |
071b810ceb18
Declare labels as line where appropriate; use #'labels, not #'flet, tests.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5402
diff
changeset
|
142 (Assert (eq (hash-table-count ht) |
071b810ceb18
Declare labels as line where appropriate; use #'labels, not #'flet, tests.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5402
diff
changeset
|
143 (hash-table-count copy-of-ht))) |
071b810ceb18
Declare labels as line where appropriate; use #'labels, not #'flet, tests.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5402
diff
changeset
|
144 (Assert (eq (hash-table-type ht) |
071b810ceb18
Declare labels as line where appropriate; use #'labels, not #'flet, tests.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5402
diff
changeset
|
145 (hash-table-type copy-of-ht))) |
071b810ceb18
Declare labels as line where appropriate; use #'labels, not #'flet, tests.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5402
diff
changeset
|
146 (Assert (eq (hash-table-size ht) |
071b810ceb18
Declare labels as line where appropriate; use #'labels, not #'flet, tests.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5402
diff
changeset
|
147 (hash-table-size copy-of-ht))) |
071b810ceb18
Declare labels as line where appropriate; use #'labels, not #'flet, tests.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5402
diff
changeset
|
148 (Assert (eql (hash-table-rehash-size ht) |
071b810ceb18
Declare labels as line where appropriate; use #'labels, not #'flet, tests.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5402
diff
changeset
|
149 (hash-table-rehash-size copy-of-ht))) |
071b810ceb18
Declare labels as line where appropriate; use #'labels, not #'flet, tests.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5402
diff
changeset
|
150 (Assert (eql (hash-table-rehash-threshold ht) |
071b810ceb18
Declare labels as line where appropriate; use #'labels, not #'flet, tests.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5402
diff
changeset
|
151 (hash-table-rehash-threshold copy-of-ht)))))) |
428 | 152 |
153 (let ((ht (make-hash-table :size 100 :rehash-threshold .6 :test 'eq))) | |
154 (dotimes (j iterations) | |
155 (puthash (+ one 0.0) t ht) | |
156 (puthash (+ two 0.0) t ht) | |
444 | 157 (puthash (cons 1 2) t ht) |
158 (puthash (cons 3 4) t ht)) | |
5136
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
4855
diff
changeset
|
159 (Assert (eq (hash-table-test ht) 'eq)) |
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
4855
diff
changeset
|
160 (Assert (= (* iterations 4) (hash-table-count ht))) |
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
4855
diff
changeset
|
161 (Assert (eq nil (gethash 1.0 ht))) |
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
4855
diff
changeset
|
162 (Assert (eq nil (gethash '(1 . 2) ht))) |
428 | 163 (check-copy ht) |
164 ) | |
165 | |
166 (let ((ht (make-hash-table :size 100 :rehash-threshold .6 :test 'eql))) | |
167 (dotimes (j iterations) | |
168 (puthash (+ one 0.0) t ht) | |
169 (puthash (+ two 0.0) t ht) | |
444 | 170 (puthash (cons 1 2) t ht) |
171 (puthash (cons 3 4) t ht)) | |
5136
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
4855
diff
changeset
|
172 (Assert (eq (hash-table-test ht) 'eql)) |
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
4855
diff
changeset
|
173 (Assert (= (+ 2 (* 2 iterations)) (hash-table-count ht))) |
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
4855
diff
changeset
|
174 (Assert (eq t (gethash 1.0 ht))) |
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
4855
diff
changeset
|
175 (Assert (eq nil (gethash '(1 . 2) ht))) |
428 | 176 (check-copy ht) |
177 ) | |
178 | |
179 (let ((ht (make-hash-table :size 100 :rehash-threshold .6 :test 'equal))) | |
180 (dotimes (j iterations) | |
181 (puthash (+ one 0.0) t ht) | |
182 (puthash (+ two 0.0) t ht) | |
444 | 183 (puthash (cons 1 2) t ht) |
184 (puthash (cons 3 4) t ht)) | |
5136
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
4855
diff
changeset
|
185 (Assert (eq (hash-table-test ht) 'equal)) |
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
4855
diff
changeset
|
186 (Assert (= 4 (hash-table-count ht))) |
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
4855
diff
changeset
|
187 (Assert (eq t (gethash 1.0 ht))) |
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
4855
diff
changeset
|
188 (Assert (eq t (gethash '(1 . 2) ht))) |
428 | 189 (check-copy ht) |
190 ) | |
191 | |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
192 (let ((ht (make-hash-table :size 100 :rehash-threshold .6 :test 'equalp))) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
193 (dotimes (j iterations) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
194 (puthash (+ one 0.0) t ht) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
195 (puthash 1 t ht) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
196 (puthash (+ two 0.0) t ht) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
197 (puthash 2 t ht) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
198 (puthash (cons 1.0 2.0) (gensym) ht) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
199 ;; Override the previous entry. |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
200 (puthash (cons 1 2) t ht) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
201 (puthash (cons 3.0 4.0) (gensym) ht) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
202 (puthash (cons 3 4) t ht)) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
203 (Assert (eq (hash-table-test ht) 'equalp)) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
204 (Assert (= 4 (hash-table-count ht))) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
205 (Assert (eq t (gethash 1.0 ht))) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
206 (Assert (eq t (gethash '(1 . 2) ht))) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
207 (check-copy ht) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
208 ) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
209 |
428 | 210 )) |
211 | |
212 ;; Test that weak hash-tables are properly handled | |
213 (loop for (weakness expected-count expected-k-sum expected-v-sum) in | |
214 '((nil 6 38 25) | |
215 (t 3 6 9) | |
216 (key 4 38 9) | |
217 (value 4 6 25)) | |
218 do | |
219 (let* ((ht (make-hash-table :weakness weakness)) | |
220 (my-obj (cons ht ht))) | |
221 (garbage-collect) | |
222 (puthash my-obj 1 ht) | |
223 (puthash 2 my-obj ht) | |
224 (puthash 4 8 ht) | |
225 (puthash (cons ht ht) 16 ht) | |
226 (puthash 32 (cons ht ht) ht) | |
227 (puthash (cons ht ht) (cons ht ht) ht) | |
228 (let ((k-sum 0) (v-sum 0)) | |
229 (maphash #'(lambda (k v) | |
230 (when (integerp k) (incf k-sum k)) | |
231 (when (integerp v) (incf v-sum v))) | |
232 ht) | |
5136
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
4855
diff
changeset
|
233 (Assert (eq 38 k-sum)) |
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
4855
diff
changeset
|
234 (Assert (eq 25 v-sum))) |
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
4855
diff
changeset
|
235 (Assert (eq 6 (hash-table-count ht))) |
428 | 236 (garbage-collect) |
5136
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
4855
diff
changeset
|
237 (Assert (eq expected-count (hash-table-count ht))) |
428 | 238 (let ((k-sum 0) (v-sum 0)) |
239 (maphash #'(lambda (k v) | |
240 (when (integerp k) (incf k-sum k)) | |
241 (when (integerp v) (incf v-sum v))) | |
242 ht) | |
5136
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
4855
diff
changeset
|
243 (Assert (eq expected-k-sum k-sum)) |
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
4855
diff
changeset
|
244 (Assert (eq expected-v-sum v-sum))))) |
428 | 245 |
246 ;;; Test the ability to puthash and remhash the current elt of a maphash | |
247 (let ((ht (make-hash-table :test 'eql))) | |
248 (dotimes (j 100) (setf (gethash j ht) (- j))) | |
249 (maphash #'(lambda (k v) | |
250 (if (oddp k) (remhash k ht) (puthash k (- v) ht))) | |
251 ht) | |
252 (let ((k-sum 0) (v-sum 0)) | |
253 (maphash #'(lambda (k v) (incf k-sum k) (incf v-sum v)) ht) | |
5136
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
4855
diff
changeset
|
254 (Assert (= (* 50 49) k-sum)) |
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
4855
diff
changeset
|
255 (Assert (= v-sum k-sum)))) |
428 | 256 |
257 ;;; Test reading and printing of hash-table objects | |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
258 (let ((h1 #s(hashtable :weakness t :rehash-size 3.0 :rehash-threshold .2 :test eq :data (1 2 3 4))) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
259 (h2 #s(hash-table :weakness t :rehash-size 3.0 :rehash-threshold .2 :test eq :data (1 2 3 4))) |
428 | 260 (h3 (make-hash-table :weakness t :rehash-size 3.0 :rehash-threshold .2 :test 'eq))) |
5136
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
4855
diff
changeset
|
261 (Assert (equal h1 h2)) |
428 | 262 (Assert (not (equal h1 h3))) |
263 (puthash 1 2 h3) | |
264 (puthash 3 4 h3) | |
5136
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
4855
diff
changeset
|
265 (Assert (equal h1 h3))) |
428 | 266 |
267 ;;; Testing equality of hash tables | |
5136
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
4855
diff
changeset
|
268 (Assert (equal (make-hash-table :test 'eql :size 300 :rehash-threshold .9 :rehash-size 3.0) |
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
4855
diff
changeset
|
269 (make-hash-table :test 'eql))) |
428 | 270 (Assert (not (equal (make-hash-table :test 'eq) |
271 (make-hash-table :test 'equal)))) | |
272 (let ((h1 (make-hash-table)) | |
273 (h2 (make-hash-table))) | |
5136
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
4855
diff
changeset
|
274 (Assert (equal h1 h2)) |
428 | 275 (Assert (not (eq h1 h2))) |
276 (puthash 1 2 h1) | |
277 (Assert (not (equal h1 h2))) | |
278 (puthash 1 2 h2) | |
5136
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
4855
diff
changeset
|
279 (Assert (equal h1 h2)) |
428 | 280 (puthash 1 3 h2) |
281 (Assert (not (equal h1 h2))) | |
282 (clrhash h1) | |
283 (Assert (not (equal h1 h2))) | |
284 (clrhash h2) | |
5136
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
4855
diff
changeset
|
285 (Assert (equal h1 h2)) |
428 | 286 ) |
287 | |
288 ;;; Test sxhash | |
5136
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
4855
diff
changeset
|
289 (Assert (= (sxhash "foo") (sxhash "foo"))) |
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
4855
diff
changeset
|
290 (Assert (= (sxhash '(1 2 3)) (sxhash '(1 2 3)))) |
4398
479443c0f95a
Have list hashes depend on the order of the contents, as is the case for vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
1761
diff
changeset
|
291 (Assert (/= (sxhash '(1 2 3)) (sxhash '(3 2 1)))) |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
292 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
293 ;; Test #'define-hash-table-test. |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
294 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
295 (defstruct hash-table-test-structure |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
296 number-identifier padding-zero padding-one padding-two) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
297 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
298 (macrolet |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
299 ((good-hash () 65599) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
300 (hash-modulo-figure () |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
301 (if (featurep 'bignum) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
302 (1+ (* most-positive-fixnum 2)) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
303 most-positive-fixnum)) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
304 (hash-table-test-structure-first-hash-figure () |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
305 (rem* (* 65599 (eq-hash 'hash-table-test-structure)) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
306 (if (featurep 'bignum) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
307 (1+ (* most-positive-fixnum 2)) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
308 most-positive-fixnum)))) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
309 (let ((hash-table-test (gensym)) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
310 (no-entry-found (gensym)) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
311 (two 2.0) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
312 (equal-function |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
313 #'(lambda (object-one object-two) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
314 (or (equal object-one object-two) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
315 (and (hash-table-test-structure-p object-one) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
316 (hash-table-test-structure-p object-two) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
317 (= (hash-table-test-structure-number-identifier |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
318 object-one) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
319 (hash-table-test-structure-number-identifier |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
320 object-two)))))) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
321 (hash-function |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
322 #'(lambda (object) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
323 (if (hash-table-test-structure-p object) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
324 (rem* (+ (hash-table-test-structure-first-hash-figure) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
325 (equalp-hash |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
326 (hash-table-test-structure-number-identifier |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
327 object))) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
328 (hash-modulo-figure)) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
329 (equal-hash object)))) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
330 hash-table-test-hash equal-hash) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
331 (Check-Error wrong-type-argument (define-hash-table-test |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
332 "hi there everyone" |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
333 equal-function hash-function)) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
334 (Check-Error wrong-number-of-arguments (define-hash-table-test |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
335 (gensym) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
336 hash-function hash-function)) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
337 (Check-Error wrong-number-of-arguments (define-hash-table-test |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
338 (gensym) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
339 equal-function equal-function)) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
340 (define-hash-table-test hash-table-test equal-function hash-function) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
341 (Assert (valid-hash-table-test-p hash-table-test)) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
342 (setq equal-hash (make-hash-table :test #'equal) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
343 hash-table-test-hash (make-hash-table :test hash-table-test)) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
344 (Assert (hash-table-p equal-hash)) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
345 (Assert (hash-table-p hash-table-test-hash)) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
346 (Assert (eq hash-table-test (hash-table-test hash-table-test-hash))) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
347 (loop |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
348 for ii from 200 below 300 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
349 with structure = nil |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
350 do |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
351 (setf structure (make-hash-table-test-structure |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
352 :number-identifier (if (oddp ii) (float (% ii 10)) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
353 (% ii 10)) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
354 :padding-zero (random) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
355 :padding-one (random) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
356 :padding-two (random)) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
357 (gethash structure hash-table-test-hash) t |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
358 (gethash structure equal-hash) t)) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
359 (Assert (= (hash-table-count hash-table-test-hash) 10)) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
360 (Assert (= (hash-table-count equal-hash) 100)) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
361 (Assert (eq t (gethash (make-hash-table-test-structure |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
362 :number-identifier 1 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
363 :padding-zero (random) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
364 :padding-one (random) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
365 :padding-two (random)) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
366 hash-table-test-hash))) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
367 (Assert (eq t (gethash (make-hash-table-test-structure |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
368 :number-identifier 2.0 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
369 :padding-zero (random) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
370 :padding-one (random) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
371 :padding-two (random)) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
372 hash-table-test-hash))) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
373 (Assert (eq no-entry-found (gethash (make-hash-table-test-structure |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
374 :number-identifier (+ two 0.0) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
375 :padding-zero (random) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
376 :padding-one (random) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
377 :padding-two (random)) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
378 equal-hash |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
379 no-entry-found))))) |