/[gcl]/gcl/ansi-tests/iteration.lsp
ViewVC logotype

Diff of /gcl/ansi-tests/iteration.lsp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.2 by pfdietz, Wed Oct 23 03:10:23 2002 UTC revision 1.3 by pfdietz, Fri Oct 25 12:31:31 2002 UTC
# Line 1  Line 1 
1  ;-*- Mode:     Lisp -*-  ;-*- Mode:     Lisp -*-
2  ;;;; Author:   Paul Dietz  ;;;; Author:   Paul Dietz
3  ;;;; Created:  Mon Oct 21 22:58:00 2002  ;;;; Created:  Mon Oct 21 22:58:00 2002
4  ;;;; Contains: Tests for iteration forms  ;;;; Contains: Tests for iteration forms other than LOOP
5    
6  (in-package :cl-test)  (in-package :cl-test)
7    
# Line 88  Line 88 
88        (incf i)))        (incf i)))
89    10)    10)
90    
91    ;;; Return of no values
92    (deftest do.10
93      (do ((i 0 (1+ i)))
94          ((> i 10) (values))))
95    
96    ;;; Return of two values
97    (deftest do.11
98      (do ((i 0 (1+ i)))
99          ((> i 10) (values i (1+ i))))
100      11 12)
101    
102    ;;; The results* list is an implicit progn
103    (deftest do.12
104      (do ((i 0 (1+ i)))
105          ((> i 10) (incf i) (incf i) i))
106      13)
107    
108    (deftest do.13
109      (do ((i 0 (1+ i)))
110          ((> i 10)))
111      nil)
112    
113    ;; Special var
114    (deftest do.14
115      (let ((x 0))
116        (flet ((%f () (locally (declare (special i))
117                               (incf x i))))
118          (do ((i 0 (1+ i)))
119              ((>= i 10) x)
120            (declare (special i))
121            (%f))))
122      45)
123    
124    ;;; Confirm that the variables in succesive iterations are
125    ;;; identical
126    (deftest do.15
127      (mapcar #'funcall
128              (let ((x nil))
129                (do ((i 0 (1+ i)))
130                    ((= i 5) x)
131                  (push #'(lambda () i) x))))
132      (5 5 5 5 5))
133    
134    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
135    
136    ;;;; Tests of DO*
137    
138    (deftest do*.1
139      (do* ((i 0 (1+ i)))
140          ((>= i 10) i))
141      10)
142    
143    (deftest do*.2
144      (do* ((i 0 (1+ j))
145            (j 0 (1+ i)))
146          ((>= i 10) (+ i j)))
147      23)
148    
149    (deftest do*.3
150      (let ((x nil))
151        (do* ((i 0 (1+ i)))
152            ((>= i 10) x)
153          (push i x)))
154      (9 8 7 6 5 4 3 2 1 0))
155    
156    (deftest do*.4
157      (let ((x nil))
158        (do* ((i 0 (1+ i)))
159            ((>= i 10) x)
160          (declare (fixnum i))
161          (push i x)))
162      (9 8 7 6 5 4 3 2 1 0))
163    
164    (deftest do*.5
165      (do* ((i 0 (1+ i)))
166          (nil)
167        (when (> i 10) (return i)))
168      11)
169    
170    ;;; Zero iterations
171    (deftest do*.6
172      (do* ((i 0 (+ i 10)))
173          ((> i -1) i)
174        (return 'bad))
175      0)
176    
177    ;;; Tests of go tags
178    (deftest do*.7
179      (let ((x nil))
180        (do* ((i 0 (1+ i)))
181            ((>= i 10) x)
182          (go around)
183          small
184          (push 'a x)
185          (go done)
186          big
187          (push 'b x)
188          (go done)
189          around
190          (if (> i 4) (go big) (go small))
191          done))
192      (b b b b b a a a a a))
193    
194    ;;; No increment form
195    (deftest do*.8
196      (do* ((i 0 (1+ i))
197           (x nil))
198          ((>= i 10) x)
199        (push 'a x))
200      (a a a a a a a a a a))
201    
202    ;;; No do* locals
203    (deftest do*.9
204      (let ((i 0))
205        (do* ()
206            ((>= i 10) i)
207          (incf i)))
208      10)
209    
210    ;;; Return of no values
211    (deftest do*.10
212      (do* ((i 0 (1+ i)))
213          ((> i 10) (values))))
214    
215    ;;; Return of two values
216    (deftest do*.11
217      (do* ((i 0 (1+ i)))
218          ((> i 10) (values i (1+ i))))
219      11 12)
220    
221    ;;; The results* list is an implicit progn
222    (deftest do*.12
223      (do* ((i 0 (1+ i)))
224          ((> i 10) (incf i) (incf i) i))
225      13)
226    
227    (deftest do*.13
228      (do* ((i 0 (1+ i)))
229          ((> i 10)))
230      nil)
231    
232    ;; Special var
233    (deftest do*.14
234      (let ((x 0))
235        (flet ((%f () (locally (declare (special i))
236                               (incf x i))))
237          (do* ((i 0 (1+ i)))
238               ((>= i 10) x)
239            (declare (special i))
240            (%f))))
241      45)
242    
243    ;;; Confirm that the variables in succesive iterations are
244    ;;; identical
245    (deftest do*.15
246      (mapcar #'funcall
247              (let ((x nil))
248                (do* ((i 0 (1+ i)))
249                    ((= i 5) x)
250                  (push #'(lambda () i) x))))
251      (5 5 5 5 5))
252    
253    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
254    
255    ;;;; Tests for DOLIST
256    
257    (deftest dolist.1
258      (let ((count 0))
259        (dolist (x '(a b nil d)) (incf count))
260        count)
261      4)
262    
263    (deftest dolist.2
264      (let ((count 0))
265        (dolist (x '(a nil c d) count) (incf count)))
266      4)
267    
268    (deftest dolist.3
269      (let ((count 0))
270        (dolist (x nil count) (incf count)))
271      0)
272    
273    (deftest dolist.4
274      (let ((y nil))
275        (flet ((%f () (locally (declare (special e))
276                               (push e y))))
277          (dolist (e '(a b c) (reverse y))
278            (declare (special e))
279            (%f))))
280      (a b c))
281    
282    ;;; Tests that it's a tagbody
283    (deftest dolist.5
284      (let ((even nil)
285            (odd nil))
286        (dolist (i '(1 2 3 4 5 6 7 8) (values (reverse even)
287                                              (reverse odd)))
288          (when (evenp i) (go even))
289          (push i odd)
290          (go done)
291          even
292          (push i even)
293          done))
294      (2 4 6 8)
295      (1 3 5 7))
296    
297    ;;; Test that bindings are not normally special
298    (deftest dolist.6
299      (let ((i 0) (y nil))
300        (declare (special i))
301        (flet ((%f () i))
302          (dolist (i '(1 2 3 4))
303            (push (%f) y)))
304        y)
305      (0 0 0 0))
306    
307    ;;; Test multiple return values
308    
309    (deftest dolist..7
310      (dolist (x '(a b) (values))))
311    
312    (deftest dolist.8
313      (let ((count 0))
314        (dolist (x '(a b c) (values count count))
315          (incf count)))
316      3 3)
317    
318    ;;; Test ability to return, and the scope of the implicit
319    ;;; nil block
320    (deftest dolist.9
321      (block nil
322        (eqlt (dolist (x '(a b c))
323                (return 1))
324              1))
325      t)
326    
327    (deftest dolist.10
328      (block nil
329        (eqlt (dolist (x '(a b c))
330                (return-from nil 1))
331              1))
332      t)
333    
334    (deftest dolist.11
335      (block nil
336        (dolist (x (return 1)))
337        2)
338      2)
339    
340    (deftest dolist.12
341      (block nil
342        (dolist (x '(a b) (return 1)))
343        2)
344      2)
345    
346    ;;; Check that binding of element var is visible in the result form
347    (deftest dolist.13
348      (dolist (e '(a b c) e))
349      nil)
350    
351    (deftest dolist.14
352      (let ((e 1))
353        (dolist (e '(a b c) (setf e 2)))
354        e)
355      1)
356    
357    (deftest dolist.15
358      (let ((x nil))
359        (dolist (e '(a b c d e f))
360          (push e x)
361          (when (eq e 'c) (return x))))
362      (c b a))
363    
364    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
365    
366    ;;; Tests for DOTIMES
367    
368    (deftest dotimes.1
369      (dotimes (i 10))
370      nil)
371    
372    (deftest dotimes.2
373      (dotimes (i 10 'a))
374      a)
375    
376    (deftest dotimes.3
377      (dotimes (i 10 (values))))
378    
379    (deftest dotimes.3
380      (dotimes (i 10 (values 'a 'b 'c)))
381      a b c)
382    
383    (deftest dotimes.4
384      (let ((x nil))
385        (dotimes (i 5 x) (push i x)))
386      (4 3 2 1 0))
387    
388    (deftest dotimes.5
389      (let ((x nil))
390        (dotimes (i 0 x) (push i x)))
391      nil)
392    
393    (deftest dotimes.6
394      (let ((x nil))
395        (dotimes (i -1 x) (push i x)))
396      nil)
397    
398    (deftest dotimes.7
399      (let ((x nil))
400        (dotimes (i (1- most-negative-fixnum) x) (push i x)))
401      nil)
402    
403    ;;; Implicit nil block has the right scope
404    (deftest dotimes.8
405      (block nil
406        (dotimes (i (return 1)))
407        2)
408      2)
409    
410    (deftest dotimes.9
411      (block nil
412        (dotimes (i 10 (return 1)))
413        2)
414      2)
415    
416    (deftest dotimes.10
417      (block nil
418        (dotimes (i 10) (return 1))
419        2)
420      2)
421    
422    (deftest dotimes.11
423      (let ((x nil))
424        (dotimes (i 10)
425          (push i x)
426          (when (= i 5) (return x))))
427      (5 4 3 2 1 0))
428    
429    ;;; Check there's an implicit tagbody
430    (deftest dotimes.12
431      (let ((even nil)
432            (odd nil))
433        (dotimes (i 8 (values (reverse even)
434                              (reverse odd)))
435          (when (evenp i) (go even))
436          (push i odd)
437          (go done)
438          even
439          (push i even)
440          done))
441      (0 2 4 6)
442      (1 3 5 7))
443    
444    ;;; Check that at the time the result form is evaluated,
445    ;;; the index variable is set to the number of times the loop
446    ;;; was executed.
447    
448    (deftest dotimes.13
449      (let ((i 100))
450        (dotimes (i 10 i)))
451      10)
452    
453    (deftest dotimes.14
454      (let ((i 100))
455        (dotimes (i 0 i)))
456      0)
457    
458    (deftest dotimes.15
459      (let ((i 100))
460        (dotimes (i -1 i)))
461      0)
462    
463    ;;; Check that the variable is not bound in the count form
464    (deftest dotimes.16
465      (let ((i nil))
466        (values
467         i
468         (dotimes (i (progn (setf i 'a) 10) i))
469         i))
470      nil 10 a)
471    
472    ;;; Check special variable decls
473    (deftest dotimes.17
474      (let ((i 0) (y nil))
475        (declare (special i))
476        (flet ((%f () i))
477          (dotimes (i 4)
478            (push (%f) y)))
479        y)
480      (0 0 0 0))
481    
482    (deftest dotimes.18
483      (let ((i 0) (y nil))
484        (declare (special i))
485        (flet ((%f () i))
486          (dotimes (i 4)
487            (declare (special i))
488            (push (%f) y)))
489        y)
490      (3 2 1 0))
491    
     
492    
493    
494    

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26