1 | ;-*- Mode: Lisp -*- |
---|
2 | ;;;; Author: Paul Dietz |
---|
3 | ;;;; Created: Sun Apr 20 07:23:23 2003 |
---|
4 | ;;;; Contains: Tests of MAPL |
---|
5 | |
---|
6 | (in-package :cl-test) |
---|
7 | |
---|
8 | (compile-and-load "cons-aux.lsp") |
---|
9 | |
---|
10 | (deftest mapl.1 |
---|
11 | (mapl #'list nil) |
---|
12 | nil) |
---|
13 | |
---|
14 | (deftest mapl.2 |
---|
15 | (let* ((a nil) |
---|
16 | (x (copy-list '(a b c))) |
---|
17 | (xcopy (make-scaffold-copy x)) |
---|
18 | (result |
---|
19 | (mapl #'(lambda (y) (push y a)) |
---|
20 | x))) |
---|
21 | (and |
---|
22 | (check-scaffold-copy x xcopy) |
---|
23 | (eqt result x) |
---|
24 | a)) |
---|
25 | ((c) (b c) (a b c))) |
---|
26 | |
---|
27 | (deftest mapl.3 |
---|
28 | (let* ((a nil) |
---|
29 | (x (copy-list '(a b c d))) |
---|
30 | (y (copy-list '(1 2 3 4))) |
---|
31 | (xcopy (make-scaffold-copy x)) |
---|
32 | (ycopy (make-scaffold-copy y)) |
---|
33 | (result |
---|
34 | (mapl #'(lambda (xtail ytail) |
---|
35 | (setf a |
---|
36 | (append (mapcar #'list xtail ytail) |
---|
37 | a))) |
---|
38 | x y))) |
---|
39 | (and |
---|
40 | (eqt result x) |
---|
41 | (check-scaffold-copy x xcopy) |
---|
42 | (check-scaffold-copy y ycopy) |
---|
43 | a)) |
---|
44 | ((d 4) (c 3) (d 4) (b 2) (c 3) (d 4) |
---|
45 | (a 1) (b 2) (c 3) (d 4))) |
---|
46 | |
---|
47 | (deftest mapl.4 |
---|
48 | (let* ((a nil) |
---|
49 | (x (copy-list '(a b c d))) |
---|
50 | (y (copy-list '(1 2 3 4 5 6 7 8))) |
---|
51 | (xcopy (make-scaffold-copy x)) |
---|
52 | (ycopy (make-scaffold-copy y)) |
---|
53 | (result |
---|
54 | (mapl #'(lambda (xtail ytail) |
---|
55 | (setf a |
---|
56 | (append (mapcar #'list xtail ytail) |
---|
57 | a))) |
---|
58 | x y))) |
---|
59 | (and |
---|
60 | (eqt result x) |
---|
61 | (check-scaffold-copy x xcopy) |
---|
62 | (check-scaffold-copy y ycopy) |
---|
63 | a)) |
---|
64 | ((d 4) (c 3) (d 4) (b 2) (c 3) (d 4) |
---|
65 | (a 1) (b 2) (c 3) (d 4))) |
---|
66 | |
---|
67 | (deftest mapl.5 |
---|
68 | (let* ((a nil) |
---|
69 | (x (copy-list '(a b c d e f g))) |
---|
70 | (y (copy-list '(1 2 3 4))) |
---|
71 | (xcopy (make-scaffold-copy x)) |
---|
72 | (ycopy (make-scaffold-copy y)) |
---|
73 | (result |
---|
74 | (mapl #'(lambda (xtail ytail) |
---|
75 | (setf a |
---|
76 | (append (mapcar #'list xtail ytail) |
---|
77 | a))) |
---|
78 | x y))) |
---|
79 | (and |
---|
80 | (eqt result x) |
---|
81 | (check-scaffold-copy x xcopy) |
---|
82 | (check-scaffold-copy y ycopy) |
---|
83 | a)) |
---|
84 | ((d 4) (c 3) (d 4) (b 2) (c 3) (d 4) |
---|
85 | (a 1) (b 2) (c 3) (d 4))) |
---|
86 | |
---|
87 | (deftest mapl.order.1 |
---|
88 | (let ((i 0) x y z) |
---|
89 | (values |
---|
90 | (mapl (progn |
---|
91 | (setf x (incf i)) |
---|
92 | (constantly nil)) |
---|
93 | (progn |
---|
94 | (setf y (incf i)) |
---|
95 | '(a b c)) |
---|
96 | (progn |
---|
97 | (setf z (incf i)) |
---|
98 | '(1 2 3))) |
---|
99 | i x y z)) |
---|
100 | (a b c) 3 1 2 3) |
---|
101 | |
---|
102 | (deftest mapl.error.1 |
---|
103 | (check-type-error #'(lambda (x) (mapl #'identity x)) #'sequencep) |
---|
104 | nil) |
---|
105 | |
---|
106 | (deftest mapl.error.2 |
---|
107 | (signals-error (mapl) program-error) |
---|
108 | t) |
---|
109 | |
---|
110 | (deftest mapl.error.3 |
---|
111 | (signals-error (mapl #'append) program-error) |
---|
112 | t) |
---|
113 | |
---|
114 | (deftest mapl.error.4 |
---|
115 | (signals-error (locally (mapl #'identity 1) t) type-error) |
---|
116 | t) |
---|
117 | |
---|
118 | (deftest mapl.error.5 |
---|
119 | (signals-error (mapl #'cons '(a b c)) program-error) |
---|
120 | t) |
---|
121 | |
---|
122 | (deftest mapl.error.6 |
---|
123 | (signals-error (mapl #'cons '(a b c) '(1 2 3) '(4 5 6)) program-error) |
---|
124 | t) |
---|
125 | |
---|
126 | (deftest mapl.error.7 |
---|
127 | (signals-error (mapl #'caar '(a b c)) type-error) |
---|
128 | t) |
---|
129 | |
---|
130 | (deftest mapl.error.8 |
---|
131 | (signals-error (mapl #'identity (list* (list 1) (list 2) 3)) type-error) |
---|
132 | t) |
---|
133 | |
---|