debian update
[kmrcl.git] / tests.lisp
1 ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
4 ;;;;
5 ;;;; Name:          kmrcl-tests.lisp
6 ;;;; Purpose:       kmrcl tests file
7 ;;;; Author:        Kevin M. Rosenberg
8 ;;;; Date Started:  Apr 2003
9 ;;;;
10 ;;;; This file is Copyright (c) 2000-2010 by Kevin M. Rosenberg
11 ;;;;
12 ;;;; *************************************************************************
13
14 (in-package #:cl)
15 (defpackage #:kmrcl-tests
16   (:use #:kmrcl #:cl #:rtest))
17 (in-package #:kmrcl-tests)
18
19 (rem-all-tests)
20
21
22 (deftest :str.0 (substitute-chars-strings "" nil) "")
23 (deftest :str.1 (substitute-chars-strings "abcd" nil) "abcd")
24 (deftest :str.2 (substitute-chars-strings "abcd" nil) "abcd")
25 (deftest :str.3 (substitute-chars-strings "abcd" '((#\j . "ef"))) "abcd")
26 (deftest :str.4 (substitute-chars-strings "abcd" '((#\a . "ef"))) "efbcd")
27 (deftest :str.5
28     (substitute-chars-strings "abcd" '((#\a . "ef") (#\j . "ghi")))
29   "efbcd")
30 (deftest :str.6
31     (substitute-chars-strings "abcd" '((#\a . "ef") (#\d . "ghi")))
32   "efbcghi")
33
34 (deftest :str.7 (escape-xml-string "") "")
35 (deftest :str.8 (escape-xml-string "abcd") "abcd")
36 (deftest :str.9 (escape-xml-string "ab&cd") "ab&cd")
37 (deftest :str.10 (escape-xml-string "ab&cd<") "ab&amp;cd&lt;")
38 (deftest :str.12 (string-trim-last-character "") "")
39 (deftest :str.13 (string-trim-last-character "a") "")
40 (deftest :str.14 (string-trim-last-character "ab") "a")
41 (deftest :str.15 (nstring-trim-last-character "") "")
42 (deftest :str.16 (nstring-trim-last-character "a") "")
43 (deftest :str.17 (nstring-trim-last-character "ab") "a")
44
45 (deftest :str.18 (delimited-string-to-list "ab|cd|ef" #\|)
46                                           ("ab" "cd" "ef"))
47 (deftest :str.19 (delimited-string-to-list "ab|cd|ef" #\| t)
48                                           ("ab" "cd" "ef"))
49 (deftest :str.20 (delimited-string-to-list "") (""))
50 (deftest :str.21 (delimited-string-to-list "" #\space t) (""))
51 (deftest :str.22 (delimited-string-to-list "ab") ("ab"))
52 (deftest :str.23 (delimited-string-to-list "ab" #\space t) ("ab"))
53 (deftest :str.24 (delimited-string-to-list "ab|" #\|) ("ab" ""))
54 (deftest :str.25 (delimited-string-to-list "ab|" #\| t) ("ab"))
55
56 (deftest :sdstl.1 (string-delimited-string-to-list "ab|cd|ef" "|a")
57   ("ab|cd|ef"))
58 (deftest :sdstl.2 (string-delimited-string-to-list "ab|cd|ef" "|")
59   ("ab" "cd" "ef"))
60 (deftest :sdstl.3 (string-delimited-string-to-list "ab|cd|ef" "cd")
61   ("ab|" "|ef"))
62 (deftest :sdstl.4 (string-delimited-string-to-list "ab|cd|ef" "ab")
63   ("" "|cd|ef"))
64
65 (deftest :hexstr.1 (binary-sequence-to-hex-string ())
66   "")
67
68 (deftest :hexstr.2 (binary-sequence-to-hex-string #())
69   "")
70
71 (deftest :hexstr.3 (binary-sequence-to-hex-string #(165))
72   "a5"
73 )
74
75 (deftest :hexstr.4 (binary-sequence-to-hex-string (list 165))
76   "a5")
77
78 (deftest :hexstr.5 (binary-sequence-to-hex-string #(165 86))
79   "a556")
80
81 (deftest :apsl.1 (append-sublists '((a b) (c d))) (a b c d))
82 (deftest :apsl.2 (append-sublists nil) nil)
83 (deftest :apsl.3 (append-sublists '((a b))) (a b))
84 (deftest :apsl.4 (append-sublists '((a))) (a))
85 (deftest :apsl.5 (append-sublists '((a) (b) (c d (e f g)))) (a b c d (e f g)))
86
87 (deftest :pss.0 (with-output-to-string (s) (print-separated-strings s "|" nil))
88   "")
89
90 (deftest :pss.1
91     (with-output-to-string (s) (print-separated-strings s "|" '("ab")) )
92   "ab")
93
94 (deftest :pss.2
95     (with-output-to-string (s) (print-separated-strings s "|" '("ab" "cd")))
96     "ab|cd")
97
98 (deftest :pss.3
99     (with-output-to-string (s) (print-separated-strings s "|" '("ab" "cd") nil))
100     "ab|cd")
101
102 (deftest :pss.4
103     (with-output-to-string (s)
104       (print-separated-strings s "|" '("ab" "cd") nil nil))
105     "ab|cd")
106
107 (deftest :pss.5
108     (with-output-to-string (s)
109       (print-separated-strings s "|" '("ab" "cd") nil '("ef") nil))
110     "ab|cd|ef")
111
112 (deftest :css.0 (concat-separated-strings "|" nil) "")
113 (deftest :css.1 (concat-separated-strings "|" nil nil) "")
114 (deftest :css.2 (concat-separated-strings "|" '("ab")) "ab")
115 (deftest :css.3 (concat-separated-strings "|" '("ab" "cd")) "ab|cd")
116 (deftest :css.4 (concat-separated-strings "|" '("ab" "cd") nil) "ab|cd")
117 (deftest :css.5 (concat-separated-strings "|" '("ab" "cd") nil '("ef")) "ab|cd|ef")
118
119 (deftest :f.1 (map-and-remove-nils #'(lambda (x) (when (oddp x) (* x x)))
120                      '(0 1 2 3 4 5 6 7 8 9)) (1 9 25 49 81))
121 (deftest :f.2 (filter #'(lambda (x) (when (oddp x) (* x x)))
122                      '(0 1 2 3 4 5 6 7 8 9)) (1 3 5 7 9))
123 (deftest :an.1 (appendnew '(a b c d) '(c c e f)) (a b c d e f))
124
125
126 (deftest :pxml.1
127   (xml-tag-contents "tag1" "<tag>Test</tag>")
128   nil nil nil)
129
130 (deftest :pxml.2
131   (xml-tag-contents "tag" "<tag>Test</tag>")
132   "Test" 15 nil)
133
134 (deftest :pxml.3
135   (xml-tag-contents "tag" "<tag  >Test</tag>")
136   "Test" 17 nil)
137
138 (deftest :pxml.4
139     (xml-tag-contents "tag" "<tag a=\"b\"></tag>")
140   "" 17 ("a=\"b\""))
141
142 (deftest :pxml.5
143     (xml-tag-contents "tag" "<tag a=\"b\" >Test</tag>")
144   "Test" 22 ("a=\"b\""))
145
146 (deftest :pxml.6
147     (xml-tag-contents "tag" "<tag a=\"b\"  c=\"ab\">Test</tag>")
148   "Test" 29 ("a=\"b\"" "c=\"ab\""))
149
150 (deftest :pxml.7
151     (xml-tag-contents "tag" "<taga a=\"b\"  c=\"ab\">Test</taga>")
152   nil nil nil)
153
154 (deftest :pxml.8
155     (xml-tag-contents "tag" "<taga a=\"b\"  c=\"ab\">Test<tag>ab</tag></taga>")
156   "ab" 37 nil)
157
158 (deftest :pxml.9
159     (xml-tag-contents "tag" "<taga a=\"b\"  c=\"ab\">Test<tag>ab</ag></taga>")
160   nil nil nil)
161
162 (deftest :fss.1 (fast-string-search "" "" 0 0 0) 0)
163 (deftest :fss.2 (fast-string-search "" "abc" 0 0 2) 0)
164 (deftest :fss.3 (fast-string-search "abc" "" 3 0 0) nil)
165 (deftest :fss.4 (fast-string-search "abc" "abcde" 3 0 4) 0)
166 (deftest :fss.5 (fast-string-search "abc" "012abcde" 3 0 7) 3)
167 (deftest :fss.6 (fast-string-search "abc" "012abcde" 3 0 7) 3)
168 (deftest :fss.7 (fast-string-search "abc" "012abcde" 3 3 7) 3)
169 (deftest :fss.8 (fast-string-search "abc" "012abcde" 3 4 7) nil)
170 (deftest :fss.9 (fast-string-search "abcde" "012abcde" 5 3 8) 3)
171 (deftest :fss.9b (cl:search "abcde" "012abcde" :start2 3 :end2 8) 3)
172 (deftest :fss.10 (fast-string-search "abcde" "012abcde" 5 3 7) nil)
173 (deftest :fss.10b (cl:search "abcde" "012abcde" :start2 3 :end2 7) nil)
174
175 (deftest :stlsd.1 (string-to-list-skip-delimiter "") ())
176 (deftest :stlsd.2 (string-to-list-skip-delimiter "abc") ("abc"))
177 (deftest :stlsd.3 (string-to-list-skip-delimiter "ab c") ("ab" "c"))
178 (deftest :stlsd.4 (string-to-list-skip-delimiter "ab  c") ("ab" "c"))
179 (deftest :stlsd.5 (string-to-list-skip-delimiter "ab   c") ("ab" "c"))
180 (deftest :stlsd.6 (string-to-list-skip-delimiter "ab   c ") ("ab" "c"))
181 (deftest :stlsd.7 (string-to-list-skip-delimiter "  ab   c  ") ("ab" "c"))
182 (deftest :stlsd.8 (string-to-list-skip-delimiter "ab,,c" #\,) ("ab" "c"))
183 (deftest :stlsd.9 (string-to-list-skip-delimiter "ab,,c,," #\,) ("ab" "c"))
184 (deftest :stlsd.10 (string-to-list-skip-delimiter " ab") ("ab"))
185
186 (deftest :csc.1 (count-string-char "" #\a) 0)
187 (deftest :csc.2 (count-string-char "abc" #\d) 0)
188 (deftest :csc.3 (count-string-char "abc" #\b) 1)
189 (deftest :csc.4 (count-string-char "abcb" #\b) 2)
190
191 (deftest :duqs.1 (decode-uri-query-string "") "")
192 (deftest :duqs.2 (decode-uri-query-string "abc") "abc")
193 (deftest :duqs.3 (decode-uri-query-string "abc+") "abc ")
194 (deftest :duqs.4 (decode-uri-query-string "abc+d") "abc d")
195 (deftest :duqs.5 (decode-uri-query-string "abc%20d") "abc d")
196
197 (deftest :sse.1 (string-strip-ending "" nil) "")
198 (deftest :sse.2 (string-strip-ending "abc" nil) "abc")
199 (deftest :sse.3 (string-strip-ending "abc" "ab") "abc")
200 (deftest :sse.4 (string-strip-ending "abc" '("ab")) "abc")
201 (deftest :sse.5 (string-strip-ending "abcd" '("a" "cd")) "ab")
202
203 (deftest :rcs.1 (remove-char-string #\space "") "")
204 (deftest :rcs.2 (remove-char-string #\space "a") "a")
205 (deftest :rcs.3 (remove-char-string #\space "ab") "ab")
206 (deftest :rcs.4 (remove-char-string #\space "a b") "ab")
207 (deftest :rcs.5 (remove-char-string #\space " a b") "ab")
208 (deftest :rcs.6 (remove-char-string #\space "a b ") "ab")
209 (deftest :rcs.7 (remove-char-string #\space "a  b   c  ") "abc")
210 (deftest :rcs.8 (remove-char-string #\space "a  b   c  d") "abcd")
211
212
213 (defun test-color-conversion ()
214   (dotimes (ih 11)
215     (dotimes (is 11)
216       (dotimes (iv 11)
217         (let ((h (* ih 30))
218               (s (/ is 10))
219               (v (/ iv 10)))
220           (multiple-value-bind (r g b) (hsv->rgb h s v)
221             (multiple-value-bind (h2 s2 v2) (rgb->hsv r g b)
222               (unless (hsv-equal h s v h2 s2 v2)
223                 (warn "Colors not equal: ~4D ~4D ~4D | ~6D:~6D ~6D:~6D ~6D:~6D~%"
224                         (float r) (float g) (float b)
225                         (when (typep h 'number) (float h))
226                         (when (typep h2 'number) (float h2))
227                         (float s) (float s2) (float v) (float v2))
228                 (return-from test-color-conversion nil))))))))
229   t)
230
231 (defun test-color-conversion-float-255 ()
232   (dotimes (ih 11)
233     (dotimes (is 11)
234       (dotimes (iv 11)
235         (let ((h (* ih 30))
236               (s (/ is 10))
237               (v (/ iv 10)))
238           (multiple-value-bind (r g b) (hsv->rgb h s v)
239             (setf r (round (* 255 r))
240                   g (round (* 255 g))
241                   b (round (* 255 b)))
242             (multiple-value-bind (h2 s2 v2) (rgb255->hsv255 r g b)
243               (unless (hsv-similar h s v h2 (/ s2 255) (/ v2 255)
244                                    :hue-range 10 :saturation-range .1
245                                    :value-range 1 :black-limit 0 :gray-limit 0)
246                 (warn "Colors not equal: ~4D ~4D ~4D | ~6D:~6D ~6D:~6D ~6D:~6D~%"
247                       r g b
248                       (when (typep h 'number) (float h))
249                       (when (typep h2 'number) (float h2))
250                       (float s) (float (/ s2 255)) (float v) (float (/ v2 255)))
251                 (return-from test-color-conversion-float-255 nil))))))))
252   t)
253
254 (defun test-color-conversion-255-float ()
255   (dotimes (ih 11)
256     (dotimes (is 11)
257       (dotimes (iv 11)
258         (let ((h (* ih 30))
259               (s (/ is 10))
260               (v (/ iv 10)))
261           (multiple-value-bind (r g b) (hsv255->rgb255 h (truncate (* 255 s))
262                                                        (truncate (* 255 v)))
263             (setf r (/ r 255)
264                   g (/ g 255)
265                   b (/ b 255))
266
267             (multiple-value-bind (h2 s2 v2) (rgb->hsv r g b)
268               (unless (hsv-similar h s v h2 s2 v2
269                                    :hue-range 10 :saturation-range .1
270                                    :value-range 1 :black-limit 0 :gray-limit 0)
271                 (warn "Colors not equal: ~4D ~4D ~4D | ~6D:~6D ~6D:~6D ~6D:~6D~%"
272                       r g b
273                       (when (typep h 'number) (float h))
274                       (when (typep h2 'number) (float h2))
275                       (float s) (float (/ s2 255)) (float v) (float (/ v2 255)))
276                 (return-from test-color-conversion-255-float nil))))))))
277   t)
278
279 (defun test-color-conversion-255 ()
280   (dotimes (ih 11)
281     (dotimes (is 11)
282       (dotimes (iv 11)
283         (let ((h (* ih 30))
284               (s (truncate (* 255 (/ is 10))))
285               (v (truncate (* 255 (/ iv 10)))))
286           (multiple-value-bind (r g b) (hsv255->rgb255 h s v)
287             (multiple-value-bind (h2 s2 v2) (rgb255->hsv255 r g b)
288               (unless (hsv255-similar h s v h2 s2 v2 :hue-range 10 :saturation-range 5
289                                       :value-range 5 :black-limit 0 :gray-limit 0)
290                 (warn "Colors not equal: ~D ~D ~D |~
291  ~3,'0D:~3,'0D ~3,'0D:~3,'0D ~3,'0D:~3,'0D~%"
292                       r g b
293                       h h2 s s2 v v2)
294                 (return-from test-color-conversion-255 nil))))))))
295   t)
296
297 (deftest :color.conv (test-color-conversion) t)
298 (deftest :color.conv.float.255 (test-color-conversion-float-255) t)
299 (deftest :color.conv.255.float (test-color-conversion-255-float) t)
300 (deftest :color.conv.255 (test-color-conversion-255) t)
301
302 (deftest :hue.diff.1 (hue-difference 10 10) 0)
303 (deftest :hue.diff.2 (hue-difference 10 9) -1)
304 (deftest :hue.diff.3 (hue-difference 9 10) 1)
305 (deftest :hue.diff.4 (hue-difference 10 nil) 360)
306 (deftest :hue.diff.5 (hue-difference nil 1) 360)
307 (deftest :hue.diff.7 (hue-difference 10 190) 180)
308 (deftest :hue.diff.8 (hue-difference 190 10) -180)
309 (deftest :hue.diff.9 (hue-difference 1 359) -2)
310 (deftest :hue.diff.10 (hue-difference 1 182) -179)
311 (deftest :hue.diff.11 (hue-difference 1 270) -91)
312
313 (deftest :hsv.sim.1 (hsv-similar 100 .5 .5 110 .5 .5 :hue-range 5
314                                 :value-range 0 :saturation-range 0
315                                 :black-limit 0 :gray-limit 0) nil)
316 (deftest :hsv.sim.2 (hsv-similar 100 .5 .5 110 .5 .5 :hue-range 15
317                                 :value-range 0 :saturation-range 0
318                                 :black-limit 0 :gray-limit 0) t)
319 (deftest :hsv.sim.3 (hsv-similar 100 .5 .5 110 .5 .6 :hue-range 15
320                                 :value-range .2 :saturation-range 0
321                                 :black-limit 0 :gray-limit 0) t)
322 (deftest :hsv.sim.4 (hsv-similar 100 .5 .5 110 .5 .8 :hue-range 15
323                                 :value-range 0.2 :saturation-range 0
324                                 :black-limit 0 :gray-limit 0) nil)
325 (deftest :hsv.sim.5 (hsv-similar 100 .5 .5 110 .6 .6 :hue-range 15
326                                 :value-range 0.2 :saturation-range .2
327                                 :black-limit 0 :gray-limit 0) t)
328 (deftest :hsv.sim.6 (hsv-similar 100 .5 .5 110 .6 .8 :hue-range 15
329                                 :value-range 0.2 :saturation-range .2
330                                 :black-limit 0 :gray-limit 0) nil)
331 (deftest :hsv.sim.7 (hsv-similar 100 .5 .05 110 .6 .01 :hue-range 0
332                                 :value-range 0 :saturation-range 0
333                                 :black-limit .1 :gray-limit 0) t)
334 (deftest :hsv.sim.8 (hsv-similar 100 .01 .5 110 .09 .6 :hue-range 0
335                                 :value-range 0.2 :saturation-range 0
336                                 :black-limit 0 :gray-limit .1) t)
337 (deftest :hsv.sim.9 (hsv-similar 100 .01 .5 110 .09 .6 :hue-range 0
338                                 :value-range 0.05 :saturation-range 0
339                                 :black-limit 0 :gray-limit .1) nil)
340
341 #+ignore
342 (progn
343 (deftest :dst.1
344     (is-dst-change-usa-spring-utime
345      (encode-universal-time 0 0 0 2 4 2000)) t)
346 (deftest :dst.2
347     (is-dst-change-usa-spring-utime
348      (encode-universal-time 0 0 0 1 4 2000)) nil)
349 (deftest :dst.3
350     (is-dst-change-usa-spring-utime
351      (encode-universal-time 0 0 0 3 4 2000)) nil)
352 (deftest :dst.4
353     (is-dst-change-usa-fall-utime
354      (encode-universal-time 0 0 0 31 10 2004)) t)
355 (deftest :dst.5
356     (is-dst-change-usa-fall-utime
357      (encode-universal-time 0 0 0 30 10 2004)) nil)
358 (deftest :dst.6
359     (is-dst-change-usa-fall-utime
360      (encode-universal-time 0 0 0 1 11 2000)) nil)
361 )
362
363 (deftest :sts.1
364     (seconds-to-condensed-time-string 0) "0s")
365 (deftest :sts.2
366     (seconds-to-condensed-time-string 60) "1m0s")
367 (deftest :sts.3
368     (seconds-to-condensed-time-string 65) "1m5s")
369 (deftest :sts.4
370     (seconds-to-condensed-time-string 3600) "1h0m0s")
371 (deftest :sts.5
372     (seconds-to-condensed-time-string 36000) "10h0m0s")
373 (deftest :sts.6
374     (seconds-to-condensed-time-string 86400) "1d0h0m0s")
375 (deftest :sts.7
376     (seconds-to-condensed-time-string (* 7 86400)) "1w0d0h0m0s")
377 (deftest :sts.8
378     (seconds-to-condensed-time-string (* 21 86400)) "3w0d0h0m0s")
379 (deftest :sts.9
380     (seconds-to-condensed-time-string (+ 86400 7200 120 50 (* 21 86400))) "3w1d2h2m50s")
381 (deftest :sts.10
382     (seconds-to-condensed-time-string (+ .1 86400 7200 120 50 (* 21 86400))
383                                       :dp-digits 1) "3w1d2h2m50.1s")
384
385 (deftest :ekdc.1
386     (ensure-keyword-default-case (read-from-string "TYPE")) :type)
387
388 (deftest :ekdc.2
389     (ensure-keyword-default-case (read-from-string "type")) :type)
390
391
392 (deftest :se.1
393     (string-elide "A Test string" 10 :end) "A Test ..." )
394
395 (deftest :se.2
396     (string-elide "A Test string" 13 :end) "A Test string")
397
398 (deftest :se.3
399     (string-elide "A Test string" 11 :end) "A Test s..." )
400
401 (deftest :se.4
402     (string-elide "A Test string" 2 :middle) "...")
403
404 (deftest :se.5
405     (string-elide "A Test string" 11 :middle) "A Te...ring")
406
407 (deftest :se.6
408     (string-elide "A Test string" 12 :middle) "A Tes...ring")
409
410 (deftest :url.1
411     (make-url "pg")
412   "pg")
413
414 (deftest :url.2
415     (make-url "pg" :anchor "now")
416   "pg#now")
417
418 (deftest :url.3
419     (make-url "pg" :vars '(("a" . "5")))
420   "pg?a=5")
421
422 (deftest :url.4
423     (make-url "pg" :anchor "then" :vars '(("a" . "5") ("b" . "pi")))
424   "pg?a=5&b=pi#then")
425
426 (defclass test-unique ()
427   ((a :initarg :a)
428    (b :initarg :b)))
429
430
431 (deftest :unique.1
432     (let ((list (list (make-instance 'test-unique :a 1 :b 1)
433                       (make-instance 'test-unique :a 2 :b 2)
434                       (make-instance 'test-unique :a 3 :b 2))))
435       (values
436        (unique-slot-values list 'a)
437        (unique-slot-values list 'b)))
438   (1 2 3) (1 2))
439
440 (deftest :unique.2
441     (unique-slot-values nil 'a)
442   nil)
443
444 (deftest :nwp.1
445        (numbers-within-percentage 1. 1.1 9)
446   nil)
447
448 (deftest :nwp.2
449        (numbers-within-percentage 1. 1.1 11)
450   t)
451
452 (deftest :pfs.1 (prefixed-fixnum-string 0 #\A 5) "A00000")
453
454 (deftest :pfs.2 (prefixed-fixnum-string 1 #\A 5) "A00001")
455
456 (deftest :pfs.3 (prefixed-fixnum-string 21 #\B 3) "B021")
457
458 (deftest :pis.4 (prefixed-integer-string 234134 #\C 7) "C0234134")
459
460 ;;; Binary tree search tests
461
462 (defvar *btree-vector*)
463
464 (defun init-btree-vector (len)
465   (make-random-state t)
466   (setq *btree-vector* (make-array (list len)
467                                    :element-type 'fixnum
468                                    :initial-element 0))
469   (dotimes (i (length *btree-vector*))
470     (do ((rand (random most-positive-fixnum) (random most-positive-fixnum)))
471         ((not (find rand *btree-vector* :end i))
472          (setf (aref *btree-vector* i) rand))))
473   (setq *btree-vector* (sort *btree-vector* #'<)))
474
475 (defun test-btree-vector (len)
476   (init-btree-vector len)
477   (dotimes (i (length *btree-vector*) t)
478     (let ((stored (aref *btree-vector* i)))
479       (multiple-value-bind (pos value last-pos count)
480           (sorted-vector-find stored *btree-vector*)
481         (declare (ignore last-pos))
482         (when (or (not (eql i pos)) (not (eql stored value)))
483           (format t "~&Error: btree value ~D at pos ~D: found ~D at pos ~D [count ~D].~%"
484                   stored i value pos count)
485           (return nil))))))
486
487 (deftest :btree.1
488     (dotimes (i 1000 t)
489       (test-btree-vector i))
490   t)
491
492 (defun time-btree (&optional (fn #'sorted-vector-find) (return-on-error nil))
493   (time
494    (let ((total-count 0))
495      (declare (fixnum total-count))
496      (dotimes (i (length *btree-vector*) t)
497        (let ((stored (aref *btree-vector* i)))
498          (multiple-value-bind (value pos count)
499              (funcall fn stored *btree-vector*)
500            (incf total-count count)
501            (when (or (/= i pos) (/= stored value))
502              (format t "~&Error: btree value ~D at pos ~D: found ~D at pos ~D [count ~D].~%"
503                      stored i value pos count)
504              (when return-on-error
505                (return-from time-btree nil))))))
506      (float (/ total-count (length *btree-vector*))))))
507
508 ;;; MOP Testing
509
510 ;; Disable attrib class until understand changes in sbcl/cmucl
511 ;; using COMPUTE-SLOT-ACCESSOR-INFO and defining method
512 ;; for slot access of ALL-ATTRIBUTES. Does this work on Allegro/LW?
513
514 #+ignore
515 (progn
516 (eval-when (:compile-toplevel :load-toplevel :execute)
517   (when (find-package '#:kmr-mop)
518     (pushnew :kmrtest-mop cl:*features*)))
519
520 #+kmrtest-mop
521 (setf (find-class 'monitored-credit-rating) nil)
522 #+kmrtest-mop
523 (setf (find-class 'credit-rating) nil)
524
525 #+kmrtest-mop
526 (defclass credit-rating ()
527   ((level :attributes (date-set time-set))
528    (id :attributes (person-setting)))
529   #+lispworks (:optimize-slot-access nil)
530   (:metaclass attributes-class))
531
532
533 #+kmrtest-mop
534 (defclass monitored-credit-rating ()
535   ((level :attributes (last-checked interval date-set))
536    (cc :initarg :cc)
537    (id :attributes (verified)))
538   (:metaclass attributes-class))
539
540 #+kmrtest-mop
541 (deftest :attrib.mop.1
542          (let ((cr (make-instance 'credit-rating)))
543            (slot-attribute cr 'level 'date-set))
544          nil)
545
546 #+kmrtest-mop
547 (deftest :attrib.mop.2
548          (let ((cr (make-instance 'credit-rating)))
549            (setf (slot-attribute cr 'level 'date-set) "12/15/1990")
550            (let ((result (slot-attribute cr 'level 'date-set)))
551              (setf (slot-attribute cr 'level 'date-set) nil)
552              result))
553          "12/15/1990")
554
555 #+kmrtest-mop
556 (deftest :attrib.mop.3
557          (let ((mcr (make-instance 'monitored-credit-rating)))
558            (setf (slot-attribute mcr 'level 'date-set) "01/05/2002")
559            (let ((result (slot-attribute mcr 'level 'date-set)))
560              (setf (slot-attribute mcr 'level 'date-set) nil)
561              result))
562          "01/05/2002")
563
564
565 #+kmrtest-mop
566 (eval-when (:compile-toplevel :load-toplevel :execute)
567   (setq cl:*features* (delete :kmrtest-mop cl:*features*)))
568
569 ) ;; progn