1 ;;; map-tests.el -- Regression Tests for the map* functions
2 ;; Copyright (C) 2006 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))))
37 (defmacro Assert-set-equality (s1 s2)
38 (let* ((m1 (if (arrayp s1) 'across 'in))
39 (m2 (if (arrayp s2) 'across 'in)))
41 (Assert (equal (type-of ,s1) (type-of ,s2)))
42 (Assert (= (length ,s1) (length ,s2)))
48 thereis (equal i j)))))))
50 (defmacro Assert-tup-equality (s1 s2)
51 (let* ((m1 (if (arrayp s1) 'across 'in))
52 (m2 (if (arrayp s2) 'across 'in)))
54 (Assert (equal (type-of ,s1) (type-of ,s2)))
59 always (equal i j))))))
66 (null (mapfam #'cons :arity 0 '(1 2) '(3 4))))
68 (null (mapfam nil :mode 'void '(1 2) '(3 4))))
70 (null (mapfam #'cons)))
75 (mapfam nil [1 2 3 4 5 6])
79 (mapfam nil :mode 'pntw [1 2 3 4 5 6])
83 (mapfam nil :mode 'pntw [1 2 3 4 5 6] :arity 2)
84 '((1 2) (3 4) (5 6))))
87 (mapfam nil :mode 'pntw [1 2 3 4 5 6] :arity 3)
92 (mapfam nil :mode 'pntw :glue #'vector [1 2 3 4 5 6])
96 (mapfam nil :mode 'pntw :glue #'vector [1 2 3 4 5 6] :arity 2)
97 '([1 2] [3 4] [5 6])))
100 (mapfam nil :mode 'pntw :glue #'vector [1 2 3 4 5 6] :arity 3)
102 ;; same on vectors/vectors
105 (mapfam nil :mode 'pntw :result-type #'vector :glue #'vector [1 2 3 4 5 6])
109 (mapfam nil :mode 'pntw :result-type #'vector :glue #'vector [1 2 3 4 5 6] :arity 2)
110 [[1 2] [3 4] [5 6]]))
113 (mapfam nil :mode 'pntw :result-type #'vector :glue #'vector [1 2 3 4 5 6] :arity 3)
118 (mapfam nil :mode 'pntw :arity 2 [1 2 3 4 5 6 7])
119 '((1 2) (3 4) (5 6))))
122 (mapfam nil :mode 'pntw :arity 3 [1 2 3 4 5 6 7])
126 (mapfam nil :mode 'pntw :glue #'vector :arity 2 [1 2 3 4 5 6 7])
127 '([1 2] [3 4] [5 6])))
130 (mapfam nil :mode 'pntw :glue #'vector :arity 3 [1 2 3 4 5 6 7])
134 (mapfam nil :mode 'pntw :result-type #'vector :glue #'vector :arity 2
136 [[1 2] [3 4] [5 6]]))
139 (mapfam nil :mode 'pntw :result-type #'vector :glue #'vector :arity 3
142 ;; larger glue than sequence
145 (mapfam nil :mode 'pntw [1 2 3 4 5 6] :arity 8)
149 (mapfam nil :mode 'pntw [1 2 3 4 5 6] :glue #'vector :arity 8)
153 (mapfam nil :mode 'pntw [1 2 3 4 5 6] :result-type #'vector :arity 8)
157 (mapfam nil :mode 'pntw [1 2 3 4 5 6] :result-type #'dllist :arity 8)
160 ;; prepare a hash-table
161 (setq test-ht (make-hash-table))
162 (puthash 12 'a test-ht)
163 (puthash 14 'b test-ht)
164 (puthash 13 'c test-ht)
165 (puthash 16 'e test-ht)
166 (puthash 15 'd test-ht)
167 ;; ... and a skiplist
168 (setq test-sl (make-skiplist))
169 (put-skiplist test-sl 12 'a)
170 (put-skiplist test-sl 14 'b)
171 (put-skiplist test-sl 13 'c)
172 (put-skiplist test-sl 16 'e)
173 (put-skiplist test-sl 15 'd)
177 '((12 a) (13 c) (14 b) (16 e) (15 d)))
179 (mapfam nil test-ht :arity '(1 1))
180 '((12 a) (13 c) (14 b) (16 e) (15 d)))
182 (mapfam nil test-ht :arity 1)
185 (mapfam nil test-ht :mode 'keyw)
188 (mapfam nil test-ht :glue #'vector)
189 '([12 a] [13 c] [14 b] [16 e] [15 d]))
193 '((12 a) (13 c) (14 b) (16 e) (15 d)))
195 (mapfam nil test-sl :arity '(1 1))
196 '((12 a) (13 c) (14 b) (16 e) (15 d)))
198 (mapfam nil test-sl :arity 1)
201 (mapfam nil test-sl :mode 'keyw)
204 (mapfam nil test-sl :glue #'vector)
205 '([12 a] [13 c] [14 b] [16 e] [15 d]))
209 (mapfam nil :mode 'comb [1 2 3 4] :arity 2)
210 '((1 2) (1 3) (1 4) (2 3) (2 4) (3 4)))
211 (Assert-tup-equality ;; we're sure that this is the order
212 (mapfam nil :mode 'comb [1 2 3 4] :arity 2)
213 '((1 2) (1 3) (1 4) (2 3) (2 4) (3 4)))
215 (mapfam nil :mode 'comb [1 2 3 4] :arity 2 :glue #'vector)
216 '([1 2] [1 3] [1 4] [2 3] [2 4] [3 4]))
217 (Assert-tup-equality ;; we're sure that this is the order
218 (mapfam nil :mode 'comb [1 2 3 4] :arity 2 :glue #'vector)
219 '([1 2] [1 3] [1 4] [2 3] [2 4] [3 4]))
222 (mapfam nil :mode 'comb [1 2 3 4] :arity 3)
223 '((1 2 3) (1 2 4) (1 3 4) (2 3 4)))
224 (Assert-tup-equality ;; we're sure that this is the order
225 (mapfam nil :mode 'comb [1 2 3 4] :arity 3)
226 '((1 2 3) (1 2 4) (1 3 4) (2 3 4)))
228 (mapfam nil :mode 'comb [1 2 3 4] :arity 3 :glue 'vector)
229 '([1 2 3] [1 2 4] [1 3 4] [2 3 4]))
231 (mapfam nil :mode 'comb [1 2 3 4] :arity 3 :glue 'vector)
232 '([1 2 3] [1 2 4] [1 3 4] [2 3 4]))
234 (mapfam nil :mode 'comb [1 2 3 4] :arity 4)
237 (mapfam nil :mode 'comb [1 2 3 4] :arity 4)
240 (mapfam nil :mode 'comb [1 2 3 4] :arity 4 :glue 'vector)
243 (mapfam nil :mode 'comb [1 2 3 4] :arity 4 :glue 'vector)
247 (mapfam nil :mode 'comb [1 2 3 4 5 6] :arity 2)
248 '((1 2) (1 3) (1 4) (1 5) (1 6)
249 (2 3) (2 4) (2 5) (2 6)
254 (mapfam nil :mode 'comb [1 2 3 4 5 6] :arity 2)
255 '((1 2) (1 3) (1 4) (1 5) (1 6)
256 (2 3) (2 4) (2 5) (2 6)
261 (mapfam nil :mode 'comb [1 2 3 4 5 6] :arity 2 :glue 'dllist)
263 (dllist 1 2) (dllist 1 3) (dllist 1 4) (dllist 1 5) (dllist 1 6)
264 (dllist 2 3) (dllist 2 4) (dllist 2 5) (dllist 2 6)
265 (dllist 3 4) (dllist 3 5) (dllist 3 6)
266 (dllist 4 5) (dllist 4 6)
269 (mapfam nil :mode 'comb [1 2 3 4 5 6] :arity 2 :glue 'dllist)
271 (dllist 1 2) (dllist 1 3) (dllist 1 4) (dllist 1 5) (dllist 1 6)
272 (dllist 2 3) (dllist 2 4) (dllist 2 5) (dllist 2 6)
273 (dllist 3 4) (dllist 3 5) (dllist 3 6)
274 (dllist 4 5) (dllist 4 6)
277 (mapfam nil :mode 'comb [1 2 3 4 5 6] :arity 3)
278 '((1 2 3) (1 2 4) (1 2 5) (1 2 6)
279 (1 3 4) (1 3 5) (1 3 6)
282 (2 3 4) (2 3 5) (2 3 6)
289 (mapfam nil :mode 'comb [1 2 3 4 5 6] :arity 3)
290 '((1 2 3) (1 2 4) (1 2 5) (1 2 6)
291 (1 3 4) (1 3 5) (1 3 6)
294 (2 3 4) (2 3 5) (2 3 6)
301 (mapfam nil :mode 'comb [1 2 3 4 5 6] :arity 3 :glue #'dllist)
303 (dllist 1 2 3) (dllist 1 2 4) (dllist 1 2 5) (dllist 1 2 6)
304 (dllist 1 3 4) (dllist 1 3 5) (dllist 1 3 6)
305 (dllist 1 4 5) (dllist 1 4 6)
307 (dllist 2 3 4) (dllist 2 3 5) (dllist 2 3 6)
308 (dllist 2 4 5) (dllist 2 4 6)
310 (dllist 3 4 5) (dllist 3 4 6)
314 (mapfam nil :mode 'comb [1 2 3 4 5 6] :arity 4)
315 '((1 2 3 4) (1 2 3 5) (1 2 3 6) (1 2 4 5) (1 2 4 6) (1 2 5 6)
316 (1 3 4 5) (1 3 4 6) (1 3 5 6)
318 (2 3 4 5) (2 3 4 6) (2 3 5 6) (2 4 5 6)
322 (mapfam nil :mode 'comb [1 2 3 4 5 6 7 8 9] :arity 4)
323 '((1 2 3 4) (1 2 3 5) (1 2 3 6) (1 2 3 7) (1 2 3 8) (1 2 3 9)
324 (1 2 4 5) (1 2 4 6) (1 2 4 7) (1 2 4 8) (1 2 4 9)
325 (1 2 5 6) (1 2 5 7) (1 2 5 8) (1 2 5 9)
326 (1 2 6 7) (1 2 6 8) (1 2 6 9)
329 (1 3 4 5) (1 3 4 6) (1 3 4 7) (1 3 4 8) (1 3 4 9)
330 (1 3 5 6) (1 3 5 7) (1 3 5 8) (1 3 5 9)
331 (1 3 6 7) (1 3 6 8) (1 3 6 9)
334 (1 4 5 6) (1 4 5 7) (1 4 5 8) (1 4 5 9)
335 (1 4 6 7) (1 4 6 8) (1 4 6 9)
338 (1 5 6 7) (1 5 6 8) (1 5 6 9)
344 (2 3 4 5) (2 3 4 6) (2 3 4 7) (2 3 4 8) (2 3 4 9)
345 (2 3 5 6) (2 3 5 7) (2 3 5 8) (2 3 5 9)
346 (2 3 6 7) (2 3 6 8) (2 3 6 9)
349 (2 4 5 6) (2 4 5 7) (2 4 5 8) (2 4 5 9)
350 (2 4 6 7) (2 4 6 8) (2 4 6 9)
353 (2 5 6 7) (2 5 6 8) (2 5 6 9)
359 (3 4 5 6) (3 4 5 7) (3 4 5 8) (3 4 5 9)
360 (3 4 6 7) (3 4 6 8) (3 4 6 9)
363 (3 5 6 7) (3 5 6 8) (3 5 6 9)
369 (4 5 6 7) (4 5 6 8) (4 5 6 9)
380 (Assert (null (mapfam nil :mode 'comb :arity 2 [a])))
381 (Assert (null (mapfam nil :mode 'comb :arity 3 [a])))
382 (Assert (null (mapfam nil :mode 'comb :arity 4 [a])))
383 (Assert (null (mapfam nil :mode 'comb :arity 5 [a])))
384 (Assert (null (mapfam nil :mode 'comb :arity 6 [a])))
385 (Assert (null (mapfam nil :mode 'comb :arity 3 [a b])))
386 (Assert (null (mapfam nil :mode 'comb :arity 4 [a b])))
387 (Assert (null (mapfam nil :mode 'comb :arity 5 [a b])))
388 (Assert (null (mapfam nil :mode 'comb :arity 6 [a b])))
389 (Assert (null (mapfam nil :mode 'comb :arity 4 [a b c])))
390 (Assert (null (mapfam nil :mode 'comb :arity 5 [a b c])))
391 (Assert (null (mapfam nil :mode 'comb :arity 6 [a b c])))
392 ;; more of them phenomena
395 (mapfam nil :mode 'comb :arity 2 [a] :result-type #'vector)
399 (mapfam nil :mode 'comb :arity 3 [a] :result-type #'vector)
403 (mapfam nil :mode 'comb :arity 4 [a] :result-type #'vector)
407 (mapfam nil :mode 'comb :arity 5 [a] :result-type #'vector)
411 (mapfam nil :mode 'comb :arity 6 [a] :result-type #'vector)
415 (mapfam nil :mode 'comb :arity 3 [a b] :result-type #'vector)
419 (mapfam nil :mode 'comb :arity 4 [a b] :result-type #'vector)
423 (mapfam nil :mode 'comb :arity 5 [a b] :result-type #'vector)
427 (mapfam nil :mode 'comb :arity 6 [a b] :result-type #'vector)
431 (mapfam nil :mode 'comb :arity 4 [a b c] :result-type #'vector)
435 (mapfam nil :mode 'comb :arity 5 [a b c] :result-type #'vector)
439 (mapfam nil :mode 'comb :arity 6 [a b c] :result-type #'vector)
444 (mapfam nil :mode 'comb :arity 2 [a] :result-type #'dllist)
448 (mapfam nil :mode 'comb :arity 3 [a] :result-type #'dllist)
452 (mapfam nil :mode 'comb :arity 4 [a] :result-type #'dllist)
456 (mapfam nil :mode 'comb :arity 5 [a] :result-type #'dllist)
460 (mapfam nil :mode 'comb :arity 6 [a] :result-type #'dllist)
464 (mapfam nil :mode 'comb :arity 3 [a b] :result-type #'dllist)
468 (mapfam nil :mode 'comb :arity 4 [a b] :result-type #'dllist)
472 (mapfam nil :mode 'comb :arity 5 [a b] :result-type #'dllist)
476 (mapfam nil :mode 'comb :arity 6 [a b] :result-type #'dllist)
480 (mapfam nil :mode 'comb :arity 4 [a b c] :result-type #'dllist)
484 (mapfam nil :mode 'comb :arity 5 [a b c] :result-type #'dllist)
488 (mapfam nil :mode 'comb :arity 6 [a b c] :result-type #'dllist)
493 (mapfam nil :mode 'comb :arity 2 [a] :result-type #'string)
497 (mapfam nil :mode 'comb :arity 3 [a] :result-type #'string)
501 (mapfam nil :mode 'comb :arity 4 [a] :result-type #'string)
505 (mapfam nil :mode 'comb :arity 5 [a] :result-type #'string)
509 (mapfam nil :mode 'comb :arity 6 [a] :result-type #'string)
513 (mapfam nil :mode 'comb :arity 3 [a b] :result-type #'string)
517 (mapfam nil :mode 'comb :arity 4 [a b] :result-type #'string)
521 (mapfam nil :mode 'comb :arity 5 [a b] :result-type #'string)
525 (mapfam nil :mode 'comb :arity 6 [a b] :result-type #'string)
529 (mapfam nil :mode 'comb :arity 4 [a b c] :result-type #'string)
533 (mapfam nil :mode 'comb :arity 5 [a b c] :result-type #'string)
537 (mapfam nil :mode 'comb :arity 6 [a b c] :result-type #'string)
543 (mapfam nil [0 1 2] :mode 'cart :arity 1)
547 (mapfam nil [0 1 2] :mode 'cart :arity 2)
548 '((0 0) (0 1) (0 2) (1 0) (1 1) (1 2) (2 0) (2 1) (2 2))))
551 (mapfam nil [0 1 2] :mode 'cart :arity 3)
552 '((0 0 0) (0 0 1) (0 0 2) (0 1 0) (0 1 1) (0 1 2) (0 2 0) (0 2 1) (0 2 2)
553 (1 0 0) (1 0 1) (1 0 2) (1 1 0) (1 1 1) (1 1 2) (1 2 0) (1 2 1) (1 2 2)
554 (2 0 0) (2 0 1) (2 0 2) (2 1 0) (2 1 1) (2 1 2) (2 2 0) (2 2 1) (2 2 2))))
557 (mapfam nil [0 1 2] :mode 'cart :arity 4)
558 '((0 0 0 0) (0 0 0 1) (0 0 0 2) (0 0 1 0) (0 0 1 1) (0 0 1 2)
559 (0 0 2 0) (0 0 2 1) (0 0 2 2) (0 1 0 0) (0 1 0 1) (0 1 0 2)
560 (0 1 1 0) (0 1 1 1) (0 1 1 2) (0 1 2 0) (0 1 2 1) (0 1 2 2)
561 (0 2 0 0) (0 2 0 1) (0 2 0 2) (0 2 1 0) (0 2 1 1) (0 2 1 2)
562 (0 2 2 0) (0 2 2 1) (0 2 2 2)
563 (1 0 0 0) (1 0 0 1) (1 0 0 2) (1 0 1 0) (1 0 1 1) (1 0 1 2)
564 (1 0 2 0) (1 0 2 1) (1 0 2 2) (1 1 0 0) (1 1 0 1) (1 1 0 2)
565 (1 1 1 0) (1 1 1 1) (1 1 1 2) (1 1 2 0) (1 1 2 1) (1 1 2 2)
566 (1 2 0 0) (1 2 0 1) (1 2 0 2) (1 2 1 0) (1 2 1 1) (1 2 1 2)
567 (1 2 2 0) (1 2 2 1) (1 2 2 2)
568 (2 0 0 0) (2 0 0 1) (2 0 0 2) (2 0 1 0) (2 0 1 1) (2 0 1 2)
569 (2 0 2 0) (2 0 2 1) (2 0 2 2) (2 1 0 0) (2 1 0 1) (2 1 0 2)
570 (2 1 1 0) (2 1 1 1) (2 1 1 2) (2 1 2 0) (2 1 2 1) (2 1 2 2)
571 (2 2 0 0) (2 2 0 1) (2 2 0 2) (2 2 1 0) (2 2 1 1) (2 2 1 2)
572 (2 2 2 0) (2 2 2 1) (2 2 2 2))))
573 ;; for the next one we just pick 20 random elements out of 243
574 ;; ... this assumes that #'random works
575 (let ((5c (mapfam nil [0 1 2] :mode 'cart :arity 5)))
576 (Assert (= (length 5c) 243))
580 (list (random 3) (random 3) (random 3) (random 3) (random 3))
582 ;; to use something other than ints ...
583 (let ((6c (mapfam nil [1.4142 1.4142 1.4142] :mode 'cart :arity 6)))
584 (Assert (= (length 6c) 729))
585 ;; all elements must look the same
587 (Assert (equal (car 6c) '(1.4142 1.4142 1.4142 1.4142 1.4142 1.4142)))
589 ;; test invariance of input sequence type
592 (mapfam nil '(0 1 2) :mode 'cart :arity 1)
593 (mapfam nil (dllist 0 1 2) :mode 'cart :arity 1)))
596 (mapfam nil '(0 1 2) :mode 'cart :arity 2)
597 (mapfam nil (dllist 0 1 2) :mode 'cart :arity 2)))
600 (mapfam nil '(0 1 2) :mode 'cart :arity 3)
601 (mapfam nil (dllist 0 1 2) :mode 'cart :arity 3)))
604 (mapfam nil '(0 1 2) :mode 'cart :arity 4)
605 (mapfam nil (dllist 0 1 2) :mode 'cart :arity 4)))
608 (mapfam nil '(0 1 2) :mode 'cart :arity 5)
609 (mapfam nil (dllist 0 1 2) :mode 'cart :arity 5)))
612 (mapfam nil '(0 1 2) :mode 'cart :arity 9)
613 (mapfam nil (dllist 0 1 2) :mode 'cart :arity 9)))
617 (mapfam nil '(0 1) :mode 'perm)
621 (mapfam nil '(0 1) :mode 'perm :arity 1)
624 (mapfam nil '(0 1) :mode 'perm :arity 2)
627 (null (mapfam nil '(0 1) :mode 'perm :arity 3)))
630 (mapfam nil '(0 1 2) :mode 'perm)
631 '((0 1 2) (1 2 0) (2 0 1) (2 1 0) (1 0 2) (0 2 1)))
634 (mapfam nil '(0 1 2) :mode 'perm :arity 1)
637 (mapfam nil '(0 1 2) :mode 'perm :arity 2)
638 '((0 1) (1 0) (0 2) (2 0) (1 2) (2 1)))
640 (mapfam nil '(0 1 2) :mode 'perm :arity 3)
641 '((0 1 2) (1 2 0) (2 0 1) (2 1 0) (1 0 2) (0 2 1)))
643 (null (mapfam nil '(0 1 2) :mode 'perm :arity 4)))
646 (mapfam nil '(1 2 3 4) :mode 'perm)
647 '((1 2 3 4) (1 2 4 3) (1 4 2 3) (1 4 3 2) (1 3 4 2) (1 3 2 4)
648 (2 3 1 4) (2 3 4 1) (2 4 3 1) (2 4 1 3) (2 1 4 3) (2 1 3 4)
649 (3 1 2 4) (3 1 4 2) (3 4 1 2) (3 4 2 1) (3 2 4 1) (3 2 1 4)
650 (4 2 1 3) (4 2 3 1) (4 3 2 1) (4 3 1 2) (4 1 3 2) (4 1 2 3)))
653 (mapfam nil '(1 2 3 4) :mode 'perm :arity 1)
656 (mapfam nil '(1 2 3 4) :mode 'perm :arity 2)
657 '((1 2) (2 1) (1 3) (3 1) (1 4) (4 1)
658 (2 3) (3 2) (2 4) (4 2)
661 (mapfam nil '(1 2 3 4) :mode 'perm :arity 3)
662 ;; we've checked S_3 perms already, so just use them
664 (mapfam nil '(1 2 3) :mode 'perm)
665 (mapfam nil '(1 2 4) :mode 'perm)
666 (mapfam nil '(1 3 4) :mode 'perm)
667 (mapfam nil '(2 3 4) :mode 'perm)))
669 (mapfam nil '(1 2 3 4) :mode 'perm :arity 4)
670 '((1 2 3 4) (1 2 4 3) (1 4 2 3) (1 4 3 2) (1 3 4 2) (1 3 2 4)
671 (2 3 1 4) (2 3 4 1) (2 4 3 1) (2 4 1 3) (2 1 4 3) (2 1 3 4)
672 (3 1 2 4) (3 1 4 2) (3 4 1 2) (3 4 2 1) (3 2 4 1) (3 2 1 4)
673 (4 2 1 3) (4 2 3 1) (4 3 2 1) (4 3 1 2) (4 1 3 2) (4 1 2 3)))
675 (null (mapfam nil '(1 2 3 4) :mode 'perm :arity 5)))
678 (mapfam nil [0 1] :mode 'perm)
679 (mapfam nil (dllist 0 1) :mode 'perm))
682 (mapfam nil (dllist 0 1) :mode 'perm :arity 1)
683 (mapfam nil [0 1] :mode 'perm :arity 1)))
685 (mapfam nil [0 1] :mode 'perm :arity 2)
686 (mapfam nil (dllist 0 1) :mode 'perm :arity 2))
688 (null (mapfam nil [0 1] :mode 'perm :arity 3)))
690 (null (mapfam nil (dllist 0 1) :mode 'perm :arity 3)))
693 (mapfam nil [0 1 2] :mode 'perm)
694 (mapfam nil (dllist 0 1 2) :mode 'perm))
697 (mapfam nil [0 1 2] :mode 'perm :arity 1)
698 (mapfam nil (dllist 0 1 2) :mode 'perm :arity 1)))
700 (mapfam nil (dllist 0 1 2) :mode 'perm :arity 2)
701 (mapfam nil [0 1 2] :mode 'perm :arity 2))
703 (mapfam nil [0 1 2] :mode 'perm :arity 3)
704 (mapfam nil (dllist 0 1 2) :mode 'perm :arity 3))
706 (null (mapfam nil [0 1 2] :mode 'perm :arity 4)))
708 (null (mapfam nil (dllist 0 1 2) :mode 'perm :arity 4)))
711 (mapfam nil [1 2 3 4] :mode 'perm)
712 (mapfam nil (dllist 1 2 3 4) :mode 'perm))
715 (mapfam nil [1 2 3 4] :mode 'perm :arity 1)
716 (mapfam nil (dllist 1 2 3 4) :mode 'perm :arity 1)))
718 (mapfam nil [1 2 3 4] :mode 'perm :arity 2)
719 (mapfam nil (dllist 1 2 3 4) :mode 'perm :arity 2))
721 (mapfam nil [1 2 3 4] :mode 'perm :arity 3)
722 (mapfam nil (dllist 1 2 3 4) :mode 'perm :arity 3))
724 (mapfam nil (dllist 1 2 3 4) :mode 'perm :arity 4)
725 (mapfam nil [1 2 3 4] :mode 'perm :arity 4))
727 (null (mapfam nil [1 2 3 4] :mode 'perm :arity 5)))
729 (null (mapfam nil (dllist 1 2 3 4) :mode 'perm :arity 5)))
731 ;;; just some things that caused problems in the past
733 (mapfam nil :glue #'string :mode 'perm "ab")
736 (mapfam #'sxhash :glue #'string :mode 'perm "ab")
737 (list (sxhash "ab") (sxhash "ba")))
739 (mapfam #'string :mode 'perm "ab")
743 (mapfam nil :glue #'string :mode 'perm "abc")
744 '("abc" "acb" "cab" "cba" "bca" "bac"))
746 (mapfam #'sxhash :glue #'string :mode 'perm "abc")
747 (list (sxhash "abc") (sxhash "acb") (sxhash "cab")
748 (sxhash "cba") (sxhash "bca") (sxhash "bac")))
750 (mapfam #'string :mode 'perm "abc")
751 '("abc" "acb" "cab" "cba" "bca" "bac"))
754 (mapfam nil :glue #'string :mode 'perm "abcd")
755 '("abcd" "abdc" "adbc" "adcb" "acdb" "acbd"
756 "cabd" "cadb" "cdab" "cdba" "cbda" "cbad"
757 "bcad" "bcda" "bdca" "bdac" "badc" "bacd"
758 "dbac" "dbca" "dcba" "dcab" "dacb" "dabc"))
760 (mapfam #'sxhash :glue #'string :mode 'perm "abcd")
761 (list (sxhash "abcd") (sxhash "abdc") (sxhash "adbc")
762 (sxhash "adcb") (sxhash "acdb") (sxhash "acbd")
763 (sxhash "cabd") (sxhash "cadb") (sxhash "cdab")
764 (sxhash "cdba") (sxhash "cbda") (sxhash "cbad")
765 (sxhash "bcad") (sxhash "bcda") (sxhash "bdca")
766 (sxhash "bdac") (sxhash "badc") (sxhash "bacd")
767 (sxhash "dbac") (sxhash "dbca") (sxhash "dcba")
768 (sxhash "dcab") (sxhash "dacb") (sxhash "dabc")))
770 (mapfam #'string :mode 'perm "abcd")
771 '("abcd" "abdc" "adbc" "adcb" "acdb" "acbd"
772 "cabd" "cadb" "cdab" "cdba" "cbda" "cbad"
773 "bcad" "bcda" "bdca" "bdac" "badc" "bacd"
774 "dbac" "dbca" "dcba" "dcab" "dacb" "dabc"))
776 (mapfam nil :glue #'string :mode 'perm "abcde" :arity 4)
777 (mapfam #'sxhash :glue #'string :mode 'perm "abcde" :arity 4)
778 (mapfam #'string :mode 'perm "abcde" :arity 4)
781 ;; now with real funs aboard
784 (mapfam #'1- [1 2 3 4 5 6])
788 (mapfam #'1+ :mode 'pntw [1 2 3 4 5 6])
791 (let* ((l ''(1 2 3 4 5 6))
793 (d (dllist 1 2 3 4 5 6))
794 ;; a sequence of coprime length
795 (l2 ''(1 2 3 4 5 6 7))
797 (d2 (dllist 1 2 3 4 5 6 7))
799 (rl '(list . '(3 7 11)))
800 (rv '(vector . [3 7 11]))
801 (rd '(dllist . (dllist 3 7 11)))
803 (rl2 '(list . '(6 15)))
804 (rv2 '(vector . [6 15]))
805 (rd2 '(dllist . (dllist 6 15))))
806 (loop for i in (list l v d) do
807 (loop for j in (list rl rv rd) do
811 (mapfam #'+ ,i :arity 2 :result-type #',(car j))
813 ;; seq length coprime to arity
814 (loop for i in (list l2 v2 d2) do
815 (loop for j in (list rl rv rd) do
819 (mapfam #'+ ,i :arity 2 :result-type #',(car j))
822 (loop for i in (list l v d) do
823 (loop for j in (list rl2 rv2 rd2) do
827 (mapfam #'+ ,i :arity 3 :result-type #',(car j))
829 ;; seq length coprime to arity
830 (loop for i in (list l2 v2 d2) do
831 (loop for j in (list rl2 rv2 rd2) do
835 (mapfam #'+ ,i :arity 3 :result-type #',(car j))
840 (mapfam #'+ [1 2 3 4 5 6 7 8] :arity 4)
844 (mapfam #'+ [1 2 3 4 5 6 7 8] :arity 4 :result-type #'vector)
848 (mapfam #'+ [1 2 3 4 5 6 7 8] :arity 4 :result-type #'dllist)
853 (mapfam #'+ [1 2 3 4 5 6 7 8 9 10 11] :arity 4)
857 (mapfam #'+ '(1 2 3 4 5 6 7 8 9 10 11) :arity 4 :result-type #'vector)
861 (mapfam #'+ (dllist 1 2 3 4 5 6 7 8 9 10 11) :arity 4 :result-type #'dllist)
864 ;; wreck the sequence during traversal
865 ;; (setq foo (dllist 1 2 3 4 5 6 7 8))
866 ;; (defun wreck-1 (a)
867 ;; (dllist-pop-car foo)
871 ;; (mapfam #'wreck-1 foo)
872 ;; '(2 3 4 5 6 7 8 9)))
873 ;; (Assert (= (dllist-size foo) 0))
875 ;; ;; wreck the sequence during traversal, arity 2
876 ;; (setq foo (dllist 1 2 3 4 5 6 7 8))
877 ;; (defun wreck-2 (a b)
878 ;; (dllist-pop-rac foo)
882 ;; (mapfam #'wreck-2 foo :arity 2)
884 ;; ;; foo was called 4 times, so should be (dllist 1 2 3 4) now
887 ;; (mapfam #'wreck-2 foo :arity 2)
889 ;; ;; foo was called twice, so should be (dllist 1 2) now
892 ;; (mapfam #'wreck-2 foo :arity 2)
894 ;; foo was called once, so should be (dllist 1) now,
895 ;; however just one element is below the requested arity, so
898 ;; (null (mapfam #'wreck-2 foo :arity 2)))
899 ;; ;; foo should still have this one element
900 ;; (Assert (= (dllist-size foo) 1))
902 ;; ;; wreck the sequence during traversal, arity 3
903 ;; (setq foo (dllist 1 2 3 4 5 6 7 8))
904 ;; (defun wreck-3 (a b c)
905 ;; (dllist-pop-rac foo)
909 ;; (mapfam #'wreck-3 foo :arity 3)
911 ;; ;; foo was called 2 times, so should be (dllist 1 2 3 4 5 6) now
914 ;; (mapfam #'wreck-3 foo :arity 3)
916 ;; ;; foo was called twice, so should be (dllist 1 2 3 4) now
919 ;; (mapfam #'wreck-3 foo :arity 3)
921 ;; ;; foo was called once, so should be (dllist 1 2 3) now,
924 ;; (mapfam #'wreck-3 foo :arity 3)
926 ;; ;; again, foo was called once, so should be (dllist 1 2) now,
927 ;; ;; however that's less elements than arity so we expect nil now
929 ;; (null (mapfam #'wreck-3 foo :arity 3)))
930 ;; ;; foo should still have these two elements
931 ;; (Assert (= (dllist-size foo) 2))
932 ;; (Assert (equal foo (dllist 1 2)))
935 (setq test-ht (make-hash-table)
936 test-sl (make-skiplist))
938 (puthash '1 'a test-ht)
939 (puthash '2 'b test-ht)
940 (puthash '3 'c test-ht)
941 (puthash '4 'd test-ht)
942 (puthash '5 'e test-ht)
943 (puthash '6 'f test-ht)
944 (puthash '7 'g test-ht)
946 (put-skiplist test-sl '1 'a)
947 (put-skiplist test-sl '2 'b)
948 (put-skiplist test-sl '3 'c)
949 (put-skiplist test-sl '4 'd)
950 (put-skiplist test-sl '5 'e)
951 (put-skiplist test-sl '6 'f)
952 (put-skiplist test-sl '7 'g)
954 ;; initialise a summing variable
957 (defun sum-2 (key val)
958 (setq sum (+ sum key)))
959 ;; we can't use the output of this one for it is uncertain in which
960 ;; order the keys are passed
961 (mapfam #'sum-2 test-ht)
962 ;; however, sum should be 28 (= 7 + 3 + 6 + 4 + 5 + 2 + 1) now
967 ;; skiplists always iterate in hash-order and hashes of ints are
968 ;; order preserving, so we are able to check the outcome
971 (setq bar (mapfam #'sum-2 test-sl))
972 '(1 3 6 10 15 21 28)))
976 ;;; testing on 2 sequences
979 (mapfam nil '(a b c) '(1 2 3))
980 '((a 1) (b 2) (c 3))))
983 (mapfam nil '(a b c) '(1 2 3 4))
984 ;; the 4 doesnt count since another sequence has finished traversal by then
985 '((a 1) (b 2) (c 3))))
986 ;; the same with list and vector
989 (mapfam nil '(a b c) [1 2 3])
990 '((a 1) (b 2) (c 3))))
993 (mapfam nil [a b c] '(1 2 3 4))
994 ;; the 4 doesnt count since another sequence has finished traversal by then
995 '((a 1) (b 2) (c 3))))
999 (mapfam nil '(a b c) (dllist 1 2 3))
1000 '((a 1) (b 2) (c 3))))
1003 (mapfam nil (dllist 'a 'b 'c) '(1 2 3 4))
1004 ;; the 4 doesnt count since another sequence has finished traversal by then
1005 '((a 1) (b 2) (c 3))))
1006 ;; dllist and vector
1009 (mapfam nil (dllist 'a 'b 'c) [1 2 3])
1010 '((a 1) (b 2) (c 3))))
1013 (mapfam nil [a b c] (dllist 1 2 3 4))
1014 ;; the 4 doesnt count since another sequence has finished traversal by then
1015 '((a 1) (b 2) (c 3))))
1016 ;; string and vector
1019 (mapfam nil "abc" [1 2 3])
1020 '((?a 1) (?b 2) (?c 3))))
1023 (mapfam nil [a b c] "1234")
1024 ;; the 4 doesnt count since another sequence has finished traversal by then
1025 '((a ?1) (b ?2) (c ?3))))
1026 ;; more than 2 sequences
1029 (mapfam nil '(a b c) [1 2 3] (dllist ?x ?y ?z))
1030 '((a 1 ?x) (b 2 ?y) (c 3 ?z))))
1033 (mapfam nil '(a b c) [1 2 3 4] (dllist ?x ?y ?z))
1034 '((a 1 ?x) (b 2 ?y) (c 3 ?z))))
1036 ;; all of the above using a different glue
1039 (mapfam nil :glue #'vector '(a b c) '(1 2 3))
1040 '([a 1] [b 2] [c 3])))
1043 (mapfam nil :glue #'vector '(a b c) '(1 2 3 4))
1044 ;; the 4 doesnt count since another sequence has finished traversal by then
1045 '([a 1] [b 2] [c 3])))
1046 ;; the same with list and vector
1049 (mapfam nil :glue #'vector '(a b c) [1 2 3])
1050 '([a 1] [b 2] [c 3])))
1053 (mapfam nil :glue #'vector [a b c] '(1 2 3 4))
1054 ;; the 4 doesnt count since another sequence has finished traversal by then
1055 '([a 1] [b 2] [c 3])))
1059 (mapfam nil :glue #'vector '(a b c) (dllist 1 2 3))
1060 '([a 1] [b 2] [c 3])))
1063 (mapfam nil :glue #'vector (dllist 'a 'b 'c) '(1 2 3 4))
1064 ;; the 4 doesnt count since another sequence has finished traversal by then
1065 '([a 1] [b 2] [c 3])))
1066 ;; dllist and vector
1069 (mapfam nil :glue #'vector (dllist 'a 'b 'c) [1 2 3])
1070 '([a 1] [b 2] [c 3])))
1073 (mapfam nil :glue #'vector [a b c] (dllist 1 2 3 4))
1074 ;; the 4 doesnt count since another sequence has finished traversal by then
1075 '([a 1] [b 2] [c 3])))
1076 ;; string and vector
1079 (mapfam nil :glue #'vector "abc" [1 2 3])
1080 '([?a 1] [?b 2] [?c 3])))
1083 (mapfam nil :glue #'vector [a b c] "1234")
1084 ;; the 4 doesnt count since another sequence has finished traversal by then
1085 '([a ?1] [b ?2] [c ?3])))
1086 ;; more than 2 sequences
1089 (mapfam nil :glue #'vector '(a b c) [1 2 3] (dllist ?x ?y ?z))
1090 '([a 1 ?x] [b 2 ?y] [c 3 ?z])))
1093 (mapfam nil :glue #'vector '(a b c) [1 2 3 4] (dllist ?x ?y ?z))
1094 '([a 1 ?x] [b 2 ?y] [c 3 ?z])))
1097 ;;; combinations with more than 1 family
1098 (Assert-set-equality
1099 (mapfam nil :mode 'comb [a b c] "1234")
1100 ;; the 4 doesnt count since another sequence has finished traversal by then
1101 '((a ?1) (a ?2) (a ?3) (a ?4)
1102 (b ?1) (b ?2) (b ?3) (b ?4)
1103 (c ?1) (c ?2) (c ?3) (c ?4)))
1105 (Assert-set-equality
1106 (mapfam nil :glue #'vector :mode 'comb [a b c] "1234")
1107 ;; the 4 doesnt count since another sequence has finished traversal by then
1108 '([a ?1] [a ?2] [a ?3] [a ?4]
1109 [b ?1] [b ?2] [b ?3] [b ?4]
1110 [c ?1] [c ?2] [c ?3] [c ?4]))
1112 (Assert-set-equality
1113 (mapfam #'cons :mode 'comb [a b c] "1234")
1114 ;; the 4 doesnt count since another sequence has finished traversal by then
1115 '((a . ?1) (a . ?2) (a . ?3) (a . ?4)
1116 (b . ?1) (b . ?2) (b . ?3) (b . ?4)
1117 (c . ?1) (c . ?2) (c . ?3) (c . ?4)))
1119 ;;; cartesians with more than 1 family
1120 (Assert-set-equality
1121 (mapfam nil :mode 'cart [a b c] "1234")
1122 ;; the 4 doesnt count since another sequence has finished traversal by then
1123 '((a ?1) (a ?2) (a ?3) (a ?4)
1124 (b ?1) (b ?2) (b ?3) (b ?4)
1125 (c ?1) (c ?2) (c ?3) (c ?4)))
1127 (Assert-set-equality
1128 (mapfam nil :glue #'vector :mode 'cart [a b c] "1234")
1129 ;; the 4 doesnt count since another sequence has finished traversal by then
1130 '([a ?1] [a ?2] [a ?3] [a ?4]
1131 [b ?1] [b ?2] [b ?3] [b ?4]
1132 [c ?1] [c ?2] [c ?3] [c ?4]))
1134 (Assert-set-equality
1135 (mapfam #'cons :mode 'cart [a b c] "1234")
1136 ;; the 4 doesnt count since another sequence has finished traversal by then
1137 '((a . ?1) (a . ?2) (a . ?3) (a . ?4)
1138 (b . ?1) (b . ?2) (b . ?3) (b . ?4)
1139 (c . ?1) (c . ?2) (c . ?3) (c . ?4)))
1141 (Assert-set-equality
1142 (mapfam nil :mode 'cart [?a ?b] "12" (dllist ?X))
1143 '((?a ?1 ?X) (?a ?2 ?X) (?b ?1 ?X) (?b ?2 ?X)))
1145 (Assert-set-equality
1146 (mapfam nil :glue #'vector :mode 'cart [?a ?b] "12" (dllist ?X))
1147 '([?a ?1 ?X] [?a ?2 ?X] [?b ?1 ?X] [?b ?2 ?X]))
1149 (Assert-set-equality
1150 (mapfam #'concat :glue #'vector :mode 'cart [?a ?b] "12" (dllist ?X))
1151 '("a1X" "a2X" "b1X" "b2X"))
1153 (Assert-set-equality
1154 (mapfam #'string :mode 'cart [?a ?b] "12" (dllist ?X))
1155 '("a1X" "a2X" "b1X" "b2X"))
1157 ;;; perms with more than 1 family
1158 (Assert-set-equality
1159 (mapfam nil :mode 'perm [?a ?b] "12")
1165 (Assert-set-equality
1166 (mapfam nil :mode 'perm [?a ?b] "12" (dllist ?X))
1167 '((?a ?1 ?X) (?a ?X ?1) (?X ?a ?1) (?X ?1 ?a) (?1 ?X ?a) (?1 ?a ?X)
1168 (?a ?2 ?X) (?a ?X ?2) (?X ?a ?2) (?X ?2 ?a) (?2 ?X ?a) (?2 ?a ?X)
1169 (?b ?1 ?X) (?b ?X ?1) (?X ?b ?1) (?X ?1 ?b) (?1 ?X ?b) (?1 ?b ?X)
1170 (?b ?2 ?X) (?b ?X ?2) (?X ?b ?2) (?X ?2 ?b) (?2 ?X ?b) (?2 ?b ?X)))
1172 (Assert-set-equality
1173 (mapfam #'string :mode 'perm [?a ?b] "12" (dllist ?X))
1174 '("a1X" "aX1" "Xa1" "X1a" "1Xa" "1aX"
1175 "a2X" "aX2" "Xa2" "X2a" "2Xa" "2aX"
1176 "b1X" "bX1" "Xb1" "X1b" "1Xb" "1bX"
1177 "b2X" "bX2" "Xb2" "X2b" "2Xb" "2bX"))
1179 (Assert-set-equality
1180 (mapfam #'string :mode 'perm [?a ?b] "12" (dllist ?X) [?A])
1181 '("a1XA" "a1AX" "aA1X" "aAX1" "aXA1" "aX1A"
1182 "1aXA" "1aAX" "1AaX" "1AXa" "1XAa" "1XaA"
1183 "X1aA" "X1Aa" "XA1a" "XAa1" "XaA1" "Xa1A"
1184 "A1Xa" "A1aX" "Aa1X" "AaX1" "AXa1" "AX1a"
1186 "a2XA" "2aXA" "2XaA" "X2aA" "Xa2A" "aX2A"
1187 "aXA2" "XaA2" "XAa2" "AXa2" "AaX2" "aAX2"
1188 "2AXa" "A2Xa" "AX2a" "XA2a" "X2Aa" "2XAa"
1189 "2aAX" "a2AX" "aA2X" "Aa2X" "A2aX" "2AaX"
1191 "b1XA" "1bXA" "1XbA" "X1bA" "Xb1A" "bX1A"
1192 "bXA1" "XbA1" "XAb1" "AXb1" "AbX1" "bAX1"
1193 "1AXb" "A1Xb" "AX1b" "XA1b" "X1Ab" "1XAb"
1194 "1bAX" "b1AX" "bA1X" "Ab1X" "A1bX" "1AbX"
1196 "b2XA" "2bXA" "2XbA" "X2bA" "Xb2A" "bX2A"
1197 "bXA2" "XbA2" "XAb2" "AXb2" "AbX2" "bAX2"
1198 "2AXb" "A2Xb" "AX2b" "XA2b" "X2Ab" "2XAb"
1199 "2bAX" "b2AX" "bA2X" "Ab2X" "A2bX" "2AbX"))
1202 ;;; testing over multiple sequences with strange arities
1203 (Assert-set-equality
1204 (mapfam nil :glue #'string "abcd" "1234" :arity 1)
1207 (Assert-set-equality
1208 (mapfam nil :glue #'string "abcd" "1234" :arity '(1))
1211 (Assert-set-equality
1212 (mapfam nil :glue #'string "abcd" "1234" :arity '(2))
1215 (Assert-set-equality
1216 (mapfam nil :glue #'string "abcd" "1234" :arity '(1 1))
1217 '("a1" "b2" "c3" "d4"))
1219 ;; (Assert-set-equality
1220 ;; (mapfam nil :glue #'string "abcd" "1234" "another" :arity '(1 1))
1221 ;; '("a1" "b2" "c3" "d4"))
1223 (Assert-set-equality
1224 (mapfam nil :glue #'string "abcd" "1234" :arity '(1 1 1))
1225 '("a1" "b2" "c3" "d4"))
1227 (Assert-set-equality
1228 (mapfam nil :glue #'string "abcd" "1234" :arity '(1 1 2))
1229 '("a1" "b2" "c3" "d4"))
1231 (Assert-set-equality
1232 (mapfam nil :glue #'string "abcd" "1234" :arity '(1 2))
1235 (Assert-set-equality
1236 (mapfam nil :glue #'string "abcd" "1234" :arity '(2 1))
1239 (Assert-set-equality
1240 (mapfam nil :glue #'string "abcd" "1234" :arity '(2 1 1))
1243 (Assert-set-equality
1244 (mapfam nil :glue #'string "abcd" "1234" :arity '(2 2))
1247 (Assert-set-equality
1248 (mapfam nil :glue #'string "abcd" "1234" :arity '(3 1))
1251 (Assert-set-equality
1252 (mapfam nil :glue #'string "abcd" "1234" :arity '(1 3))
1255 (Assert-set-equality
1256 (mapfam nil :glue #'string "abcd" "1234" :arity '(3 2))
1259 (Assert-set-equality
1260 (mapfam nil :glue #'string "abcd" "1234" :arity '(2 3))
1263 (Assert-set-equality
1264 (mapfam nil :glue #'string "abcd" "1234" :arity '(3 3))
1267 (Assert-set-equality
1268 (mapfam nil :glue #'string "abcd" "1234" :arity '(4 1))
1271 (Assert-set-equality
1272 (mapfam nil :glue #'string "abcd" "1234" :arity '(1 4))
1275 (Assert-set-equality
1276 (mapfam nil :glue #'string "abcd" "1234" :arity '(4 2))
1279 (Assert-set-equality
1280 (mapfam nil :glue #'string "abcd" "1234" :arity '(2 4))
1283 (Assert-set-equality
1284 (mapfam nil :glue #'string "abcd" "1234" :arity '(4 3))
1287 (Assert-set-equality
1288 (mapfam nil :glue #'string "abcd" "1234" :arity '(3 4))
1291 (Assert-set-equality
1292 (mapfam nil :glue #'string "abcd" "1234" :arity '(4 4))
1297 (mapfam nil :glue #'string "abcd" "1234" :arity '(5 1))))
1301 (mapfam nil :glue #'string "abcd" "1234" :arity '(1 5))))
1305 (mapfam nil :glue #'string "abcd" "1234" :arity '(5 5))))
1308 (Assert-set-equality
1309 (mapfam nil :mode 'cart :glue #'string "abc" "123" :arity '(2 1))
1310 '("aa1" "aa2" "aa3" "ab1" "ab2" "ab3" "ac1" "ac2" "ac3"
1311 "ba1" "ba2" "ba3" "bb1" "bb2" "bb3" "bc1" "bc2" "bc3"
1312 "ca1" "ca2" "ca3" "cb1" "cb2" "cb3" "cc1" "cc2" "cc3"))
1313 (Assert-set-equality
1314 (mapfam nil :mode 'cart :glue #'string "abc" "123" :arity '(2 2))
1315 '("aa11" "aa12" "aa13" "aa21" "aa22" "aa23" "aa31" "aa32" "aa33"
1316 "ab11" "ab12" "ab13" "ab21" "ab22" "ab23" "ab31" "ab32" "ab33"
1317 "ac11" "ac12" "ac13" "ac21" "ac22" "ac23" "ac31" "ac32" "ac33"
1319 "ba11" "ba12" "ba13" "ba21" "ba22" "ba23" "ba31" "ba32" "ba33"
1320 "bb11" "bb12" "bb13" "bb21" "bb22" "bb23" "bb31" "bb32" "bb33"
1321 "bc11" "bc12" "bc13" "bc21" "bc22" "bc23" "bc31" "bc32" "bc33"
1323 "ca11" "ca12" "ca13" "ca21" "ca22" "ca23" "ca31" "ca32" "ca33"
1324 "cb11" "cb12" "cb13" "cb21" "cb22" "cb23" "cb31" "cb32" "cb33"
1325 "cc11" "cc12" "cc13" "cc21" "cc22" "cc23" "cc31" "cc32" "cc33"))
1328 (Assert-set-equality
1329 (mapfam nil :mode 'comb :glue #'string "abcd" "123" :arity '(2 2))
1330 '("ab12" "ab13" "ab23" "ac12" "ac13" "ac23" "ad12" "ad13" "ad23"
1331 "bc12" "bc13" "bc23" "bd12" "bd13" "bd23"
1332 "cd12" "cd13" "cd23"))
1334 (Assert-set-equality
1335 (mapfam nil :mode 'comb :glue #'string "abcd" "123" :arity '(2 1))
1336 '("ab1" "ab2" "ab3" "ac1" "ac2" "ac3" "ad1" "ad2" "ad3"
1337 "bc1" "bc2" "bc3" "bd1" "bd2" "bd3"
1340 (Assert-set-equality
1341 (mapfam nil :mode 'comb :glue #'string "abcd" "1234" :arity '(2 3))
1342 '("ab123" "ab124" "ab134" "ab234"
1343 "ac123" "ac124" "ac134" "ac234"
1344 "ad123" "ad124" "ad134" "ad234"
1345 "bc123" "bc124" "bc134" "bc234"
1346 "bd123" "bd124" "bd134" "bd234"
1347 "cd123" "cd124" "cd134" "cd234"))
1350 (null (mapfam nil :mode 'comb :glue #'string "abcd" "1234" :arity '(2 5))))
1352 ;; the same but with #'string being the mapper
1353 (Assert-set-equality
1354 (mapfam #'string :mode 'comb "abcd" "123" :arity '(2 2))
1355 '("ab12" "ab13" "ab23" "ac12" "ac13" "ac23" "ad12" "ad13" "ad23"
1356 "bc12" "bc13" "bc23" "bd12" "bd13" "bd23"
1357 "cd12" "cd13" "cd23"))
1359 (Assert-set-equality
1360 (mapfam #'string :mode 'comb "abcd" "123" :arity '(2 1))
1361 '("ab1" "ab2" "ab3" "ac1" "ac2" "ac3" "ad1" "ad2" "ad3"
1362 "bc1" "bc2" "bc3" "bd1" "bd2" "bd3"
1365 (Assert-set-equality
1366 (mapfam #'string :mode 'comb "abcd" "1234" :arity '(2 3))
1367 '("ab123" "ab124" "ab134" "ab234"
1368 "ac123" "ac124" "ac134" "ac234"
1369 "ad123" "ad124" "ad134" "ad234"
1370 "bc123" "bc124" "bc134" "bc234"
1371 "bd123" "bd124" "bd134" "bd234"
1372 "cd123" "cd124" "cd134" "cd234"))
1375 (null (mapfam #'string :mode 'comb "abcd" "1234" :arity '(2 5))))
1377 ;; the same but with #'concat being the mapper and #'string being glue
1378 (Assert-set-equality
1379 (mapfam #'concat :mode 'comb :glue #'string "abcd" "123" :arity '(2 2))
1380 '("ab12" "ab13" "ab23" "ac12" "ac13" "ac23" "ad12" "ad13" "ad23"
1381 "bc12" "bc13" "bc23" "bd12" "bd13" "bd23"
1382 "cd12" "cd13" "cd23"))
1384 (Assert-set-equality
1385 (mapfam #'concat :mode 'comb :glue #'string "abcd" "123" :arity '(2 1))
1386 '("ab1" "ab2" "ab3" "ac1" "ac2" "ac3" "ad1" "ad2" "ad3"
1387 "bc1" "bc2" "bc3" "bd1" "bd2" "bd3"
1390 (Assert-set-equality
1391 (mapfam #'concat :mode 'comb :glue #'string "abcd" "1234" :arity '(2 3))
1392 '("ab123" "ab124" "ab134" "ab234"
1393 "ac123" "ac124" "ac134" "ac234"
1394 "ad123" "ad124" "ad134" "ad234"
1395 "bc123" "bc124" "bc134" "bc234"
1396 "bd123" "bd124" "bd134" "bd234"
1397 "cd123" "cd124" "cd134" "cd234"))
1400 (null (mapfam #'concat :mode 'comb :glue #'string "abcd" "1234" :arity '(2 5))))
1403 (Assert-set-equality
1404 (mapfam nil :mode 'perm :glue #'string "abcd" "123" :arity '(2 2))
1406 (mapfam nil :mode 'perm :glue #'string "ab12")
1407 (mapfam nil :mode 'perm :glue #'string "ab13")
1408 (mapfam nil :mode 'perm :glue #'string "ab23")
1409 (mapfam nil :mode 'perm :glue #'string "ac12")
1410 (mapfam nil :mode 'perm :glue #'string "ac13")
1411 (mapfam nil :mode 'perm :glue #'string "ac23")
1412 (mapfam nil :mode 'perm :glue #'string "ad12")
1413 (mapfam nil :mode 'perm :glue #'string "ad13")
1414 (mapfam nil :mode 'perm :glue #'string "ad23")
1415 (mapfam nil :mode 'perm :glue #'string "bc12")
1416 (mapfam nil :mode 'perm :glue #'string "bc13")
1417 (mapfam nil :mode 'perm :glue #'string "bc23")
1418 (mapfam nil :mode 'perm :glue #'string "bd12")
1419 (mapfam nil :mode 'perm :glue #'string "bd13")
1420 (mapfam nil :mode 'perm :glue #'string "bd23")
1421 (mapfam nil :mode 'perm :glue #'string "cd12")
1422 (mapfam nil :mode 'perm :glue #'string "cd13")
1423 (mapfam nil :mode 'perm :glue #'string "cd23")))
1425 (Assert-set-equality
1426 (mapfam nil :mode 'perm :glue #'string "abcd" "123" :arity '(1 1))
1427 '("a1" "1a" "a2" "2a" "a3" "3a" "b1" "1b" "b2" "2b" "b3" "3b"
1428 "c1" "1c" "c2" "2c" "c3" "3c" "d1" "1d" "d2" "2d" "d3" "3d"))
1430 ;;; test Steve's favourite
1432 ;; (mapconcat #'concat (split-string "unsplit this split string") " ")
1433 ;; => "unsplit this split string"
1435 ;; Now with #'mapfam...
1437 ;; First, with the exact same syntax as we did with #'mapconcat (because it is
1438 ;; our plan to replace all of our #'map* functions with aliases to #'mapfam)
1440 ;; (mapfam #'concat (split-string "unsplit this split string") " ")
1441 ;; => Wrong type argument: sequencep, ?\ <- it's a space character
1443 ;; hrop: Yes, that's exactly what happens! Let's make a test ...
1445 (Check-Error wrong-type-argument
1446 (mapfam #'concat (split-string "unsplit this split string") " "))
1448 ;; ... why that you ask?
1449 ;; By design #'mapfam operates like CL's #'map, i.e. takes any number of
1450 ;; sequences as input. Because of this there is no way to tell whether you
1451 ;; actually meant the third arg of the above mapfam call to act as separator
1452 ;; or as a sequence (a string is a sequence too), well, it is simply assumed
1453 ;; that you mean the sequence which is why the above call throws the
1454 ;; wrong-type-argument error.
1456 ;; Now lets try to wing it with more fancy syntax...
1458 ;; (mapfam nil :separator " " :result-type #'concat
1459 ;; (split-string "unsplit this split string"))
1460 ;; => "unsplitthissplitstring"
1462 ;; hrop: That's a bug ... here's the test
1465 (string= (mapfam nil :separator " " :result-type #'concat
1466 (split-string "unsplit this split string"))
1467 "unsplit this split string"))
1469 ;; here's the proof that it really inserts the separator element
1471 (equal (mapfam nil :separator " " :result-type #'list
1472 (split-string "unsplit this split string"))
1473 '("unsplit" " " "this" " " "split" " " "string")))
1475 ;; (mapfam #'concat :result-type #'concat
1476 ;; (split-string "unsplit this split string") " ")
1477 ;; => Wrong type argument: sequencep, ?\
1479 ;; hrop: um, I can't see what that is supposed to do, but yes, the wrong-type
1480 ;; error is because of the second sequence (" ") which is kinda like [?\ ]
1481 ;; let's do some fancy tests insteads
1485 (mapfam nil :initiator "!" :separator " " :terminator "?"
1486 :result-type #'concat ["uuuuh" "yeeeeah"])
1489 ;; here to prove that the separator can be anything really
1492 (mapfam nil :initiator ?! :separator (cons 'foo 'bar) :terminator ??
1493 :result-type #'vector ["does" "this" "work"])
1494 [?! "does" (foo . bar) "this" (foo . bar) "work" ?\?]))
1496 ;; and it is the same element actually ... which is an undocumented feature :)
1499 (mapfam nil :separator (cons 'foo 'bar) :result-type #'vector
1501 (setcar (aref bar 1) 'bar)
1502 (Assert (eq (car (aref bar 3)) 'bar))
1504 ;; Oh, here's a way...
1505 ;; (mapfam #'concat :result-type #'concat
1506 ;; (split-string "unsplit this split string") '(" " " " " " ""))
1507 ;; => "unsplit this split string"
1509 ;; hrop: yipp :) that works of course ...
1513 ;; (mapfam #'concat :result-type #'concat
1514 ;; (split-string "unsplit this split string") '(" " " " " " ""))
1515 ;; "unsplit this split string"))
1517 ;; (when-fboundp #'divisiblep
1518 ;; (Assert-set-equality
1519 ;; (let ((divisors))
1520 ;; (mapfam :result-type 'void
1522 ;; (garbage-collect)
1523 ;; (if (divisiblep 5041 p) (push p divisors))
1524 ;; (garbage-collect))
1525 ;; '(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
1526 ;; 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
1527 ;; 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
1528 ;; 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 69 70
1529 ;; 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
1530 ;; 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
1531 ;; 104 105 106 107 108 109 110 111 112 113 114 115 116
1532 ;; 117 118 119 120 121 122 123 124 125 126 127 128 129
1533 ;; 130 131 132 133 134 135 136 137 138 139 140 141 142
1534 ;; 143 144 145 146 147 148 149 150 151 152 153 154 155
1535 ;; 156 157 158 159 160 161 162 163 164 165 166 167 168
1536 ;; 169 170 171 172 173 174 175 176 177 178 179 180 181
1537 ;; 182 183 184 185 186 187 188 189 190 191 192 193 194
1538 ;; 195 196 197 198 199 200 201 202 203 204 205 206 207
1539 ;; 208 209 210 211 212 213 214 215 216 217 218 219 220
1540 ;; 221 222 223 224 225 226 227 228 229 230 231 232 233
1541 ;; 234 235 236 237 238 239 240 241 242 243 244 245 246
1542 ;; 247 248 249 250 251 252 253 254 255 256 257 258 259
1543 ;; 260 261 262 263 264 265 266 267 268 269 270 271 272
1544 ;; 273 274 275 276 277 278 279 280 281 282 283 284 285
1549 ;; (Assert-set-equality
1550 ;; (let ((divisors))
1551 ;; (mapfam #'(lambda (p)
1552 ;; (garbage-collect)
1553 ;; (if (divisiblep 5041 p) (push p divisors))
1554 ;; (garbage-collect))
1555 ;; '(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
1556 ;; 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
1557 ;; 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
1558 ;; 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 69 70
1559 ;; 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
1560 ;; 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
1561 ;; 104 105 106 107 108 109 110 111 112 113 114 115 116
1562 ;; 117 118 119 120 121 122 123 124 125 126 127 128 129
1563 ;; 130 131 132 133 134 135 136 137 138 139 140 141 142
1564 ;; 143 144 145 146 147 148 149 150 151 152 153 154 155
1565 ;; 156 157 158 159 160 161 162 163 164 165 166 167 168
1566 ;; 169 170 171 172 173 174 175 176 177 178 179 180 181
1567 ;; 182 183 184 185 186 187 188 189 190 191 192 193 194
1568 ;; 195 196 197 198 199 200 201 202 203 204 205 206 207
1569 ;; 208 209 210 211 212 213 214 215 216 217 218 219 220
1570 ;; 221 222 223 224 225 226 227 228 229 230 231 232 233
1571 ;; 234 235 236 237 238 239 240 241 242 243 244 245 246
1572 ;; 247 248 249 250 251 252 253 254 255 256 257 258 259
1573 ;; 260 261 262 263 264 265 266 267 268 269 270 271 272
1574 ;; 273 274 275 276 277 278 279 280 281 282 283 284 285
1580 (Assert (null (mapfam #'identity nil)))
1581 (Assert (null (mapfam nil nil)))
1582 (Assert (null (mapfam #'identity [])))
1583 (Assert (null (mapfam nil [])))
1584 (Assert (null (mapfam #'identity (dllist))))
1585 (Assert (null (mapfam nil (dllist))))
1586 (Assert (null (mapfam #'identity "")))
1587 (Assert (null (mapfam nil "")))
1589 (Assert (vectorp (mapfam #'identity nil :result-type #'vector)))
1590 (Assert (vectorp (mapfam nil nil :result-type #'vector)))
1591 (Assert (vectorp (mapfam #'identity [] :result-type #'vector)))
1592 (Assert (vectorp (mapfam nil [] :result-type #'vector)))
1593 (Assert (vectorp (mapfam #'identity (dllist) :result-type #'vector)))
1594 (Assert (vectorp (mapfam nil (dllist) :result-type #'vector)))
1595 (Assert (vectorp (mapfam #'identity "" :result-type #'vector)))
1596 (Assert (vectorp (mapfam nil "" :result-type #'vector)))
1598 (Assert (zerop (length (mapfam #'identity nil :result-type #'vector))))
1599 (Assert (zerop (length (mapfam nil nil :result-type #'vector))))
1600 (Assert (zerop (length (mapfam #'identity [] :result-type #'vector))))
1601 (Assert (zerop (length (mapfam nil [] :result-type #'vector))))
1602 (Assert (zerop (length (mapfam #'identity (dllist) :result-type #'vector))))
1603 (Assert (zerop (length (mapfam nil (dllist) :result-type #'vector))))
1604 (Assert (zerop (length (mapfam #'identity "" :result-type #'vector))))
1605 (Assert (zerop (length (mapfam nil "" :result-type #'vector))))
1607 ;;; map-tests.el ends here