1 ;;; bloom-tests.el -- Regression Tests for bloom filters
2 ;; Copyright (C) 2005 Sebastian Freundt
4 ;; Author: Sebastian Freundt <hroptatyr@sxemacs.org>
7 ;; This file is part of SXEmacs.
9 ;; SXEmacs is free software: you can redistribute it and/or modify it
10 ;; under the terms of the GNU General Public License as published by the
11 ;; Free Software Foundation, either version 3 of the License, or (at your
12 ;; option) any later version.
14 ;; SXEmacs is distributed in the hope that it will be
15 ;; useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 ;; General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
22 ;;; Synched up with: Not in FSF.
26 ;; See test-harness.el for instructions on how to run these tests.
30 (require 'test-harness)
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))))
39 ;; create some bloom filters
40 (let ((b1 (make-bloom))
43 (b4 (make-bloom 512 26)))
44 (eval `(Assert (eq (bloom-order ,b1)
46 (eval `(Assert (eq (bloom-order ,b3) 512)))
47 (eval `(Assert (eq (bloom-order ,b4) 512)))
48 (eval `(Assert (eq (bloom-degree ,b1)
50 (eval `(Assert (eq (bloom-degree ,b4) 26)))
51 (eval `(Assert (eq (bloom-size ,b1) 0)))
52 (eval `(Assert (eq (bloom-size ,b2) 0)))
53 (eval `(Assert (eq (bloom-size ,b3) 0)))
54 (eval `(Assert (eq (bloom-size ,b4) 0)))
66 (eval `(Assert (bloom-owns-p ,b1 12)))
67 (eval `(Assert (bloom-owns-p ,b1 21)))
68 (eval `(Assert (bloom-owns-p ,b1 0)))
69 (eval `(Assert (not (bloom-owns-p ,b1 13))))
70 (eval `(Assert (not (bloom-owns-p ,b1 17))))
71 (eval `(Assert (eq (bloom-size ,b1) 3)))
76 (eval `(Assert (not (bloom-owns-p ,b1 12))))
77 (eval `(Assert (not (bloom-owns-p ,b1 21))))
78 (eval `(Assert (bloom-owns-p ,b1 0)))
79 (eval `(Assert (eq (bloom-size ,b1) 1)))
88 (eval `(Assert (not (bloom-owns-p ,b2 12))))
89 (eval `(Assert (not (bloom-owns-p ,b2 21))))
90 (eval `(Assert (bloom-owns-p ,b2 2)))
91 (eval `(Assert (bloom-owns-p ,b2 16)))
92 (eval `(Assert (bloom-owns-p ,b2 0)))
94 (setq b3 (bloom-union b1 b2))
96 (eval `(Assert (bloom-owns-p ,b3 12)))
97 (eval `(Assert (bloom-owns-p ,b3 21)))
98 (eval `(Assert (bloom-owns-p ,b3 2)))
99 (eval `(Assert (bloom-owns-p ,b3 16)))
100 (eval `(Assert (bloom-owns-p ,b3 0)))
102 (eval `(Assert (>= (bloom-size ,b3) 5)))
103 (eval `(Assert (not (bloom-owns-p ,b3 17))))
105 ;;; moved to man/lispref/lists.texi -hroptatyr
106 ;; ;; when we add 8-times-degree-times more elements than the order
107 ;; ;; of the bloom we expect it to turn into a universe
109 ;; (dotimes (i (* 8 (bloom-degree b4) (bloom-order b4)))
112 ;; (eval `(Assert (bloom-owns-p ,b4 'a-symbol-i-never-added)))
113 ;; (eval `(Assert (bloom-owns-p ,b4 "a-string-i-never-added")))
114 ;; (eval `(Assert (bloom-owns-p ,b4 [a vector i never added])))
118 ;; dealing with universes
119 (let ((b1 (make-bloom-universe))
120 (b2 (make-bloom-universe))
121 (b3 (make-bloom-universe 512))
122 (b4 (make-bloom-universe 512 26)))
123 (eval `(Assert (eq (bloom-order ,b1)
125 (eval `(Assert (eq (bloom-order ,b3) 512)))
126 (eval `(Assert (eq (bloom-order ,b4) 512)))
127 (eval `(Assert (eq (bloom-degree ,b1)
128 (bloom-degree ,b2))))
129 (eval `(Assert (eq (bloom-degree ,b4) 26)))
130 (eval `(Assert (eq (bloom-size ,b1)
132 (eval `(Assert (eq (bloom-size ,b3)
135 (eval `(Assert (bloom-owns-p ,b1 21)))
136 (eval `(Assert (bloom-owns-p ,b1 'a-symbol)))
137 (eval `(Assert (bloom-owns-p ,b1 "a string")))
138 (eval `(Assert (bloom-owns-p ,b1 [a vector])))
140 ;; we can delete many elements from the universe, they are still in the bloom
142 (eval `(Assert (bloom-owns-p ,b1 21)))
144 (bloom-remove b1 'a-symbol)
145 (eval `(Assert (bloom-owns-p ,b1 'a-symbol)))
147 (bloom-remove b1 "a string")
148 (eval `(Assert (bloom-owns-p ,b1 "a string")))
150 (bloom-remove b1 [a vector])
151 (eval `(Assert (bloom-owns-p ,b1 [a vector]))))
154 ;;; bloom-tests.el ends here