mapc.lsp 2.2 KB
Newer Older
1 2 3 4 5 6 7
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Sun Apr 20 07:21:24 2003
;;;; Contains: Tests of MAPC

(in-package :cl-test)

8 9
(compile-and-load "cons-aux.lsp")

10 11 12 13 14 15 16
(deftest mapc.1
  (mapc #'list nil)
  nil)

(deftest mapc.2
  (let ((x 0))
    (let ((result
sds's avatar
sds committed
17 18
           (mapc #'(lambda (y) (incf x y))
                 '(1 2 3 4))))
19 20 21 22 23 24 25
      (list result x)))
  ((1 2 3 4) 10))

(deftest mapc.3
  (let ((x 0))
    (list
     (mapc #'(lambda (y z) (declare (ignore y z)) (incf x))
sds's avatar
sds committed
26 27
           (make-list 5 :initial-element 'a)
           (make-list 5 ))
28 29 30 31 32 33 34
     x))
  ((a a a a a) 5))

(deftest mapc.4
  (let ((x 0))
    (list
     (mapc #'(lambda (y z) (declare (ignore y z)) (incf x))
sds's avatar
sds committed
35 36
           (make-list 5 :initial-element 'a)
           (make-list 10))
37 38 39 40 41 42 43
     x))
  ((a a a a a) 5))

(deftest mapc.5
  (let ((x 0))
    (list
     (mapc #'(lambda (y z) (declare (ignore y z)) (incf x))
sds's avatar
sds committed
44 45
           (make-list 5 :initial-element 'a)
           (make-list 3))
46 47 48 49 50
     x))
  ((a a a a a) 3))

(deftest mapc.6
  (let* ((x (copy-list '(a b c d e f g h)))
sds's avatar
sds committed
51
         (xcopy (make-scaffold-copy x)))
52 53 54
    (setf *mapc.6-var* nil)
    (let ((result (mapc 'mapc.6-fun x)))
      (and (check-scaffold-copy x xcopy)
sds's avatar
sds committed
55 56
           (eqt result x)
           *mapc.6-var*)))
57 58 59 60 61 62
  (h g f e d c b a))

(deftest mapc.order.1
  (let ((i 0) x y z)
    (values
     (mapc (progn (setf x (incf i))
sds's avatar
sds committed
63 64 65 66 67
                  #'list)
           (progn (setf y (incf i))
                  '(a b c))
           (progn (setf z (incf i))
                  '(1 2 3)))
68 69 70
     i x y z))
  (a b c) 3 1 2 3)

pfdietz's avatar
pfdietz committed
71 72
;;; Error tests

73
(deftest mapc.error.1
pfdietz's avatar
pfdietz committed
74 75
  (check-type-error #'(lambda (x) (mapc #'identity x)) #'listp)
  nil)
76 77

(deftest mapc.error.2
78 79
  (signals-error (mapc) program-error)
  t)
80 81

(deftest mapc.error.3
82 83
  (signals-error (mapc #'append) program-error)
  t)
84 85

(deftest mapc.error.4
86 87
  (signals-error (locally (mapc #'identity 1) t) type-error)
  t)
88 89

(deftest mapc.error.5
90 91
  (signals-error (mapc #'cons '(a b c)) program-error)
  t)
92 93

(deftest mapc.error.6
94 95
  (signals-error (mapc #'cons '(a b c) '(1 2 3) '(4 5 6)) program-error)
  t)
96 97

(deftest mapc.error.7
98 99
  (signals-error (mapc #'car '(a b c)) type-error)
  t)
100 101

(deftest mapc.error.8
102 103
  (signals-error (mapc #'identity (list* 1 2 3 4)) type-error)
  t)