source: trunk/source/tests/ansi-tests/loop15.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: 5.0 KB
Line 
1;-*- Mode:     Lisp -*-
2;;;; Author:   Paul Dietz
3;;;; Created:  Thu Nov 21 07:08:21 2002
4;;;; Contains: Tests that keywords can be loop keywords
5
6(in-package :cl-test)
7
8;;; Tests of loop keywords
9
10(deftest loop.15.30
11  (loop :for i :from 1 :to 10 :collect i)
12  (1 2 3 4 5 6 7 8 9 10))
13
14(deftest loop.15.31
15  (loop :for i :upfrom 1 :below 10 :by 2 :collect i)
16  (1 3 5 7 9))
17
18(deftest loop.15.32
19  (loop :with x = 1 :and y = 2 :return (values x y))
20  1 2)
21
22(deftest loop.15.33
23  (loop :named foo :doing (return-from foo 1))
24  1)
25
26(deftest loop.15.34
27  (let ((x 0))
28    (loop
29     :initially (setq x 2)
30     :until t
31     :finally (return x)))
32  2)
33
34(deftest loop.15.35
35  (loop :for x :in '(a b c) :collecting x)
36  (a b c))
37
38(deftest loop.15.36
39  (loop :for x :in '(a b c) :append (list x))
40  (a b c))
41
42(deftest loop.15.37
43  (loop :for x :in '(a b c) :appending (list x))
44  (a b c))
45
46(deftest loop.15.38
47  (loop :for x :in '(a b c) :nconc (list x))
48  (a b c))
49
50(deftest loop.15.39
51  (loop :for x :in '(a b c) :nconcing (list x))
52  (a b c))
53
54(deftest loop.15.40
55  (loop :for x :in '(1 2 3) :count x)
56  3)
57
58(deftest loop.15.41
59  (loop :for x :in '(1 2 3) :counting x)
60  3)
61
62(deftest loop.15.42
63  (loop :for x :in '(1 2 3) :sum x)
64  6)
65
66(deftest loop.15.43
67  (loop :for x :in '(1 2 3) :summing x)
68  6)
69
70(deftest loop.15.44
71  (loop :for x :in '(10 20 30) :maximize x)
72  30)
73
74(deftest loop.15.45
75  (loop :for x :in '(10 20 30) :maximizing x)
76  30)
77
78(deftest loop.15.46
79  (loop :for x :in '(10 20 30) :minimize x)
80  10)
81
82(deftest loop.15.47
83  (loop :for x :in '(10 20 30) :minimizing x)
84  10)
85
86(deftest loop.15.48
87  (loop :for x :in '(1 2 3 4) :sum x :into foo :of-type fixnum
88        :finally (return foo))
89  10)
90
91(deftest loop.15.49
92  (loop :for x :upfrom 1 :to 10
93        :if (evenp x) :sum x :into foo
94        :else :sum x :into bar
95        :end
96        :finally (return (values foo bar)))
97  30 25)
98
99(deftest loop.15.50
100  (loop :for x :downfrom 10 :above 0
101        :when (evenp x) :sum x :into foo
102        :else :sum x :into bar
103        :end
104        :finally (return (values foo bar)))
105  30 25)
106
107(deftest loop.15.51
108  (loop :for x :in '(a b nil c d nil)
109        :unless x :count t)
110  2)
111
112(deftest loop.15.52
113  (loop :for x :in '(a b nil c d nil)
114        :unless x :collect x :into bar :and :count t :into foo
115        :end
116        finally (return (values bar foo)))
117  (nil nil)
118  2)
119
120(deftest loop.15.53
121  (loop :for x :in '(nil nil a b nil c nil)
122        :collect x
123        :until x)
124  (nil nil a))
125
126(deftest loop.15.54
127  (loop :for x :in '(a b nil c nil)
128        :while x :collect x)
129  (a b))
130
131(deftest loop.15.55
132  (loop :for x :in '(nil nil a b nil c nil)
133        :thereis x)
134  a)
135
136(deftest loop.15.56
137  (loop :for x :in '(nil nil a b nil c nil)
138        :never x)
139  nil)
140
141(deftest loop.15.57
142  (loop :for x :in '(a b c d e)
143        :always x)
144  t)
145
146(deftest loop.15.58
147  (loop :as x :in '(a b c) :count t)
148  3)
149
150(deftest loop.15.59
151  (loop :for i :from 10 :downto 5 :collect i)
152  (10 9 8 7 6 5))
153
154(deftest loop.15.60
155  (loop :for i :from 0 :upto 5 :collect i)
156  (0 1 2 3 4 5))
157
158(deftest loop.15.61
159  (loop :for x :on '(a b c) :collecting (car x))
160  (a b c))
161
162(deftest loop.15.62
163  (loop :for x = '(a b c) :then (cdr x)
164        :while x
165        :collect (car x))
166  (a b c))
167
168(deftest loop.15.63
169  (loop :for x :across #(a b c) :collect x)
170  (a b c))
171
172(deftest loop.15.64
173  (loop :for x :being :the :hash-keys :of (make-hash-table)
174        :count t)
175  0)
176
177(deftest loop.15.65
178  (loop :for x :being :each :hash-key :in (make-hash-table)
179        :count t)
180  0)
181
182(deftest loop.15.66
183  (loop :for x :being :each :hash-value :of (make-hash-table)
184        :count t)
185  0)
186
187(deftest loop.15.67
188  (loop :for x :being :the :hash-values :in (make-hash-table)
189        :count t)
190  0)
191
192(deftest loop.15.68
193  (loop :for x :being :the :hash-values :in (make-hash-table)
194        :using (:hash-key k)
195        :count t)
196  0)
197
198(deftest loop.15.69
199  (loop :for x :being :the :hash-keys :in (make-hash-table)
200        :using (:hash-value v)
201        :count t)
202  0)
203
204(deftest loop.15.70
205  (let ()
206    (ignore-errors (delete-package "LOOP.15.PACKAGE"))
207    (let ((p (make-package "LOOP.15.PACKAGE" :use nil)))
208      (loop :for x :being :the :symbols :of p :count t)))
209  0)
210
211(deftest loop.15.71
212  (let ()
213    (ignore-errors (delete-package "LOOP.15.PACKAGE"))
214    (let ((p (make-package "LOOP.15.PACKAGE" :use nil)))
215      (loop :for x :being :each :symbol :of p :count t)))
216  0)
217
218(deftest loop.15.72
219  (let ()
220    (ignore-errors (delete-package "LOOP.15.PACKAGE"))
221    (let ((p (make-package "LOOP.15.PACKAGE" :use nil)))
222      (loop :for x :being :the :external-symbols :of p :count t)))
223  0)
224
225(deftest loop.15.73
226  (let ()
227    (ignore-errors (delete-package "LOOP.15.PACKAGE"))
228    (let ((p (make-package "LOOP.15.PACKAGE" :use nil)))
229      (loop :for x :being :each :external-symbol :of p :count t)))
230  0)
231
232(deftest loop.15.74
233  (let ()
234    (ignore-errors (delete-package "LOOP.15.PACKAGE"))
235    (let ((p (make-package "LOOP.15.PACKAGE" :use nil)))
236      (loop :for x :being :the :present-symbols :of p :count t)))
237  0)
238
239(deftest loop.15.75
240  (let ()
241    (ignore-errors (delete-package "LOOP.15.PACKAGE"))
242    (let ((p (make-package "LOOP.15.PACKAGE" :use nil)))
243      (loop :for x :being :each :present-symbol :of p :count t)))
244  0)
245
246
247
248
249
Note: See TracBrowser for help on using the repository browser.