source: trunk/source/tests/ansi-tests/loop14.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: 7.2 KB
Line 
1;-*- Mode:     Lisp -*-
2;;;; Author:   Paul Dietz
3;;;; Created:  Wed Nov 20 06:33:21 2002
4;;;; Contains: Tests of LOOP conditional execution clauses
5
6(in-package :cl-test)
7
8(deftest loop.14.1
9  (loop for x from 1 to 6
10        when (evenp x)
11        collect x)
12  (2 4 6))
13
14(deftest loop.14.2
15  (loop for x from 1 to 6
16        unless (evenp x)
17        collect x)
18  (1 3 5))
19
20(deftest loop.14.3
21  (loop for x from 1 to 10
22        when (evenp x)
23          collect x into foo
24          and count t into bar
25        finally (return (values foo bar)))
26  (2 4 6 8 10)
27  5)
28
29(deftest loop.14.4
30  (loop for x from 1 to 10
31        when (evenp x) collect x end)
32  (2 4 6 8 10))
33
34(deftest loop.14.5
35  (loop for x from 1 to 10
36        when (evenp x) collect x into evens
37        else collect x into odds
38        end
39        finally (return (values evens odds)))
40  (2 4 6 8 10)
41  (1 3 5 7 9))
42
43(deftest loop.14.6
44  (loop for x from 1 to 10
45        unless (oddp x)
46          collect x into foo
47          and count t into bar
48        finally (return (values foo bar)))
49  (2 4 6 8 10)
50  5)
51
52(deftest loop.14.7
53  (loop for x from 1 to 10
54        unless (oddp x) collect x end)
55  (2 4 6 8 10))
56
57(deftest loop.14.8
58  (loop for x from 1 to 10
59        unless (oddp x) collect x into evens
60        else collect x into odds
61        end
62        finally (return (values evens odds)))
63  (2 4 6 8 10)
64  (1 3 5 7 9))
65
66(deftest loop.14.9
67  (loop for x from 1 to 6
68        if (evenp x)
69        collect x)
70  (2 4 6))
71
72(deftest loop.14.10
73  (loop for x from 1 to 10
74        if (evenp x)
75          collect x into foo
76          and count t into bar
77        finally (return (values foo bar)))
78  (2 4 6 8 10)
79  5)
80
81(deftest loop.14.11
82  (loop for x from 1 to 10
83        if (evenp x) collect x end)
84  (2 4 6 8 10))
85
86(deftest loop.14.12
87  (loop for x from 1 to 10
88        if (evenp x) collect x into evens
89        else collect x into odds
90        end
91        finally (return (values evens odds)))
92  (2 4 6 8 10)
93  (1 3 5 7 9))
94
95;;; Test that else associates with the nearest conditional unclosed
96;;; by end
97
98(deftest loop.14.13
99  (loop for i from 1 to 20
100        if (evenp i)
101          if (= (mod i 3) 0)
102            collect i into list1
103            else collect i into list2
104        finally (return (values list1 list2)))
105  (6 12 18)
106  (2 4 8 10 14 16 20))
107
108(deftest loop.14.14
109  (loop for i from 1 to 20
110        when (evenp i)
111          if (= (mod i 3) 0)
112            collect i into list1
113            else collect i into list2
114        finally (return (values list1 list2)))
115  (6 12 18)
116  (2 4 8 10 14 16 20))
117
118(deftest loop.14.15
119  (loop for i from 1 to 20
120        if (evenp i)
121          when (= (mod i 3) 0)
122            collect i into list1
123            else collect i into list2
124        finally (return (values list1 list2)))
125  (6 12 18)
126  (2 4 8 10 14 16 20))
127
128(deftest loop.14.16
129  (loop for i from 1 to 20
130        if (evenp i)
131          if (= (mod i 3) 0)
132            collect i into list1
133          end
134          else collect i into list2
135        finally (return (values list1 list2)))
136  (6 12 18)
137  (1 3 5 7 9 11 13 15 17 19))
138
139(deftest loop.14.17
140  (loop for i from 1 to 20
141        when (evenp i)
142          if (= (mod i 3) 0)
143            collect i into list1
144          end
145          else collect i into list2
146        finally (return (values list1 list2)))
147  (6 12 18)
148  (1 3 5 7 9 11 13 15 17 19))
149
150(deftest loop.14.18
151  (loop for i from 1 to 20
152        if (evenp i)
153          when (= (mod i 3) 0)
154            collect i into list1
155          end
156          else collect i into list2
157        finally (return (values list1 list2)))
158  (6 12 18)
159  (1 3 5 7 9 11 13 15 17 19))
160
161(deftest loop.14.19
162  (loop for i from 1 to 20
163        when (evenp i)
164          when (= (mod i 3) 0)
165            collect i into list1
166          end
167          else collect i into list2
168        finally (return (values list1 list2)))
169  (6 12 18)
170  (1 3 5 7 9 11 13 15 17 19))
171
172(deftest loop.14.20
173  (loop for i from 1 to 20
174        unless (oddp i)
175          if (= (mod i 3) 0)
176            collect i into list1
177          end
178          else collect i into list2
179        finally (return (values list1 list2)))
180  (6 12 18)
181  (1 3 5 7 9 11 13 15 17 19))
182
183(deftest loop.14.21
184  (loop for i from 1 to 20
185        if (evenp i)
186          unless (/= (mod i 3) 0)
187            collect i into list1
188          end
189          else collect i into list2
190        finally (return (values list1 list2)))
191  (6 12 18)
192  (1 3 5 7 9 11 13 15 17 19))
193
194(deftest loop.14.22
195  (loop for i from 1 to 20
196        unless (oddp i)
197          unless (/= (mod i 3) 0)
198            collect i into list1
199          end
200          else collect i into list2
201        finally (return (values list1 list2)))
202  (6 12 18)
203  (1 3 5 7 9 11 13 15 17 19))
204
205;;; More tests conditionals
206
207(deftest loop.14.23
208  (loop for i from 1 to 20
209        if (evenp i)
210          collect i into list1
211        else if (= (mod i 3) 0)
212          collect i into list2
213        else collect i into list3
214        finally (return (values list1 list2 list3)))
215  (2 4 6 8 10 12 14 16 18 20)
216  (3 9 15)
217  (1 5 7 11 13 17 19))
218
219;;; Tests of 'IT'
220
221(deftest loop.14.24
222  (loop for x in '((a) nil (b) (c) (nil) (d))
223        when (car x) collect it)
224  (a b c d))
225
226(deftest loop.14.25
227  (loop for x in '((a) nil (b) (c) (nil) (d))
228        if (car x) collect it)
229  (a b c d))
230
231(deftest loop.14.26
232  (loop for x in '(nil (a) nil (b) (c) (nil) (d))
233        when (car x) return it)
234  a)
235
236(deftest loop.14.27
237  (loop for x in '(nil (a) nil (b) (c) (nil) (d))
238        if (car x) return it)
239  a)
240
241(deftest loop.14.28
242  (loop for x in '((a) nil (b) (c) (nil) (d))
243        when (car x) collect it and collect 'foo)
244  (a foo b foo c foo d foo))
245
246(deftest loop.14.29
247  (let ((it 'z))
248    (loop for x in '(a b c d)
249          when x collect it and collect it))
250  (a z b z c z d z))
251
252(deftest loop.14.30
253  (let ((it 'z))
254    (loop for x in '(a b c d)
255          if x collect it end
256          collect it))
257  (a z b z c z d z))
258
259(deftest loop.14.31
260  (loop for it on '(a b c d)
261        when (car it) collect it)
262  (a b c d))
263
264(deftest loop.14.32
265  (loop for x in '(a b nil c d nil e)
266        when x collecting it)
267  (a b c d e))
268
269(deftest loop.14.33
270  (loop for x in '(a b nil c d nil e)
271        when x append (list x))
272  (a b c d e))
273
274(deftest loop.14.34
275  (loop for x in '(a b nil c d nil e)
276        when x appending (list x))
277  (a b c d e))
278
279(deftest loop.14.35
280  (loop for x in '(a b nil c d nil e)
281        when x nconc (list x))
282  (a b c d e))
283
284(deftest loop.14.36
285  (loop for x in '(a b nil c d nil e)
286        when x nconcing (list x))
287  (a b c d e))
288
289(deftest loop.14.37
290  (loop for it on '(a b c d)
291        when (car it) collect it into foo
292        finally (return foo))
293  (a b c d))
294
295(deftest loop.14.38
296  (loop for x in '(1 2 nil 3 4 nil 5 nil)
297        when x count it)
298  5)
299
300(deftest loop.14.39
301  (loop for x in '(1 2 nil 3 4 nil 5 nil)
302        when x counting it)
303  5)
304
305(deftest loop.14.40
306  (loop for x in '(1 2 nil 3 4 nil 6 nil)
307        when x maximize it)
308  6)
309
310(deftest loop.14.41
311  (loop for x in '(1 2 nil 3 4 nil 6 nil)
312        when x maximizing it)
313  6)
314
315(deftest loop.14.42
316  (loop for x in '(1 2 nil 3 4 nil 6 nil)
317        when x minimize it)
318  1)
319
320(deftest loop.14.43
321  (loop for x in '(1 2 nil 3 4 nil 6 nil)
322        when x minimizing it)
323  1)
324
325(deftest loop.14.44
326  (loop for x in '(1 2 nil 3 4 nil 6 nil)
327        when x sum it)
328  16)
329
330(deftest loop.14.45
331  (loop for x in '(1 2 nil 3 4 nil 6 nil)
332        when x summing it)
333  16)
334
335;;; Test that explicit calls to macroexpand in subforms
336;;; are done in the correct environment
337
338(deftest loop.14.46
339  (macrolet
340   ((%m (z) z))
341   (loop for x from 1 to 6
342         when (expand-in-current-env (%m (evenp x)))
343         collect x))
344  (2 4 6))
345
346(deftest loop.14.47
347  (macrolet
348   ((%m (z) z))
349   (loop for x from 1 to 6
350         unless (expand-in-current-env (%m (evenp x)))
351         collect x))
352  (1 3 5))
353
354(deftest loop.14.48
355  (macrolet
356   ((%m (z) z))
357   (loop for x from 1 to 6
358         when (expand-in-current-env (%m t))
359         sum x))
360  21)
361
362(deftest loop.14.49
363  (macrolet
364   ((%m (z) z))
365   (loop for x from 1 to 10
366         if  (expand-in-current-env (%m (evenp x)))
367         collect x end))
368  (2 4 6 8 10))
Note: See TracBrowser for help on using the repository browser.