3 (defpackage :alexandria-tests
4 (:use
:cl
:alexandria
#+sbcl
:sb-rt
#-sbcl
:rtest
)
5 (:import-from
#+sbcl
:sb-rt
#-sbcl
:rtest
6 #:*compile-tests
* #:*expected-failures
*))
8 (in-package :alexandria-tests
)
10 (defun run-tests (&key
((:compiled
*compile-tests
*)))
16 (let* ((orig (vector 1 2 3))
17 (copy (copy-array orig
)))
18 (values (eq orig copy
) (equalp orig copy
)))
22 (let ((orig (make-array 1024 :fill-pointer
0)))
23 (vector-push-extend 1 orig
)
24 (vector-push-extend 2 orig
)
25 (vector-push-extend 3 orig
)
26 (let ((copy (copy-array orig
)))
27 (values (eq orig copy
) (equalp orig copy
)
28 (array-has-fill-pointer-p copy
)
29 (eql (fill-pointer orig
) (fill-pointer copy
)))))
32 (deftest array-index
.1
33 (typep 0 'array-index
)
38 (deftest unwind-protect-case
.1
40 (unwind-protect-case ()
42 (:normal
(push :normal result
))
43 (:abort
(push :abort result
))
44 (:always
(push :always result
)))
48 (deftest unwind-protect-case
.2
50 (unwind-protect-case ()
52 (:always
(push :always result
))
53 (:normal
(push :normal result
))
54 (:abort
(push :abort result
)))
58 (deftest unwind-protect-case
.3
59 (let (result1 result2 result3
)
61 (unwind-protect-case ()
63 (:normal
(push :normal result1
))
64 (:abort
(push :abort result1
))
65 (:always
(push :always result1
))))
67 (unwind-protect-case ()
69 (:normal
(push :normal result2
))
70 (:abort
(push :abort result2
))
71 (:always
(push :always result2
))))
73 (unwind-protect-case ()
75 (:normal
(push :normal result3
))
76 (:abort
(push :abort result3
))
77 (:always
(push :always result3
))))
78 (values result1 result2 result3
))
83 (deftest unwind-protect-case
.4
85 (unwind-protect-case (aborted-p)
87 (:always
(setq result aborted-p
)))
91 (deftest unwind-protect-case
.5
94 (unwind-protect-case (aborted-p)
96 (:always
(setq result aborted-p
))))
130 (cswitch (13 :test
=)
136 (cswitch (13 :key
1-
)
141 (deftest multiple-value-prog2.1
142 (multiple-value-prog2
148 (deftest nth-value-or
.1
149 (multiple-value-bind (a b c
)
157 (let ((x (whichever 1 2 3)))
158 (and (member x
'(1 2 3)) t
))
165 (x (whichever a b c
)))
166 (and (member x
'(1 2 3)) t
))
186 (deftest define-constant
.1
187 (let ((name (gensym)))
188 (eval `(define-constant ,name
"FOO" :test
'equal
))
189 (eval `(define-constant ,name
"FOO" :test
'equal
))
190 (values (equal "FOO" (symbol-value name
))
195 (deftest define-constant
.2
196 (let ((name (gensym)))
197 (eval `(define-constant ,name
13))
198 (eval `(define-constant ,name
13))
199 (values (eql 13 (symbol-value name
))
206 ;;; TYPEP is specified to return a generalized boolean and, for
207 ;;; example, ECL exploits this by returning the superclasses of ERROR
210 (not (null (typep x
'error
))))
212 (deftest required-argument
.1
213 (multiple-value-bind (res err
)
214 (ignore-errors (required-argument))
220 (deftest ensure-hash-table
.1
221 (let ((table (make-hash-table))
223 (multiple-value-bind (value already-there
)
224 (ensure-gethash x table
42)
227 (= 42 (gethash x table
))
228 (multiple-value-bind (value2 already-there2
)
229 (ensure-gethash x table
13)
232 (= 42 (gethash x table
)))))))
235 #+clisp
(pushnew 'copy-hash-table
.1 *expected-failures
*)
237 (deftest copy-hash-table
.1
238 (let ((orig (make-hash-table :test
'eq
:size
123))
240 (setf (gethash orig orig
) t
241 (gethash foo orig
) t
)
242 (let ((eq-copy (copy-hash-table orig
))
243 (eql-copy (copy-hash-table orig
:test
'eql
))
244 (equal-copy (copy-hash-table orig
:test
'equal
))
245 ;; CLISP overflows the stack with this bit.
246 ;; See <http://sourceforge.net/tracker/index.php?func=detail&aid=2029069&group_id=1355&atid=101355>.
247 #-clisp
(equalp-copy (copy-hash-table orig
:test
'equalp
)))
248 (list (eql (hash-table-size eq-copy
) (hash-table-size orig
))
249 (eql (hash-table-rehash-size eq-copy
)
250 (hash-table-rehash-size orig
))
251 (hash-table-count eql-copy
)
252 (gethash orig eq-copy
)
253 (gethash (copy-seq foo
) eql-copy
)
254 (gethash foo eql-copy
)
255 (gethash (copy-seq foo
) equal-copy
)
256 (gethash "FOO" equal-copy
)
257 #-clisp
(gethash "FOO" equalp-copy
))))
258 (t t
2 t nil t t nil t
))
260 (deftest copy-hash-table
.2
261 (let ((ht (make-hash-table))
262 (list (list :list
(vector :A
:B
:C
))))
263 (setf (gethash 'list ht
) list
)
264 (let* ((shallow-copy (copy-hash-table ht
))
265 (deep1-copy (copy-hash-table ht
:key
'copy-list
))
266 (list (gethash 'list ht
))
267 (shallow-list (gethash 'list shallow-copy
))
268 (deep1-list (gethash 'list deep1-copy
)))
269 (list (eq ht shallow-copy
)
271 (eq list shallow-list
)
272 (eq list deep1-list
) ; outer list was copied.
273 (eq (second list
) (second shallow-list
))
274 (eq (second list
) (second deep1-list
)) ; inner vector wasn't copied.
278 (deftest maphash-keys
.1
280 (table (make-hash-table)))
281 (declare (notinline maphash-keys
))
283 (setf (gethash i table
) t
))
284 (maphash-keys (lambda (k) (push k keys
)) table
)
285 (set-equal keys
'(0 1 2 3 4 5 6 7 8 9)))
288 (deftest maphash-values
.1
290 (table (make-hash-table)))
291 (declare (notinline maphash-values
))
293 (setf (gethash i table
) (- i
)))
294 (maphash-values (lambda (v) (push v vals
)) table
)
295 (set-equal vals
'(0 -
1 -
2 -
3 -
4 -
5 -
6 -
7 -
8 -
9)))
298 (deftest hash-table-keys
.1
299 (let ((table (make-hash-table)))
301 (setf (gethash i table
) t
))
302 (set-equal (hash-table-keys table
) '(0 1 2 3 4 5 6 7 8 9)))
305 (deftest hash-table-values
.1
306 (let ((table (make-hash-table)))
308 (setf (gethash (gensym) table
) i
))
309 (set-equal (hash-table-values table
) '(0 1 2 3 4 5 6 7 8 9)))
312 (deftest hash-table-alist
.1
313 (let ((table (make-hash-table)))
315 (setf (gethash i table
) (- i
)))
316 (let ((alist (hash-table-alist table
)))
322 (10 (0 .
0) (3 . -
3) (9 . -
9) nil
))
324 (deftest hash-table-plist
.1
325 (let ((table (make-hash-table)))
327 (setf (gethash i table
) (- i
)))
328 (let ((plist (hash-table-plist table
)))
336 #+clisp
(pushnew 'alist-hash-table
.1 *expected-failures
*)
338 (deftest alist-hash-table
.1
339 (let* ((alist '((0 a
) (1 b
) (2 c
)))
340 (table (alist-hash-table alist
)))
341 (list (hash-table-count table
)
345 (hash-table-test table
))) ; CLISP returns EXT:FASTHASH-EQL.
348 #+clisp
(pushnew 'plist-hash-table
.1 *expected-failures
*)
350 (deftest plist-hash-table
.1
351 (let* ((plist '(:a
1 :b
2 :c
3))
352 (table (plist-hash-table plist
:test
'eq
)))
353 (list (hash-table-count table
)
359 (hash-table-test table
))) ; CLISP returns EXT:FASTHASH-EQ.
360 (3 1 2 3 nil nil eq
))
365 (let ((disjunction (disjoin (lambda (x)
366 (and (consp x
) :cons
))
368 (and (stringp x
) :string
)))))
369 (list (funcall disjunction
'zot
)
370 (funcall disjunction
'(foo bar
))
371 (funcall disjunction
"test")))
375 (let ((disjunction (disjoin #'zerop
)))
376 (list (funcall disjunction
0)
377 (funcall disjunction
1)))
381 (let ((conjunction (conjoin #'consp
386 (list (funcall conjunction
'zot
)
387 (funcall conjunction
'(foo))
388 (funcall conjunction
'("foo"))))
392 (let ((conjunction (conjoin #'zerop
)))
393 (list (funcall conjunction
0)
394 (funcall conjunction
1)))
398 (let ((composite (compose '1+
401 #'read-from-string
)))
402 (funcall composite
"1"))
407 (locally (declare (notinline compose
))
411 #'read-from-string
))))
412 (funcall composite
"2"))
416 (let ((compose-form (funcall (compiler-macro-function 'compose
)
422 (let ((fun (funcall (compile nil
`(lambda () ,compose-form
)))))
427 (let ((composite (compose #'zerop
)))
428 (list (funcall composite
0)
429 (funcall composite
1)))
432 (deftest multiple-value-compose
.1
433 (let ((composite (multiple-value-compose
438 (with-input-from-string (s x
)
439 (values (read s
) (read s
)))))))
440 (multiple-value-list (funcall composite
"2 7")))
443 (deftest multiple-value-compose
.2
444 (let ((composite (locally (declare (notinline multiple-value-compose
))
445 (multiple-value-compose
450 (with-input-from-string (s x
)
451 (values (read s
) (read s
))))))))
452 (multiple-value-list (funcall composite
"2 11")))
455 (deftest multiple-value-compose
.3
456 (let ((compose-form (funcall (compiler-macro-function 'multiple-value-compose
)
457 '(multiple-value-compose
462 (with-input-from-string (s x
)
463 (values (read s
) (read s
)))))
465 (let ((fun (funcall (compile nil
`(lambda () ,compose-form
)))))
466 (multiple-value-list (funcall fun
"2 9"))))
469 (deftest multiple-value-compose
.4
470 (let ((composite (multiple-value-compose #'truncate
)))
471 (multiple-value-list (funcall composite
9 2)))
475 (let ((curried (curry '+ 3)))
476 (funcall curried
1 5))
480 (let ((curried (locally (declare (notinline curry
))
486 (let ((curried-form (funcall (compiler-macro-function 'curry
)
489 (let ((fun (funcall (compile nil
`(lambda () ,curried-form
)))))
494 (let ((r (rcurry '/ 2)))
498 (deftest named-lambda
.1
499 (let ((fac (named-lambda fac
(x)
506 (deftest named-lambda
.2
507 (let ((fac (named-lambda fac
(&key x
)
509 (* x
(fac :x
(- x
1)))
516 (deftest alist-plist
.1
517 (alist-plist '((a .
1) (b .
2) (c .
3)))
520 (deftest plist-alist
.1
521 (plist-alist '(a 1 b
2 c
3))
522 ((a .
1) (b .
2) (c .
3)))
525 (let* ((list (list 1 2 3))
527 (unionf list
(list 1 2 4))
528 (values (equal orig
(list 1 2 3))
529 (eql (length list
) 4)
530 (set-difference list
(list 1 2 3 4))
531 (set-difference (list 1 2 3 4) list
)))
538 (let ((list (list 1 2 3)))
539 (nunionf list
(list 1 2 4))
540 (values (eql (length list
) 4)
541 (set-difference (list 1 2 3 4) list
)
542 (set-difference list
(list 1 2 3 4))))
548 (let* ((list (list 1 2 3))
550 (appendf list
'(4 5 6) '(7 8))
551 (list list
(eq list orig
)))
552 ((1 2 3 4 5 6 7 8) nil
))
555 (let ((list1 (list 1 2 3))
556 (list2 (list 4 5 6)))
557 (nconcf list1 list2
(list 7 8 9))
561 (deftest circular-list
.1
562 (let ((circle (circular-list 1 2 3)))
567 (eq circle
(nthcdr 3 circle
))))
570 (deftest circular-list-p
.1
571 (let* ((circle (circular-list 1 2 3 4))
572 (tree (list circle circle
))
573 (dotted (cons circle t
))
574 (proper (list 1 2 3 circle
))
575 (tailcirc (list* 1 2 3 circle
)))
576 (list (circular-list-p circle
)
577 (circular-list-p tree
)
578 (circular-list-p dotted
)
579 (circular-list-p proper
)
580 (circular-list-p tailcirc
)))
583 (deftest circular-list-p
.2
584 (circular-list-p 'foo
)
587 (deftest circular-tree-p
.1
588 (let* ((circle (circular-list 1 2 3 4))
589 (tree1 (list circle circle
))
590 (tree2 (let* ((level2 (list 1 nil
2))
591 (level1 (list level2
)))
592 (setf (second level2
) level1
)
594 (dotted (cons circle t
))
595 (proper (list 1 2 3 circle
))
596 (tailcirc (list* 1 2 3 circle
))
597 (quite-proper (list 1 2 3))
598 (quite-dotted (list 1 (cons 2 3))))
599 (list (circular-tree-p circle
)
600 (circular-tree-p tree1
)
601 (circular-tree-p tree2
)
602 (circular-tree-p dotted
)
603 (circular-tree-p proper
)
604 (circular-tree-p tailcirc
)
605 (circular-tree-p quite-proper
)
606 (circular-tree-p quite-dotted
)))
607 (t t t t t t nil nil
))
609 (deftest proper-list-p
.1
613 (l4 (list (cons 1 2) 3))
614 (l5 (circular-list 1 2)))
615 (list (proper-list-p l1
)
622 (deftest proper-list-p
.2
623 (proper-list-p '(1 2 .
3))
626 (deftest proper-list.type
.1
630 (l4 (list (cons 1 2) 3))
631 (l5 (circular-list 1 2)))
632 (list (typep l1
'proper-list
)
633 (typep l2
'proper-list
)
634 (typep l3
'proper-list
)
635 (typep l4
'proper-list
)
636 (typep l5
'proper-list
)))
639 (deftest proper-list-length
.1
641 (proper-list-length nil
)
642 (proper-list-length (list 1))
643 (proper-list-length (list 2 2))
644 (proper-list-length (list 3 3 3))
645 (proper-list-length (list 4 4 4 4))
646 (proper-list-length (list 5 5 5 5 5))
647 (proper-list-length (list 6 6 6 6 6 6))
648 (proper-list-length (list 7 7 7 7 7 7 7))
649 (proper-list-length (list 8 8 8 8 8 8 8 8))
650 (proper-list-length (list 9 9 9 9 9 9 9 9 9)))
653 (deftest proper-list-length
.2
656 (proper-list-length x
)
661 (plength (list* 2 2))
662 (plength (list* 3 3 3))
663 (plength (list* 4 4 4 4))
664 (plength (list* 5 5 5 5 5))
665 (plength (list* 6 6 6 6 6 6))
666 (plength (list* 7 7 7 7 7 7 7))
667 (plength (list* 8 8 8 8 8 8 8 8))
668 (plength (list* 9 9 9 9 9 9 9 9 9))))
680 (deftest lastcar.error
.2
683 (lastcar (circular-list 1 2 3))
689 (deftest setf-lastcar
.1
690 (let ((l (list 1 2 3 4)))
693 (setf (lastcar l
) 42)
698 (deftest setf-lastcar
.2
699 (let ((l (circular-list 1 2 3)))
700 (multiple-value-bind (res err
)
701 (ignore-errors (setf (lastcar l
) 4))
702 (typep err
'type-error
)))
705 (deftest make-circular-list
.1
706 (let ((l (make-circular-list 3 :initial-element
:x
)))
708 (list (eq l
(nthcdr 3 l
))
715 (deftest circular-list.type
.1
716 (let* ((l1 (list 1 2 3))
717 (l2 (circular-list 1 2 3))
718 (l3 (list* 1 2 3 l2
)))
719 (list (typep l1
'circular-list
)
720 (typep l2
'circular-list
)
721 (typep l3
'circular-list
)))
724 (deftest ensure-list
.1
727 (list (ensure-list x
)
731 (deftest ensure-cons
.1
735 (values (ensure-cons x
)
767 (setp '(a :a
) :key
'character
)
771 (setp '(a :a
) :key
'character
:test
(constantly nil
))
775 (set-equal '(1 2 3) '(3 1 2))
779 (set-equal '("Xa") '("Xb")
780 :test
(lambda (a b
) (eql (char a
0) (char b
0))))
784 (set-equal '(1 2) '(4 2))
788 (set-equal '(a b c
) '(:a
:b
:c
) :key
'string
:test
'equal
)
792 (set-equal '(a d c
) '(:a
:b
:c
) :key
'string
:test
'equal
)
796 (set-equal '(a b c
) '(a b c d
))
799 (deftest map-product
.1
800 (map-product 'cons
'(2 3) '(1 4))
801 ((2 .
1) (2 .
4) (3 .
1) (3 .
4)))
803 (deftest map-product
.2
804 (map-product #'cons
'(2 3) '(1 4))
805 ((2 .
1) (2 .
4) (3 .
1) (3 .
4)))
808 (flatten '((1) 2 (((3 4))) ((((5)) 6)) 7))
811 (deftest remove-from-plist
.1
812 (let ((orig '(a 1 b
2 c
3 d
4)))
813 (list (remove-from-plist orig
'a
'c
)
814 (remove-from-plist orig
'b
'd
)
815 (remove-from-plist orig
'b
)
816 (remove-from-plist orig
'a
)
817 (remove-from-plist orig
'd
42 "zot")
818 (remove-from-plist orig
'a
'b
'c
'd
)
819 (remove-from-plist orig
'a
'b
'c
'd
'x
)
820 (equal orig
'(a 1 b
2 c
3 d
4))))
831 (mappend (compose 'list
'*) '(1 2 3) '(1 2 3))
834 (deftest assoc-value
.1
835 (let ((key1 '(complex key
))
839 (push 1 (assoc-value alist key1
:test
#'equal
))
840 (push 2 (assoc-value alist key1
:test
'equal
))
841 (push 42 (assoc-value alist key2
))
842 (push 43 (assoc-value alist key2
:test
'eq
))
843 (push (assoc-value alist key1
:test
#'equal
) result
)
844 (push (assoc-value alist key2
) result
)
846 (push 'very
(rassoc-value alist
(list 2 1) :test
#'equal
))
847 (push (cdr (assoc '(very complex key
) alist
:test
#'equal
)) result
)
849 ((2 1) (43 42) (2 1)))
854 (list (clamp 1.5 1 2)
861 (deftest gaussian-random
.1
864 (multiple-value-bind (g1 g2
)
865 (gaussian-random min max
)
866 (values (<= min g1 max
)
879 (iota 3 :start
0.0d0
)
883 (iota 3 :start
2 :step
3.0)
888 (declare (notinline map-iota
))
889 (values (map-iota (lambda (x) (push x all
))
918 (median '(100 0 99 1 98 2 97))
922 (median '(100 0 99 1 98 2 97 96))
926 (variance (list 1 2 3))
929 (deftest standard-deviation
.1
930 (< 0 (standard-deviation (list 1 2 3)) 1)
953 (let ((xv (vector 0 0 0))
955 (maxf (svref xv
(incf p
)) (incf p
))
966 (let ((xv (vector 10 10 10))
968 (minf (svref xv
(incf p
)) (incf p
))
975 (deftest array-index.type
)
983 (list (rotate (list 1 2 3) 0)
984 (rotate (list 1 2 3) 1)
985 (rotate (list 1 2 3) 2)
986 (rotate (list 1 2 3) 3)
987 (rotate (list 1 2 3) 4))
995 (list (rotate (vector 1 2 3 4) 0)
996 (rotate (vector 1 2 3 4))
997 (rotate (vector 1 2 3 4) 2)
998 (rotate (vector 1 2 3 4) 3)
999 (rotate (vector 1 2 3 4) 4)
1000 (rotate (vector 1 2 3 4) 5))
1009 (list (rotate (list 1 2 3) 0)
1010 (rotate (list 1 2 3) -
1)
1011 (rotate (list 1 2 3) -
2)
1012 (rotate (list 1 2 3) -
3)
1013 (rotate (list 1 2 3) -
4))
1021 (list (rotate (vector 1 2 3 4) 0)
1022 (rotate (vector 1 2 3 4) -
1)
1023 (rotate (vector 1 2 3 4) -
2)
1024 (rotate (vector 1 2 3 4) -
3)
1025 (rotate (vector 1 2 3 4) -
4)
1026 (rotate (vector 1 2 3 4) -
5))
1035 (values (rotate (list 1) 17)
1036 (rotate (list 1) -
5))
1041 (let ((s (shuffle (iota 100))))
1042 (list (equal s
(iota 100))
1047 (typep x
'(integer 0 99)))
1052 (let ((s (shuffle (coerce (iota 100) 'vector
))))
1053 (list (equal s
(coerce (iota 100) 'vector
))
1058 (typep x
'(integer 0 99)))
1062 (deftest random-elt
.1
1063 (let ((s1 #(1 2 3 4))
1065 (list (dotimes (i 1000 nil
)
1066 (unless (member (random-elt s1
) s2
)
1068 (when (/= (random-elt s1
) (random-elt s1
))
1070 (dotimes (i 1000 nil
)
1071 (unless (member (random-elt s2
) s2
)
1073 (when (/= (random-elt s2
) (random-elt s2
))
1091 (let* ((x (list 1 2 3))
1101 (deftest map-permutations
.1
1102 (let ((seq (list 1 2 3))
1105 (map-permutations (lambda (s)
1106 (unless (set-equal s seq
)
1108 (when (member s seen
:test
'equal
)
1113 (values ok
(length seen
)))
1117 (deftest proper-sequence.type
.1
1119 (typep x
'proper-sequence
))
1123 (circular-list 1 2 3 4)))
1135 (deftest sequence-of-length-p
.1
1136 (mapcar #'sequence-of-length-p
1157 (t t t t t t nil nil nil nil
))
1181 (t t t t t t nil nil nil nil
))
1184 ;; test the compiler macro
1185 (macrolet ((x (&rest args
)
1189 (length= ,@args
))))))
1197 (deftest copy-sequence
.1
1198 (let ((l (list 1 2 3))
1199 (v (vector #\a #\b #\c
)))
1200 (declare (notinline copy-sequence
))
1201 (let ((l.list
(copy-sequence 'list l
))
1202 (l.vector
(copy-sequence 'vector l
))
1203 (l.spec-v
(copy-sequence '(vector fixnum
) l
))
1204 (v.vector
(copy-sequence 'vector v
))
1205 (v.list
(copy-sequence 'list v
))
1206 (v.string
(copy-sequence 'string v
)))
1207 (list (member l
(list l.list l.vector l.spec-v
))
1208 (member v
(list v.vector v.list v.string
))
1210 (equalp l.vector
#(1 2 3))
1211 (eql (upgraded-array-element-type 'fixnum
)
1212 (array-element-type l.spec-v
))
1214 (equal v.list
'(#\a #\b #\c
))
1215 (equal "abc" v.string
))))
1216 (nil nil t t t t t t
))
1218 (deftest first-elt
.1
1225 (deftest first-elt.error
.1
1240 (deftest setf-first-elt
.1
1241 (let ((l (list 1 2 3))
1242 (s (copy-seq "foobar"))
1243 (v (vector :a
:b
:c
)))
1244 (setf (first-elt l
) -
1
1252 (deftest setf-first-elt.error
.1
1254 (multiple-value-bind (res err
)
1255 (ignore-errors (setf (first-elt l
) 4))
1256 (typep err
'type-error
)))
1268 (deftest last-elt.error
.1
1278 (circular-list 1 2 3)
1279 (list* 1 2 3 (circular-list 4 5))))
1287 (deftest setf-last-elt
.1
1288 (let ((l (list 1 2 3))
1289 (s (copy-seq "foobar"))
1290 (b (copy-seq #*010101001)))
1291 (setf (last-elt l
) '???
1299 (deftest setf-last-elt.error
.1
1301 (setf (last-elt 'foo
) 13)
1306 (deftest starts-with
.1
1307 (list (starts-with 1 '(1 2 3))
1308 (starts-with 1 #(1 2 3))
1309 (starts-with #\x
"xyz")
1310 (starts-with 2 '(1 2 3))
1311 (starts-with 3 #(1 2 3))
1313 (starts-with nil nil
))
1314 (t t t nil nil nil nil
))
1316 (deftest starts-with
.2
1317 (values (starts-with 1 '(-1 2 3) :key
'-
)
1318 (starts-with "foo" '("foo" "bar") :test
'equal
)
1319 (starts-with "f" '(#\f) :key
'string
:test
'equal
)
1320 (starts-with -
1 '(0 1 2) :key
#'1+)
1321 (starts-with "zot" '("ZOT") :test
'equal
))
1328 (deftest ends-with
.1
1329 (list (ends-with 3 '(1 2 3))
1330 (ends-with 3 #(1 2 3))
1331 (ends-with #\z
"xyz")
1332 (ends-with 2 '(1 2 3))
1333 (ends-with 1 #(1 2 3))
1335 (ends-with nil nil
))
1336 (t t t nil nil nil nil
))
1338 (deftest ends-with
.2
1339 (values (ends-with 2 '(0 13 1) :key
'1+)
1340 (ends-with "foo" (vector "bar" "foo") :test
'equal
)
1341 (ends-with "X" (vector 1 2 #\X
) :key
'string
:test
'equal
)
1342 (ends-with "foo" "foo" :test
'equal
))
1348 (deftest ends-with.error
.1
1350 (ends-with 3 (circular-list 3 3 3 1 3 3))
1355 (deftest sequences.passing-improper-lists
1356 (macrolet ((signals-error-p (form)
1361 (cut (fn &rest args
)
1363 (print`(lambda (,arg
)
1364 (apply ,fn
(list ,@(substitute arg
'_ args
))))))))
1365 (let ((circular-list (make-circular-list 5 :initial-element
:foo
))
1366 (dotted-list (list* 'a
'b
'c
'd
)))
1367 (loop for nth from
0
1373 (cut #'random-elt _
)
1375 (cut #'ends-with
:foo _
))
1377 (let ((on-circular-p (signals-error-p (funcall fn circular-list
)))
1378 (on-dotted-p (signals-error-p (funcall fn dotted-list
))))
1379 (when (or (not on-circular-p
) (not on-dotted-p
))
1381 (unless on-circular-p
1382 (let ((*print-circle
* t
))
1385 "No appropriate error signalled when passing ~S to ~Ath entry."
1386 circular-list nth
))))
1390 "No appropriate error signalled when passing ~S to ~Ath entry."
1391 dotted-list nth
)))))))))
1394 (deftest with-unique-names
.1
1395 (let ((*gensym-counter
* 0))
1396 (let ((syms (with-unique-names (foo bar quux
)
1397 (list foo bar quux
))))
1398 (list (find-if #'symbol-package syms
)
1399 (equal '("FOO0" "BAR1" "QUUX2")
1400 (mapcar #'symbol-name syms
)))))
1403 (deftest with-unique-names
.2
1404 (let ((*gensym-counter
* 0))
1405 (let ((syms (with-unique-names ((foo "_foo_") (bar -bar-
) (quux #\q
))
1406 (list foo bar quux
))))
1407 (list (find-if #'symbol-package syms
)
1408 (equal '("_foo_0" "-BAR-1" "q2")
1409 (mapcar #'symbol-name syms
)))))
1412 (deftest with-unique-names
.3
1413 (let ((*gensym-counter
* 0))
1414 (multiple-value-bind (res err
)
1418 (with-unique-names ((foo "_foo_") (bar -bar-
) (quux 42))
1419 (list foo bar quux
))))
1420 (list (find-if #'symbol-package syms
)
1421 (equal '("_foo_0" "-BAR-1" "q2")
1422 (mapcar #'symbol-name syms
))))))
1426 (deftest once-only
.1
1427 (macrolet ((cons1.good
(x)
1433 (list (cons1.good
(incf y
))
1435 (cons1.bad
(incf y
))
1437 ((1 .
1) 1 (2 .
3) 3))
1439 (deftest once-only
.2
1440 (macrolet ((cons1 (x)
1444 (list (cons1 (incf z
))
1447 ((1 .
1) 1 (2 .
2)))
1449 (deftest parse-body
.1
1450 (parse-body '("doc" "body") :documentation t
)
1455 (deftest parse-body
.2
1456 (parse-body '("body") :documentation t
)
1461 (deftest parse-body
.3
1462 (parse-body '("doc" "body"))
1467 (deftest parse-body
.4
1468 (parse-body '((declare (foo)) "doc" (declare (bar)) body
) :documentation t
)
1470 ((declare (foo)) (declare (bar)))
1473 (deftest parse-body
.5
1474 (parse-body '((declare (foo)) "doc" (declare (bar)) body
))
1475 ("doc" (declare (bar)) body
)
1479 (deftest parse-body
.6
1480 (multiple-value-bind (res err
)
1482 (parse-body '("foo" "bar" "quux")
1489 (deftest ensure-symbol
.1
1490 (ensure-symbol :cons
:cl
)
1494 (deftest ensure-symbol
.2
1495 (ensure-symbol "CONS" :alexandria
)
1499 (deftest ensure-symbol
.3
1500 (ensure-symbol 'foo
:keyword
)
1504 (deftest ensure-symbol
.4
1505 (ensure-symbol #\
* :alexandria
)
1509 (deftest format-symbol
.1
1510 (let ((s (format-symbol nil
"X-~D" 13)))
1511 (list (symbol-package s
)
1515 (deftest format-symbol
.2
1516 (format-symbol :keyword
"SYM-~A" :bolic
)
1519 (deftest format-symbol
.3
1520 (let ((*package
* (find-package :cl
)))
1521 (format-symbol t
"FIND-~A" 'package
))
1524 (deftest make-keyword
.1
1525 (list (make-keyword 'zot
)
1526 (make-keyword "FOO")
1530 (deftest make-gensym-list
.1
1531 (let ((*gensym-counter
* 0))
1532 (let ((syms (make-gensym-list 3 "FOO")))
1533 (list (find-if 'symbol-package syms
)
1534 (equal '("FOO0" "FOO1" "FOO2")
1535 (mapcar 'symbol-name syms
)))))
1538 (deftest make-gensym-list
.2
1539 (let ((*gensym-counter
* 0))
1540 (let ((syms (make-gensym-list 3)))
1541 (list (find-if 'symbol-package syms
)
1542 (equal '("G0" "G1" "G2")
1543 (mapcar 'symbol-name syms
)))))
1550 (declare (notinline of-type
))
1551 (let ((f (of-type 'string
)))
1552 (list (funcall f
"foo")
1557 (type= 'string
'string
)
1562 (type= 'list
'(or null cons
))
1567 (type= 'null
'(and symbol list
))
1572 (type= 'string
'(satisfies emptyp
))
1577 (type= 'string
'list
)
1582 ((test (type numbers
)
1583 `(deftest ,(format-symbol t
"CDR5.~A" type
)
1584 (let ((numbers ,numbers
))
1585 (values (mapcar (of-type ',(format-symbol t
"NEGATIVE-~A" type
)) numbers
)
1586 (mapcar (of-type ',(format-symbol t
"NON-POSITIVE-~A" type
)) numbers
)
1587 (mapcar (of-type ',(format-symbol t
"NON-NEGATIVE-~A" type
)) numbers
)
1588 (mapcar (of-type ',(format-symbol t
"POSITIVE-~A" type
)) numbers
)))
1589 (t t t nil nil nil nil
)
1590 (t t t t nil nil nil
)
1591 (nil nil nil t t t t
)
1592 (nil nil nil nil t t t
))))
1593 (test fixnum
(list most-negative-fixnum -
42 -
1 0 1 42 most-positive-fixnum
))
1594 (test integer
(list (1- most-negative-fixnum
) -
42 -
1 0 1 42 (1+ most-positive-fixnum
)))
1595 (test rational
(list (1- most-negative-fixnum
) -
42/13 -
1 0 1 42/13 (1+ most-positive-fixnum
)))
1596 (test real
(list most-negative-long-float -
42/13 -
1 0 1 42/13 most-positive-long-float
))
1597 (test float
(list most-negative-short-float -
42.02 -
1.0 0.0 1.0 42.02 most-positive-short-float
))
1598 (test short-float
(list most-negative-short-float -
42.02s0 -
1.0s0
0.0s0
1.0s0
42.02s0 most-positive-short-float
))
1599 (test single-float
(list most-negative-single-float -
42.02f0 -
1.0f0
0.0f0
1.0f0
42.02f0 most-positive-single-float
))
1600 (test double-float
(list most-negative-double-float -
42.02d0 -
1.0d0
0.0d0
1.0d0
42.02d0 most-positive-double-float
))
1601 (test long-float
(list most-negative-long-float -
42.02l0 -
1.0l0 0.0l0 1.0l0 42.02l0 most-positive-long-float
)))
1605 (declaim (notinline opaque
))
1610 (if-let (x (opaque :ok
))
1616 (if-let (x (opaque nil
))
1642 (deftest if-let.error
.1
1652 (when-let (x (opaque :ok
))
1671 (deftest when-let.error
.1
1673 (eval '(when-let x
:oops
))
1678 (deftest when-let
*.1
1685 (deftest when-let
*.2
1691 (deftest when-let
*.3
1698 (deftest when-let
*.error
.1
1700 (eval '(when-let* x
:oops
))
1707 (doplist (k v
'(a 1 b
2 c
3) (values t
(reverse keys
) (reverse values
) k v
))
1716 (deftest count-permutations
.1
1717 (values (count-permutations 31 7)
1718 (count-permutations 1 1)
1719 (count-permutations 2 1)
1720 (count-permutations 2 2)
1721 (count-permutations 3 2)
1722 (count-permutations 3 1))
1730 (deftest binomial-coefficient
.1
1731 (alexandria:binomial-coefficient
1239 139)
1732 28794902202288970200771694600561826718847179309929858835480006683522184441358211423695124921058123706380656375919763349913245306834194782172712255592710204598527867804110129489943080460154)