source: trunk/source/tests/ansi-tests/loop1.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.7 KB
Line 
1;-*- Mode:     Lisp -*-
2;;;; Author:   Paul Dietz
3;;;; Created:  Fri Oct 25 19:07:19 2002
4;;;; Contains: Tests of extended loop, part 1
5
6(in-package :cl-test)
7
8;;; Tests of variable initialization and stepping clauses
9
10;;; for-as-arithmetic
11
12(deftest loop.1.1
13  (loop for x from 1 to 10 collect x)
14  (1 2 3 4 5 6 7 8 9 10))
15
16(deftest loop.1.2
17  (loop for x from 6 downto 1 collect x)
18  (6 5 4 3 2 1))
19
20(deftest loop.1.3
21  (loop for x from 1 to 1 collect x)
22  (1))
23
24(deftest loop.1.4
25  (loop for x from 1 to 0 collect x)
26  nil)
27
28(deftest loop.1.5
29  (loop for x to 5 collect x)
30  (0 1 2 3 4 5))
31
32(deftest loop.1.6
33  (loop for x downfrom 5 to 0 collect x)
34  (5 4 3 2 1 0))
35
36(deftest loop.1.7
37  (loop for x upfrom 1 to 5 collect x)
38  (1 2 3 4 5))
39
40(deftest loop.1.8
41  (loop for x from 1.0 to 5.0 count x)
42  5)
43
44(deftest loop.1.9
45  (loop for x from 1 to 9 by 2 collect x)
46  (1 3 5 7 9))
47
48(deftest loop.1.10
49  (loop for x from 1 to 10 by 2 collect x)
50  (1 3 5 7 9))
51
52(deftest loop.1.11
53  (loop for x to 10 from 1 collect x)
54  (1 2 3 4 5 6 7 8 9 10))
55
56(deftest loop.1.12
57  (loop for x to 10 by 2 from 1 collect x)
58  (1 3 5 7 9))
59
60(deftest loop.1.13
61  (loop for x by 2 to 10 from 1 collect x)
62  (1 3 5 7 9))
63
64(deftest loop.1.14
65  (loop for x by 2 to 10 collect x)
66  (0 2 4 6 8 10))
67
68(deftest loop.1.15
69  (loop for x to 10 by 2 collect x)
70  (0 2 4 6 8 10))
71
72(deftest loop.1.16
73  (let ((n 0))
74    (loop for x from (incf n) to (+ n 5) collect x))
75  (1 2 3 4 5 6))
76
77(deftest loop.1.17
78  (let ((n 0))
79    (loop for x to (+ n 5) from (incf n) collect x))
80  (1 2 3 4 5))
81
82(deftest loop.1.18
83  (let ((n 0))
84    (loop for x from (incf n) to (+ n 9) by (incf n) collect x))
85  (1 3 5 7 9))
86
87(deftest loop.1.19
88  (let ((n 0))
89    (loop for x from (incf n) by (incf n) to (+ n 9) collect x))
90  (1 3 5 7 9 11))
91
92(deftest loop.1.20
93  (let ((a 0) (b 5) (c 1))
94    (loop for x from a to b by c
95          collect (progn (incf a) (incf b 2) (incf c 3) x)))
96  (0 1 2 3 4 5))
97
98(deftest loop.1.21
99  (loop for x from 0 to 5 by 1/2 collect x)
100  (0 1/2 1 3/2 2 5/2 3 7/2 4 9/2 5))
101
102(deftest loop.1.22
103  (loop for x from 1 below 5 collect x)
104  (1 2 3 4))
105
106(deftest loop.1.23
107  (loop for x from 1 below 5.01 collect x)
108  (1 2 3 4 5))
109
110(deftest loop.1.24
111  (loop for x below 5 from 2 collect x)
112  (2 3 4))
113
114(deftest loop.1.25
115  (loop for x from 10 above 4 collect x)
116  (10 9 8 7 6 5))
117
118(deftest loop.1.26
119  (loop for x from 14 above 6 by 2 collect x)
120  (14 12 10 8))
121
122(deftest loop.1.27
123  (loop for x above 6 from 14 by 2 collect x)
124  (14 12 10 8))
125
126(deftest loop.1.28
127  (loop for x downfrom 16 above 7 by 3 collect x)
128  (16 13 10))
129
130(deftest loop.1.29
131  (let (a b c (i 0))
132    (values
133     (loop for x from (progn (setq a (incf i)) 0)
134           below (progn (setq b (incf i)) 9)
135           by (progn (setq c (incf i)) 2)
136           collect x)
137     a b c i))
138  (0 2 4 6 8)
139  1 2 3 3)
140
141(deftest loop.1.30
142  (let (a b c (i 0))
143    (values
144     (loop for x from (progn (setq a (incf i)) 0)
145           by (progn (setq c (incf i)) 2)
146           below (progn (setq b (incf i)) 9)
147           collect x)
148     a b c i))
149  (0 2 4 6 8)
150  1 3 2 3)
151
152(deftest loop.1.31
153  (let (a b c (i 0))
154    (values
155     (loop for x
156           below (progn (setq b (incf i)) 9)
157           by (progn (setq c (incf i)) 2)
158           from (progn (setq a (incf i)) 0)
159           collect x)
160     a b c i))
161  (0 2 4 6 8)
162  3 1 2 3)
163
164(deftest loop.1.32
165  (let (a b c (i 0))
166    (values
167     (loop for x
168           by (progn (setq c (incf i)) 2)
169           below (progn (setq b (incf i)) 9)
170           from (progn (setq a (incf i)) 0)
171           collect x)
172     a b c i))
173  (0 2 4 6 8)
174  3 2 1 3)
175
176(deftest loop.1.33
177  (loop for x from 1 upto 5 collect x)
178  (1 2 3 4 5))
179
180(deftest loop.1.34
181  (loop for x from 1 to 4.0 collect x)
182  (1 2 3 4))
183
184(deftest loop.1.35
185  (loop for x below 5 collect x)
186  (0 1 2 3 4))
187
188(deftest loop.1.36
189  (loop for x below 20 by 3 collect x)
190  (0 3 6 9 12 15 18))
191
192(deftest loop.1.37
193  (loop for x by 3 below 20 collect x)
194  (0 3 6 9 12 15 18))
195
196(deftest loop.1.38
197  (loop for x of-type fixnum from 1 to 5 collect x)
198  (1 2 3 4 5))
199
200#|
201;;; The following provides an example where an incorrect
202;;; implementation will assign X an out-of-range value
203;;; at the end.
204(deftest loop.1.39
205  (loop for x of-type (integer 1 5) from 1 to 5 collect x)
206  (1 2 3 4 5))
207
208;;; Test that the index variable achieves the inclusive
209;;; upper bound, but does not exceed it.
210(deftest loop.1.40
211  (loop for x from 1 to 5 do nil finally (return x))
212  5)
213
214;;; Test that the index variable acheives the exclusive
215;;; upper bound, but does not exceed it.
216(deftest loop.1.41
217  (loop for x from 1 below 5 do nil finally (return x))
218  4)
219
220(deftest loop.1.42
221  (loop for x from 10 downto 0 do nil finally (return x))
222  0)
223
224(deftest loop.1.43
225  (loop for x from 10 above 0 do nil finally (return x))
226  1)
227|#
228
229;;; The arithmetic loop form says the types are numbers, not
230;;; reals, so arguably they should work on complexes (which are
231;;; numbers.)  Comparing these for termination could be problematic,
232;;; but a clause without termination should work just fine.
233
234(deftest loop.1.44
235  (loop for i from 1 to 5 for c from #c(0 1) collect c)
236  (#c(0 1) #c(1 1) #c(2 1) #c(3 1) #c(4 1)))
237
238(deftest loop.1.45
239  (loop for i from 1 to 5 for c from #c(0 1) by 2 collect c)
240  (#c(0 1) #c(2 1) #c(4 1) #c(6 1) #c(8 1)))
241
242(deftest loop.1.46
243  (loop for i from 1 to 5 for c downfrom #c(5 1) collect c)
244  (#c(5 1) #c(4 1) #c(3 1) #c(2 1) #c(1 1)))
245
246(deftest loop.1.47
247  (loop for i from 1 to 5 for c downfrom #c(10 1) by 2 collect c)
248  (#c(10 1) #c(8 1) #c(6 1) #c(4 1) #c(2 1)))
249
250(deftest loop.1.48
251  (loop for i from 1 to 5 for c upfrom #c(0 1) collect c)
252  (#c(0 1) #c(1 1) #c(2 1) #c(3 1) #c(4 1)))
253
254(deftest loop.1.49
255  (loop for i from 1 to 5 for c upfrom #c(0 1) by 2 collect c)
256  (#c(0 1) #c(2 1) #c(4 1) #c(6 1) #c(8 1)))
257
258;;; The variable in the loop for-as-arithmetic clause
259;;; can be a d-var-spec, so 'NIL' should mean don't bind anything
260
261(deftest loop.1.50
262  (let ((i 0))
263    (loop for nil from 10 to 15 collect (incf i)))
264  (1 2 3 4 5 6))
265
266(deftest loop.1.51
267  (let ((i 0))
268    (loop for nil from 10 below 15 collect (incf i)))
269  (1 2 3 4 5))
270
271(deftest loop.1.52
272  (loop for nil from 10 to 0 collect 'a)
273  nil)
274
275(deftest loop.1.53
276  (let ((i 0))
277    (loop for nil from 0 to 10 by 2 collect (incf i)))
278  (1 2 3 4 5 6))
279
280(deftest loop.1.54
281  (let ((i 0))
282    (loop for nil from 1 to 4
283          for nil from 1 to 10 collect (incf i)))
284  (1 2 3 4))
285
286(deftest loop.1.55
287  (let ((i 0))
288    (loop for nil from 5 downto 0 collect (incf i)))
289  (1 2 3 4 5 6))
290
291(deftest loop.1.56
292  (let ((i 0))
293    (loop for nil from 5 above 0 collect (incf i)))
294  (1 2 3 4 5))
295
296;;; Test that explicit calls to macroexpand in subforms
297;;; are done in the correct environment
298
299(deftest loop.1.57
300  (macrolet
301   ((%m (z) z))
302   (loop for i from (expand-in-current-env (%m 1)) to 5 collect i))
303  (1 2 3 4 5))
304
305(deftest loop.1.58
306  (macrolet
307   ((%m (z) z))
308   (loop for i from 1 to (expand-in-current-env (%m 5)) collect i))
309  (1 2 3 4 5))
310
311(deftest loop.1.59
312  (macrolet
313   ((%m (z) z))
314   (loop for i from 1 to 5 by (expand-in-current-env (%m 2)) collect i))
315  (1 3 5))
316
317(deftest loop.1.60
318  (macrolet
319   ((%m (z) z))
320   (loop for i downfrom (expand-in-current-env (%m 10))
321         to 3
322         collect i))
323  (10 9 8 7 6 5 4 3))
324
325(deftest loop.1.61
326  (macrolet
327   ((%m (z) z))
328   (loop for i downfrom 10
329         to (expand-in-current-env (%m 3))
330         collect i))
331  (10 9 8 7 6 5 4 3))
332
333(deftest loop.1.62
334  (macrolet
335   ((%m (z) z))
336   (loop for i from (expand-in-current-env (%m 10))
337         downto 3
338         collect i))
339  (10 9 8 7 6 5 4 3))
340
341(deftest loop.1.63
342  (macrolet
343   ((%m (z) z))
344   (loop for i from 10
345         downto (expand-in-current-env (%m 3))
346         collect i))
347  (10 9 8 7 6 5 4 3))
348
349(deftest loop.1.64
350  (macrolet
351   ((%m (z) z))
352   (loop for i from (expand-in-current-env (%m 1)) below 5 collect i))
353  (1 2 3 4))
354 
355(deftest loop.1.65
356  (macrolet
357   ((%m (z) z))
358   (loop for i from 1 below (expand-in-current-env (%m 5)) collect i))
359  (1 2 3 4))
360
361 
Note: See TracBrowser for help on using the repository browser.