mapcon.lsp 1.96 KB
Newer Older
1 2 3 4 5
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Sun Apr 20 07:24:28 2003
;;;; Contains: Tests of MAPCON

6

7

8

9

10 11 12 13 14 15
(deftest mapcon.1
  (mapcon #'(lambda (x) (append '(a) x nil)) nil)
  nil)

(deftest mapcon.2
  (let* ((x (copy-list '(1 2 3 4)))
sds's avatar
sds committed
16 17 18
         (xcopy (make-scaffold-copy x))
         (result
          (mapcon #'(lambda (y) (append '(a) y nil)) x)))
19 20 21 22 23 24 25
    (and
     (check-scaffold-copy x xcopy)
     result))
  (a 1 2 3 4 a 2 3 4 a 3 4 a 4))

(deftest mapcon.3
  (let* ((x (copy-list '(4 2 3 2 2)))
sds's avatar
sds committed
26 27 28 29 30 31 32
         (y (copy-list '(a b c d e f g h i j k l)))
         (xcopy (make-scaffold-copy x))
         (ycopy (make-scaffold-copy y))
         (result
          (mapcon #'(lambda (xt yt)
                      (subseq yt 0 (car xt)))
                  x y)))
33 34 35 36 37 38 39 40 41 42 43 44 45 46
    (and
     (check-scaffold-copy x xcopy)
     (check-scaffold-copy y ycopy)
     result))
  (a b c d b c c d e d e e f))

(deftest mapcon.4
  (mapcon (constantly 1) (list 'a))
  1)

(deftest mapcon.order.1
  (let ((i 0) x y z)
    (values
     (mapcon (progn (setf x (incf i))
sds's avatar
sds committed
47 48 49 50 51
                    #'(lambda (x y) (list (car x) (car y))))
             (progn (setf y (incf i))
                    '(a b c))
             (progn (setf z (incf i))
                    '(1 2 3)))
52 53 54 55 56
     i x y z))
  (a 1 b 2 c 3)
  3 1 2 3)

(deftest mapcon.error.1
pfdietz's avatar
pfdietz committed
57 58
  (check-type-error #'(lambda (x) (mapcon #'identity x)) #'listp)
  nil)
59 60

(deftest mapcon.error.2
61 62
  (signals-error (mapcon) program-error)
  t)
63 64

(deftest mapcon.error.3
65 66
  (signals-error (mapcon #'append) program-error)
  t)
67 68

(deftest mapcon.error.4
69 70
  (signals-error (locally (mapcon #'identity 1) t) type-error)
  t)
71 72

(deftest mapcon.error.5
73 74
  (signals-error (mapcon #'caar '(a b c)) type-error)
  t)
75 76

(deftest mapcon.error.6
77 78
  (signals-error (mapcon #'cons '(a b c)) program-error)
  t)
79 80

(deftest mapcon.error.7
81 82
  (signals-error (mapcon #'cons '(a b c) '(1 2 3) '(4 5 6)) program-error)
  t)
83 84

(deftest mapcon.error.8
85 86
  (signals-error (mapcon #'copy-tree (cons 1 2)) type-error)
  t)