source: trunk/source/tests/ansi-tests/mapc.lsp @ 8991

Last change on this file since 8991 was 8991, checked in by gz, 12 years ago

Check in the gcl ansi test suite (original, in preparation for making local changes)

File size: 2.1 KB
Line 
1;-*- Mode:     Lisp -*-
2;;;; Author:   Paul Dietz
3;;;; Created:  Sun Apr 20 07:21:24 2003
4;;;; Contains: Tests of MAPC
5
6(in-package :cl-test)
7
8(compile-and-load "cons-aux.lsp")
9
10(deftest mapc.1
11  (mapc #'list nil)
12  nil)
13
14(deftest mapc.2
15  (let ((x 0))
16    (let ((result
17           (mapc #'(lambda (y) (incf x y))
18                 '(1 2 3 4))))
19      (list result x)))
20  ((1 2 3 4) 10))
21
22(deftest mapc.3
23  (let ((x 0))
24    (list
25     (mapc #'(lambda (y z) (declare (ignore y z)) (incf x))
26           (make-list 5 :initial-element 'a)
27           (make-list 5 ))
28     x))
29  ((a a a a a) 5))
30
31(deftest mapc.4
32  (let ((x 0))
33    (list
34     (mapc #'(lambda (y z) (declare (ignore y z)) (incf x))
35           (make-list 5 :initial-element 'a)
36           (make-list 10))
37     x))
38  ((a a a a a) 5))
39
40(deftest mapc.5
41  (let ((x 0))
42    (list
43     (mapc #'(lambda (y z) (declare (ignore y z)) (incf x))
44           (make-list 5 :initial-element 'a)
45           (make-list 3))
46     x))
47  ((a a a a a) 3))
48
49(deftest mapc.6
50  (let* ((x (copy-list '(a b c d e f g h)))
51         (xcopy (make-scaffold-copy x)))
52    (setf *mapc.6-var* nil)
53    (let ((result (mapc 'mapc.6-fun x)))
54      (and (check-scaffold-copy x xcopy)
55           (eqt result x)
56           *mapc.6-var*)))
57  (h g f e d c b a))
58
59(deftest mapc.order.1
60  (let ((i 0) x y z)
61    (values
62     (mapc (progn (setf x (incf i))
63                  #'list)
64           (progn (setf y (incf i))
65                  '(a b c))
66           (progn (setf z (incf i))
67                  '(1 2 3)))
68     i x y z))
69  (a b c) 3 1 2 3)
70
71;;; Error tests
72
73(deftest mapc.error.1
74  (check-type-error #'(lambda (x) (mapc #'identity x)) #'listp)
75  nil)
76
77(deftest mapc.error.2
78  (signals-error (mapc) program-error)
79  t)
80
81(deftest mapc.error.3
82  (signals-error (mapc #'append) program-error)
83  t)
84
85(deftest mapc.error.4
86  (signals-error (locally (mapc #'identity 1) t) type-error)
87  t)
88
89(deftest mapc.error.5
90  (signals-error (mapc #'cons '(a b c)) program-error)
91  t)
92
93(deftest mapc.error.6
94  (signals-error (mapc #'cons '(a b c) '(1 2 3) '(4 5 6)) program-error)
95  t)
96
97(deftest mapc.error.7
98  (signals-error (mapc #'car '(a b c)) type-error)
99  t)
100
101(deftest mapc.error.8
102  (signals-error (mapc #'identity (list* 1 2 3 4)) type-error)
103  t)
Note: See TracBrowser for help on using the repository browser.